Exemple #1
0
 def from_bytes(cls, header: Header, byte_stream: ByteStream) -> 'FunctionPacket':
     num_bytes = header.specific_data_size
     all_data = general_unpack(byte_stream, num_bytes)
     function_name: str = all_data[0]
     args: tuple = all_data[1]
     kwargs: dict = all_data[2]
     return cls.__call__(function_name, *args, **kwargs)
Exemple #2
0
 def from_bytes(cls, header: Header, byte_stream: ByteStream) -> 'FileMetaPacket':
     num_bytes = header.specific_data_size
     all_data = general_unpack(byte_stream, num_bytes)
     src_path: str = all_data[0]
     dst_path: Optional[str] = all_data[1]
     size: int = all_data[2]
     return cls.__call__(src_path, size, dst_path)
Exemple #3
0
 def test_lambda(self):
     byte_string = general_pack(lambda x, y: x + y)
     byte_stream = ByteStream(byte_string)
     new_value = general_unpack(byte_stream)[0]
     self.assertEqual(10, new_value(5, 5))
Exemple #4
0
def single_value(test_self, value):
    byte_string = general_pack(value)
    byte_stream = ByteStream(byte_string)
    new_value = general_unpack(byte_stream)[0]
    test_self.assertEqual(value, new_value)
Exemple #5
0
 def from_bytes(cls, header: Header, byte_stream: ByteStream) -> 'DataPacket':
     num_bytes = header.specific_data_size
     data = general_unpack(byte_stream, num_bytes)[0]
     return cls.__call__(**data)