Ejemplo n.º 1
0
 def execute(self, request_type, uri, callback):
     header = mercury.Header(**{'uri': uri, 'method': str(request_type)})
     buffer= b'\x00\x08'+   \
             self._sequence.to_bytes( 8, byteorder='big' )+  \
             b'\x01'+       \
             b'\x00\x01'+   \
             struct.pack(">H", len( header.SerializeToString() ) )+ \
             header.SerializeToString()
     self.set_callback(self._sequence, callback)
     self._sequence += 1
     self._connection.send_packet(request_type.as_command(), buffer)
Ejemplo n.º 2
0
    def _parse_response(self, payload):
        header_size = struct.unpack(">H", payload[13:15])[0]
        header = mercury.Header()
        header.ParseFromString(payload[15:15 + header_size])
        print(header)
        # Now go through all parts and separate them
        pos = 15 + header_size
        parts = []
        while pos < len(payload):
            chunk_size = struct.unpack(">H", payload[pos:pos + 2])[0]
            chunk = payload[pos + 2:pos + 2 + chunk_size]
            parts.append(chunk)
            pos += 2 + chunk_size

        return int.from_bytes(payload[2:10], byteorder='big'), header, parts