武器级mqtt包编解码器。
mqtt-codec的Python项目详细描述
武器级mqtt包编解码器(codec)。
状态
mqtt codec包是 MQTT 3.1.1 包编码器和解码器(编解码器)。图书馆的测试覆盖率很高 (~94%),在分布式物联网中表现良好 数千个节点。
用法
编码/解码循环如下:
>>>fromioimportBytesIO>>>frombinasciiimportb2a_hex>>>importmqtt_codec.packet>>>importmqtt_codec.io>>>>>># Encode a Connect packet>>>will=mqtt_codec.packet.MqttWill(qos=0,topic='hello',message='message',retain=True)>>>connect=mqtt_codec.packet.MqttConnect(client_id='client_id',clean_session=False,keep_alive=0,will=will)>>>withBytesIO()asf:...num_bytes_written=connect.encode(f)...buf=f.getvalue()...>>>assertlen(buf)==num_bytes_written>>>print('0x{} ({} bytes)'.format(b2a_hex(buf),len(buf)))0x102500044d515454042400000009636c69656e745f6964000568656c6c6f00076d657373616765(39bytes)>>>>>># Decode the connect packet and assert equality.>>>withmqtt_codec.io.BytesReader(buf)asf:...num_bytes_read,decoded_connect=connect.decode(f)...>>>assertlen(buf)==num_bytes_written>>>assertconnect==decoded_connect>>>print(' Encoded {}'.format(connect))EncodedMqttConnect(client_id='client_id',clean_session=False,keep_alive=0,username=***,password=***,will=MqttWill(topic=hello,payload=0x6d657373616765,retain=True,qos=0))>>>print('= Decoded {}'.format(decoded_connect))=DecodedMqttConnect(client_id=u'client_id',clean_session=False,keep_alive=0,username=***,password=***,will=MqttWill(topic=hello,payload=0x6d657373616765,retain=True,qos=0))
python需求
mqtt-codec项目已经在linux上针对以下内容进行了测试 环境:
- python 2.7版
- Python3.4
- Python3.5
- python 3.6
- Python3.7
python版本python 3.0-3.3可以工作,但不能作为 项目持续集成基础设施。
库要求
当运行低于3.4的python版本时,enum34包是 必修的。没有其他包装要求。
项目基础设施
该项目通过公共基础设施进行协调,可在 几个地方: