text
stringlengths 0
828
|
|---|
num_bytes_written += mqtt_io.encode_utf8(self.password, f)
|
return num_bytes_written"
|
1170,"def decode_body(cls, header, f):
|
""""""Generates a `MqttSubscribe` packet given a
|
`MqttFixedHeader`. This method asserts that header.packet_type
|
is `subscribe`.
|
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``.
|
MqttSubscribe
|
Object extracted from ``f``.
|
""""""
|
assert header.packet_type == MqttControlPacketType.subscribe
|
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, name = decoder.unpack_utf8()
|
max_qos, = decoder.unpack(mqtt_io.FIELD_U8)
|
try:
|
sub_topic = MqttTopic(name, max_qos)
|
except ValueError:
|
raise DecodeError('Invalid QOS {}'.format(max_qos))
|
topics.append(sub_topic)
|
assert header.remaining_len == decoder.num_bytes_consumed
|
return decoder.num_bytes_consumed, MqttSubscribe(packet_id, topics)"
|
1171,"def decode_body(cls, header, f):
|
""""""Generates a `MqttSuback` packet given a
|
`MqttFixedHeader`. This method asserts that header.packet_type
|
is `suback`.
|
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``.
|
MqttSuback
|
Object extracted from ``f``.
|
""""""
|
assert header.packet_type == MqttControlPacketType.suback
|
decoder = mqtt_io.FileDecoder(mqtt_io.LimitReader(f, header.remaining_len))
|
packet_id, = decoder.unpack(mqtt_io.FIELD_PACKET_ID)
|
results = []
|
while header.remaining_len > decoder.num_bytes_consumed:
|
result, = decoder.unpack(mqtt_io.FIELD_U8)
|
try:
|
results.append(SubscribeResult(result))
|
except ValueError:
|
raise DecodeError('Unsupported result {:02x}.'.format(result))
|
assert header.remaining_len == decoder.num_bytes_consumed
|
return decoder.num_bytes_consumed, MqttSuback(packet_id, results)"
|
1172,"def decode_body(cls, header, f):
|
""""""Generates a `MqttPublish` packet given a
|
`MqttFixedHeader`. This method asserts that header.packet_type
|
is `publish`.
|
Parameters
|
----------
|
header: MqttFixedHeader
|
f: file
|
Object with a read method.
|
Raises
|
------
|
DecodeError
|
When there are extra bytes at the end of the packet.
|
Returns
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.