| 141 | |
| 142 | @cross_language_test |
| 143 | def test_map_encoder(data_file_path): |
| 144 | encoder = pyfory.encoder(A) |
| 145 | a = A(f1=1, f2={"pid": "12345", "ip": "0.0.0.0", "k1": "v1"}) |
| 146 | with open(data_file_path, "rb+") as f: |
| 147 | data_bytes = f.read() |
| 148 | obj = encoder.decode(data_bytes) |
| 149 | debug_print("deserialized obj", obj) |
| 150 | # Compare by dict since decoder returns a record class, not the original class |
| 151 | assert to_dict(obj) == to_dict(a) |
| 152 | decoded_round_trip = encoder.decode(encoder.encode(a)) |
| 153 | assert to_dict(decoded_round_trip) == to_dict(a) |
| 154 | f.seek(0) |
| 155 | f.truncate() |
| 156 | f.write(encoder.encode(a)) |
| 157 | |
| 158 | |
| 159 | @cross_language_test |