예제 #1
0
    def test_msgpack_for_ipc_encode_deoode(self):
        expected_struct: list = [
            1, -1, b'123456', b'', "hello", "",
            create_address(), None
        ]

        data_list: list = []
        for value in expected_struct:
            data_list.append(MsgPackForIpc.encode(value))

        data: bytes = MsgPackForIpc.dumps(data_list)
        struct: list = MsgPackForIpc.loads(data)

        actual_struct: list = [
            MsgPackForIpc.decode(TypeTag.INT, struct[0]),
            MsgPackForIpc.decode(TypeTag.INT, struct[1]),
            MsgPackForIpc.decode(TypeTag.BYTES, struct[2]),
            MsgPackForIpc.decode(TypeTag.BYTES, struct[3]),
            MsgPackForIpc.decode(TypeTag.STRING, struct[4]),
            MsgPackForIpc.decode(TypeTag.STRING, struct[5]),
            MsgPackForIpc.decode(TypeTag.ADDRESS, struct[6]),
            MsgPackForIpc.decode(TypeTag.NIL, struct[7])
        ]

        self.assertEqual(expected_struct, actual_struct)
예제 #2
0
    def test_msgpack_loads_dumps(self):
        expected_struct: list = [
            1, -1, b'123456', b'', [1, 2, 3, 4, 5], {
                1: 2,
                3: 4
            }, True, False, None
        ]

        data: bytes = MsgPackForIpc.dumps(expected_struct)
        struct: list = MsgPackForIpc.loads(data)
        self.assertEqual(expected_struct, struct)