MCPcopy Create free account
hub / github.com/apache/fory / test_register_serializer

Function test_register_serializer

python/pyfory/tests/test_cross_language.py:631–659  ·  view source on GitHub ↗
(data_file_path)

Source from the content-addressed store, hash-verified

629
630@cross_language_test
631def test_register_serializer(data_file_path):
632 with open(data_file_path, "rb") as f:
633 data_bytes = f.read()
634 buffer = pyfory.Buffer(data_bytes)
635
636 fory = pyfory.Fory(xlang=True, compatible=False, ref=True)
637 fory.register_type(
638 ComplexObject1,
639 name="test.ComplexObject1",
640 serializer=ComplexObject1Serializer(fory.type_resolver, ComplexObject1),
641 )
642 expected = ComplexObject1(*[None] * 12)
643 expected.f1, expected.f2, expected.f3 = True, "abc", ["abc", "abc"]
644 bytes1 = fory.serialize(expected)
645 assert fory.deserialize(bytes1) == expected
646 new_obj = fory.deserialize(buffer)
647
648 debug_print(new_obj)
649 assert new_obj == expected
650 new_buf = pyfory.Buffer.allocate(32)
651 fory.serialize(new_obj, buffer=new_buf)
652 bytes1 = fory.serialize(new_obj)
653 assert len(bytes1) == len(data_bytes), (bytes1, data_bytes)
654 # header can differ across writers
655 assert bytes1[8:] == data_bytes[8:]
656 assert fory.deserialize(fory.serialize(new_obj)) == new_obj, new_obj
657 print(f"test_register_serializer: {new_obj}")
658 with open(data_file_path, "wb+") as f:
659 f.write(new_buf.get_bytes(0, new_buf.get_writer_index()))
660
661
662@cross_language_test

Callers

nothing calls this directly

Calls 12

register_typeMethod · 0.95
serializeMethod · 0.95
deserializeMethod · 0.95
get_bytesMethod · 0.80
ComplexObject1Class · 0.70
debug_printFunction · 0.70
readMethod · 0.65
allocateMethod · 0.65
writeMethod · 0.65
BufferMethod · 0.45
ForyMethod · 0.45

Tested by

no test coverage detected