@@ -69,7 +69,10 @@ enum BonSerializerCmd : byte
69
69
NextArray ,
70
70
InitList ,
71
71
InitHashSet ,
72
- NextHashSet
72
+ NextHashSet ,
73
+ InitDictionary ,
74
+ NextDictionary ,
75
+ AddOffset
73
76
}
74
77
75
78
public ref struct BonSerializerCtx
@@ -267,6 +270,24 @@ public void Generate()
267
270
return ;
268
271
}
269
272
273
+ if ( _type . SpecializationOf ( typeof ( Dictionary < , > ) ) is { } dictionaryType )
274
+ {
275
+ _memWriter . WriteUInt8 ( ( byte ) BonSerializerCmd . InitDictionary ) ;
276
+ var keyType = dictionaryType . GetGenericArguments ( ) [ 0 ] ;
277
+ var valueType = dictionaryType . GetGenericArguments ( ) [ 1 ] ;
278
+ var layout = RawData . GetDictionaryEntriesLayout ( keyType , valueType ) ;
279
+ _memWriter . WriteUInt8 ( ( byte ) BonSerializerCmd . AddOffset ) ;
280
+ _memWriter . WriteVUInt32 ( layout . OffsetKey ) ;
281
+ WriteCmdByType ( null , keyType ) ;
282
+ _memWriter . WriteUInt8 ( ( byte ) BonSerializerCmd . AddOffset ) ;
283
+ _memWriter . WriteVUInt32 ( layout . OffsetValue - layout . OffsetKey ) ;
284
+ WriteCmdByType ( null , valueType ) ;
285
+ _memWriter . WriteUInt8 ( ( byte ) BonSerializerCmd . AddOffset ) ;
286
+ _memWriter . WriteVUInt32 ( layout . Size - layout . OffsetValue ) ;
287
+ _memWriter . WriteUInt8 ( ( byte ) BonSerializerCmd . NextDictionary ) ;
288
+ return ;
289
+ }
290
+
270
291
var classMetadata = ReflectionMetadata . FindByType ( _type ) ;
271
292
if ( classMetadata != null )
272
293
{
@@ -707,6 +728,55 @@ public unsafe BonSerialize Build()
707
728
708
729
break ;
709
730
}
731
+ case BonSerializerCmd . AddOffset :
732
+ offset += reader . ReadVUInt32 ( ) ;
733
+ break ;
734
+ case BonSerializerCmd . InitDictionary :
735
+ {
736
+ tempObject2 = Unsafe . As < byte , object > ( ref value ) ;
737
+ var count = Unsafe . As < byte , int > ( ref RawData . Ref ( tempObject2 ,
738
+ RawData . Align ( 8 + 6 * ( uint ) Unsafe . SizeOf < nint > ( ) , 8 ) ) ) ;
739
+ tempObject2 = RawData . HashSetEntries ( Unsafe . As < HashSet < object > > ( tempObject2 ) ) ;
740
+ ref readonly var mt = ref RawData . MethodTableRef ( tempObject2 ) ;
741
+ offset = mt . BaseSize - ( uint ) Unsafe . SizeOf < nint > ( ) ;
742
+ offsetDelta = mt . ComponentSize ;
743
+ offsetFinal = offset + offsetDelta * ( uint ) count ;
744
+ offsetLabel = ( uint ) reader . GetCurrentPositionWithoutController ( ) ;
745
+ ctx . Builder . StartDictionary ( ) ;
746
+ while ( offset < offsetFinal )
747
+ {
748
+ if ( Unsafe . As < byte , int > ( ref RawData . Ref ( tempObject2 , offset + 4 ) ) >= - 1 ) break ;
749
+ offset += offsetDelta ;
750
+ }
751
+
752
+ if ( offset >= offsetFinal )
753
+ {
754
+ ctx . Builder . FinishDictionary ( ) ;
755
+ return ;
756
+ }
757
+
758
+ break ;
759
+ }
760
+ case BonSerializerCmd . NextDictionary :
761
+ {
762
+ while ( offset < offsetFinal )
763
+ {
764
+ if ( Unsafe . As < byte , int > ( ref RawData . Ref ( tempObject2 , offset + 4 ) ) >= - 1 ) break ;
765
+ offset += offsetDelta ;
766
+ }
767
+
768
+ if ( offset < offsetFinal )
769
+ {
770
+ reader . SetCurrentPositionWithoutController ( offsetLabel ) ;
771
+ }
772
+ else
773
+ {
774
+ ctx . Builder . FinishDictionary ( ) ;
775
+ return ;
776
+ }
777
+
778
+ break ;
779
+ }
710
780
default :
711
781
throw new InvalidDataException ( "Unknown command in BonSerializer " + ( byte ) cmd + " at " +
712
782
( reader . GetCurrentPosition ( ) - 1 ) ) ;
0 commit comments