Example #1
0
 def test_encode_message_delimited(self):
     request = krpc.schema.KRPC.Request()
     request.service = 'ServiceName'
     request.procedure = 'ProcedureName'
     data = Encoder.encode_delimited(request, self.types.as_type('KRPC.Request'))
     expected = '1c'+'0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     self.assertEqual(expected, hexlify(data))
Example #2
0
 def test_encode_message(self):
     call = self.types.procedure_call_type.python_type()
     call.service = 'ServiceName'
     call.procedure = 'ProcedureName'
     data = Encoder.encode(call, self.types.procedure_call_type)
     expected = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     self.assertEqual(expected, hexlify(data))
Example #3
0
 def test_encode_message(self):
     call = self.types.procedure_call_type.python_type()
     call.service = 'ServiceName'
     call.procedure = 'ProcedureName'
     data = Encoder.encode(call, self.types.procedure_call_type)
     expected = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     self.assertEqual(expected, hexlify(data))
Example #4
0
 def test_encode_class(self):
     typ = self.types.as_type('Class(ServiceName.ClassName)')
     class_type = typ.python_type
     self.assertTrue(issubclass(class_type, ClassBase))
     value = class_type(300)
     self.assertEqual(300, value._object_id)
     data = Encoder.encode(value, typ)
     self.assertEqual('ac02', hexlify(data))
Example #5
0
 def test_hexlify(self):
     self.assertEqual(hexlify(b''), '')
     self.assertEqual(hexlify(b'\x00\x01\x02'), '000102')
     self.assertEqual(hexlify(b'\xFF'), 'ff')
Example #6
0
 def test_encode_class_none(self):
     typ = self.types.as_type('Class(ServiceName.ClassName)')
     value = None
     data = Encoder.encode(value, typ)
     self.assertEqual('00', hexlify(data))
Example #7
0
 def test_encode_value_delimited(self):
     data = Encoder.encode_delimited(300, self.types.as_type('int32'))
     self.assertEqual('02'+'ac02', hexlify(data))
Example #8
0
 def test_encode_value(self):
     data = Encoder.encode(300, self.types.uint32_type)
     self.assertEqual('ac02', hexlify(data))
Example #9
0
 def _run_test_encode_value(self, typ, cases):
     for decoded, encoded in cases:
         data = Encoder.encode(decoded, self.types.as_type(typ))
         self.assertEqual(encoded, hexlify(data))
Example #10
0
 def test_empty_client_name(self):
     message = Encoder.client_name()
     self.assertEqual (32, len(message))
     self.assertEqual ('00'*32, hexlify(message))
Example #11
0
 def test_client_name(self):
     message = Encoder.client_name('foo')
     self.assertEqual (32, len(message))
     self.assertEqual ('666f6f'+'00'*29, hexlify(message))
Example #12
0
 def test_stream_hello_message(self):
     message = Encoder.STREAM_HELLO_MESSAGE
     self.assertEqual (12, len(message))
     self.assertEqual ('48454c4c4f2d53545245414d', hexlify(message))
Example #13
0
 def test_rpc_hello_message(self):
     message = Encoder.RPC_HELLO_MESSAGE
     self.assertEqual (12, len(message))
     self.assertEqual ('48454c4c4f2d525043000000', hexlify(message))
Example #14
0
 def guid(cls, data):
     """ Decode a 16-byte GUID into a string """
     return '-'.join((hexlify(data[3::-1]), hexlify(data[5:3:-1]), hexlify(data[7:5:-1]),
                      hexlify(data[8:10]), hexlify(data[10:16])))
Example #15
0
 def test_encode_value(self):
     data = Encoder.encode(300, self.types.uint32_type)
     self.assertEqual('ac02', hexlify(data))
Example #16
0
 def guid(cls, data):
     """ Decode a 16-byte GUID into a string """
     return '-'.join(
         (hexlify(data[3::-1]), hexlify(data[5:3:-1]),
          hexlify(data[7:5:-1]), hexlify(data[8:10]), hexlify(data[10:16])))
Example #17
0
 def test_hexlify(self):
     self.assertEqual(hexlify(b''), '')
     self.assertEqual(hexlify(b'\x00\x01\x02'), '000102')
     self.assertEqual(hexlify(b'\xFF'), 'ff')
Example #18
0
 def test_long_client_name(self):
     message = Encoder.client_name('a'*33)
     self.assertEqual (32, len(message))
     self.assertEqual ('61'*32, hexlify(message))
Example #19
0
 def _run_test_encode_value(self, typ, cases):
     for decoded, encoded in cases:
         data = Encoder.encode(decoded, self.types.as_type(typ))
         self.assertEqual(encoded, hexlify(data))
Example #20
0
 def test_encode_unicode_string(self):
     data = Encoder.encode(b'\xe2\x84\xa2'.decode('utf-8'), self.types.as_type('string'))
     self.assertEqual('03e284a2', hexlify(data))