@@ -674,6 +674,102 @@ def buffer_callback(binary_object):
674674 f .write (out_of_band_buffer .to_bytes (0 , out_of_band_buffer .writer_index ))
675675
676676
677+ @cross_language_test
678+ def test_cross_language_meta_share (data_file_path ):
679+ """Test cross-language meta sharing with ComplexObject2."""
680+ fory = pyfory .Fory (language = pyfory .Language .XLANG , compatible = True , ref_tracking = True )
681+
682+ @dataclass
683+ class ComplexObject2 :
684+ f1 : Any
685+ f2 : Dict [int , int ] # Use plain int types to avoid type annotation issues
686+
687+ fory .register_type (ComplexObject2 , namespace = "test" , typename = "ComplexObject2" )
688+
689+ with open (data_file_path , "rb" ) as f :
690+ data_bytes = f .read ()
691+
692+ debug_print (f"Reading data of length { len (data_bytes )} from { data_file_path } " )
693+
694+ # Deserialize Java-generated data with meta share
695+ obj = fory .deserialize (data_bytes )
696+ debug_print (f"Deserialized object: { obj } " )
697+
698+ # Verify the object structure
699+ assert obj .f1 is True # Boolean value
700+ assert isinstance (obj .f2 , dict )
701+ assert obj .f2 [- 1 ] == 2 # Dict[Int8, Int32] with key=-1, value=2
702+
703+ # Serialize back with meta share
704+ new_serialized = fory .serialize (obj )
705+ debug_print (f"Re-serialized data length: { len (new_serialized )} " )
706+
707+ # Verify round-trip
708+ round_trip_obj = fory .deserialize (new_serialized )
709+ assert round_trip_obj == obj
710+
711+ # Write back for Java to verify
712+ with open (data_file_path , "wb" ) as f :
713+ f .write (new_serialized )
714+
715+
716+ @cross_language_test
717+ def test_cross_language_meta_share_complex (data_file_path ):
718+ """Test cross-language meta sharing with complex nested objects."""
719+ fory = pyfory .Fory (language = pyfory .Language .XLANG , compatible = True , ref_tracking = True )
720+
721+ @dataclass
722+ class ComplexObject2 :
723+ f1 : Any
724+ f2 : Dict [int , int ]
725+
726+ @dataclass
727+ class ComplexObject1 :
728+ f1 : Any
729+ f2 : str
730+ f3 : List [str ]
731+ f4 : Dict [int , int ]
732+ f5 : int
733+ f6 : int
734+ f7 : int
735+ f8 : int
736+ f9 : float
737+ f10 : float
738+ f11 : List [int ] # Simplified from array
739+ f12 : List [int ]
740+
741+ fory .register_type (ComplexObject1 , namespace = "test" , typename = "ComplexObject1" )
742+ fory .register_type (ComplexObject2 , namespace = "test" , typename = "ComplexObject2" )
743+
744+ with open (data_file_path , "rb" ) as f :
745+ data_bytes = f .read ()
746+
747+ debug_print (f"Reading complex data of length { len (data_bytes )} from { data_file_path } " )
748+
749+ # Deserialize Java-generated complex object with meta share
750+ obj = fory .deserialize (data_bytes )
751+ debug_print (f"Deserialized complex object: { obj } " )
752+
753+ # Verify the nested object structure
754+ assert hasattr (obj , 'f1' ) and hasattr (obj .f1 , 'f1' ) and hasattr (obj .f1 , 'f2' )
755+ assert obj .f1 .f1 is True
756+ assert isinstance (obj .f1 .f2 , dict )
757+ assert obj .f2 == "meta_share_test"
758+ assert obj .f3 == ["compatible" , "mode" ]
759+
760+ # Serialize back with meta share
761+ new_serialized = fory .serialize (obj )
762+ debug_print (f"Re-serialized complex data length: { len (new_serialized )} " )
763+
764+ # Verify round-trip
765+ round_trip_obj = fory .deserialize (new_serialized )
766+ assert round_trip_obj == obj
767+
768+ # Write back for Java to verify
769+ with open (data_file_path , "wb" ) as f :
770+ f .write (new_serialized )
771+
772+
677773if __name__ == "__main__" :
678774 """This file will be executed by CrossLanguageTest.java in fory-core/fory-format module and
679775 fory_xlang_test.go in go/fory module
0 commit comments