예제 #1
0
파일: connect.py 프로젝트: tulir/hbmqtt
    def from_stream(cls, reader: ReaderAdapter, fixed_header: MQTTFixedHeader):
        #  protocol name
        protocol_name = yield from decode_string(reader)

        # protocol level
        protocol_level_byte = yield from read_or_raise(reader, 1)
        protocol_level = bytes_to_int(protocol_level_byte)

        # flags
        flags_byte = yield from read_or_raise(reader, 1)
        flags = bytes_to_int(flags_byte)

        # keep-alive
        keep_alive_byte = yield from read_or_raise(reader, 2)
        keep_alive = bytes_to_int(keep_alive_byte)

        return cls(flags, keep_alive, protocol_name, protocol_level)
예제 #2
0
    def from_stream(cls, reader: ReaderAdapter, fixed_header: MQTTFixedHeader):
        #  protocol name
        protocol_name = yield from decode_string(reader)

        # protocol level
        protocol_level_byte = yield from read_or_raise(reader, 1)
        protocol_level = bytes_to_int(protocol_level_byte)

        # flags
        flags_byte = yield from read_or_raise(reader, 1)
        flags = bytes_to_int(flags_byte)

        # keep-alive
        keep_alive_byte = yield from read_or_raise(reader, 2)
        keep_alive = bytes_to_int(keep_alive_byte)

        return cls(flags, keep_alive, protocol_name, protocol_level)
예제 #3
0
 def from_stream(cls, reader: ReaderAdapter, fixed_header: MQTTFixedHeader,
                 variable_header: MQTTVariableHeader):
     return_codes = []
     bytes_to_read = fixed_header.remaining_length - variable_header.bytes_length
     for i in range(0, bytes_to_read):
         try:
             return_code_byte = yield from read_or_raise(reader, 1)
             return_code = bytes_to_int(return_code_byte)
             return_codes.append(return_code)
         except NoDataException:
             break
     return cls(return_codes)
예제 #4
0
 def from_stream(cls, reader: ReaderAdapter, fixed_header: MQTTFixedHeader,
                 variable_header: MQTTVariableHeader):
     return_codes = []
     bytes_to_read = fixed_header.remaining_length - variable_header.bytes_length
     for i in range(0, bytes_to_read):
         try:
             return_code_byte = yield from read_or_raise(reader, 1)
             return_code = bytes_to_int(return_code_byte)
             return_codes.append(return_code)
         except NoDataException:
             break
     return cls(return_codes)
예제 #5
0
 def from_stream(cls, reader: asyncio.StreamReader, fixed_header: MQTTFixedHeader,
                 variable_header: MQTTVariableHeader):
     topics = []
     payload_length = fixed_header.remaining_length - variable_header.bytes_length
     read_bytes = 0
     while read_bytes < payload_length:
         try:
             topic = yield from decode_string(reader)
             qos_byte = yield from read_or_raise(reader, 1)
             qos = bytes_to_int(qos_byte)
             topics.append((topic, qos))
             read_bytes += 2 + len(topic.encode('utf-8')) + 1
         except NoDataException as exc:
             break
     return cls(topics)
예제 #6
0
 def from_stream(cls, reader: asyncio.StreamReader,
                 fixed_header: MQTTFixedHeader,
                 variable_header: MQTTVariableHeader):
     topics = []
     payload_length = fixed_header.remaining_length - variable_header.bytes_length
     read_bytes = 0
     while read_bytes < payload_length:
         try:
             topic = yield from decode_string(reader)
             qos_byte = yield from read_or_raise(reader, 1)
             qos = bytes_to_int(qos_byte)
             topics.append((topic, qos))
             read_bytes += 2 + len(topic.encode('utf-8')) + 1
         except NoDataException as exc:
             break
     return cls(topics)
예제 #7
0
 def from_stream(cls, reader: ReaderAdapter, fixed_header: MQTTFixedHeader):
     data = yield from read_or_raise(reader, 2)
     session_parent = data[0] & 0x01
     return_code = bytes_to_int(data[1])
     return cls(session_parent, return_code)
예제 #8
0
파일: connack.py 프로젝트: feedernet/hbmqtt
 async def from_stream(cls, reader: ReaderAdapter,
                       fixed_header: MQTTFixedHeader):
     data = await read_or_raise(reader, 2)
     session_parent = data[0] & 0x01
     return_code = bytes_to_int(data[1])
     return cls(session_parent, return_code)
예제 #9
0
 def test_bytes_to_int(self):
     ret = bytes_to_int(b'\x7f')
     self.assertEqual(ret, 127)
     ret = bytes_to_int(b'\xff\xff')
     self.assertEqual(ret, 65535)
예제 #10
0
 def from_stream(cls, reader: asyncio.StreamReader, fixed_header: MQTTFixedHeader):
     data = yield from read_or_raise(reader, 2)
     session_parent = data[0] & 0x01
     return_code = ReturnCode(bytes_to_int(data[1]))
     return cls(session_parent, return_code)