示例#1
0
    def test_msgpack_for_db_loads_dumps(self):
        int_table = [-1, 0, 1, 10**30]
        bytes_table = [b'hello', b'', ZERO_SCORE_ADDRESS.to_bytes()]
        str_table = ["hello", ""]
        address_table = [create_address(), create_address(1)]
        dict_table = {"1": 1, "2": 2, "3": 3}
        list_table = [1, 2, 3, 4, 5]
        bool_table = [True, False]
        None_table = [None]

        expected_struct: list = [
            int_table, bytes_table, str_table, address_table, dict_table,
            list_table, bool_table, None_table
        ]

        data: bytes = MsgPackForDB.dumps(expected_struct)
        struct: list = MsgPackForDB.loads(data)
        self.assertEqual(expected_struct, struct)
示例#2
0
 def _prt_length_info(self, tag: str, data_list: list):
     data: bytes = MsgPackForDB.dumps(data_list)
     print(f"{tag} data: {data_list}")
     print(f"{tag} length: {len(data)}")