text
stringlengths 0
828
|
|---|
-------
|
int
|
Number of bytes consumed from ``f``.
|
MqttPublish
|
Object extracted from ``f``.
|
""""""
|
assert header.packet_type == MqttControlPacketType.publish
|
dupe = bool(header.flags & 0x08)
|
retain = bool(header.flags & 0x01)
|
qos = ((header.flags & 0x06) >> 1)
|
if qos == 0 and dupe:
|
# The DUP flag MUST be set to 0 for all QoS 0 messages
|
# [MQTT-3.3.1-2]
|
raise DecodeError(""Unexpected dupe=True for qos==0 message [MQTT-3.3.1-2]."")
|
decoder = mqtt_io.FileDecoder(mqtt_io.LimitReader(f, header.remaining_len))
|
num_bytes_consumed, topic_name = decoder.unpack_utf8()
|
if qos != 0:
|
# See MQTT 3.1.1 section 3.3.2.2
|
# See https://github.com/kcallin/mqtt-codec/issues/5
|
packet_id, = decoder.unpack(mqtt_io.FIELD_PACKET_ID)
|
else:
|
packet_id = 0
|
payload_len = header.remaining_len - decoder.num_bytes_consumed
|
payload = decoder.read(payload_len)
|
return decoder.num_bytes_consumed, MqttPublish(packet_id, topic_name, payload, dupe, qos, retain)"
|
1173,"def decode_body(cls, header, f):
|
""""""Generates a `MqttPubrel` packet given a
|
`MqttFixedHeader`. This method asserts that header.packet_type
|
is `pubrel`.
|
Parameters
|
----------
|
header: MqttFixedHeader
|
f: file
|
Object with a read method.
|
Raises
|
------
|
DecodeError
|
When there are extra bytes at the end of the packet.
|
Returns
|
-------
|
int
|
Number of bytes consumed from ``f``.
|
MqttPubrel
|
Object extracted from ``f``.
|
""""""
|
assert header.packet_type == MqttControlPacketType.pubrel
|
decoder = mqtt_io.FileDecoder(mqtt_io.LimitReader(f, header.remaining_len))
|
packet_id, = decoder.unpack(mqtt_io.FIELD_U16)
|
if header.remaining_len != decoder.num_bytes_consumed:
|
raise DecodeError('Extra bytes at end of packet.')
|
return decoder.num_bytes_consumed, MqttPubrel(packet_id)"
|
1174,"def decode_body(cls, header, f):
|
""""""Generates a `MqttUnsubscribe` packet given a
|
`MqttFixedHeader`. This method asserts that header.packet_type
|
is `unsubscribe`.
|
Parameters
|
----------
|
header: MqttFixedHeader
|
f: file
|
Object with a read method.
|
Raises
|
------
|
DecodeError
|
When there are extra bytes at the end of the packet.
|
Returns
|
-------
|
int
|
Number of bytes consumed from ``f``.
|
MqttUnsubscribe
|
Object extracted from ``f``.
|
""""""
|
assert header.packet_type == MqttControlPacketType.unsubscribe
|
decoder = mqtt_io.FileDecoder(mqtt_io.LimitReader(f, header.remaining_len))
|
packet_id, = decoder.unpack(mqtt_io.FIELD_PACKET_ID)
|
topics = []
|
while header.remaining_len > decoder.num_bytes_consumed:
|
num_str_bytes, topic = decoder.unpack_utf8()
|
topics.append(topic)
|
assert header.remaining_len - decoder.num_bytes_consumed == 0
|
return decoder.num_bytes_consumed, MqttUnsubscribe(packet_id, topics)"
|
1175,"def decode_body(cls, header, f):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.