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

Method ReadCollectionData

csharp/src/Fory/CollectionSerializers.cs:198–309  ·  view source on GitHub ↗
(Serializer<T> elementSerializer, ReadContext context)

Source from the content-addressed store, hash-verified

196 }
197
198 public static List<T> ReadCollectionData<T>(Serializer<T> elementSerializer, ReadContext context)
199 {
200 TypeInfo elementTypeInfo = context.TypeResolver.GetTypeInfo<T>();
201 int length = checked((int)context.Reader.ReadVarUInt32());
202 if (length == 0)
203 {
204 return [];
205 }
206
207 byte header = context.Reader.ReadUInt8();
208 // IMPORTANT: collection readers must obey the ref/null bits written on
209 // the wire, not the local generic metadata that may imply a different
210 // ref policy. Shared xlang tests intentionally deserialize one ref
211 // policy and then serialize another local payload. DO NOT REMOVE this comment.
212 bool trackRef = (header & CollectionBits.TrackingRef) != 0;
213 bool hasNull = (header & CollectionBits.HasNull) != 0;
214 bool declared = (header & CollectionBits.DeclaredElementType) != 0;
215 bool sameType = (header & CollectionBits.SameType) != 0;
216 context.Reader.CheckBound(length);
217 List<T> values = new(length);
218 if (!sameType)
219 {
220 if (trackRef)
221 {
222 for (int i = 0; i < length; i++)
223 {
224 values.Add(elementSerializer.Read(context, RefMode.Tracking, true));
225 }
226
227 return values;
228 }
229
230 if (hasNull)
231 {
232 for (int i = 0; i < length; i++)
233 {
234 sbyte refFlag = context.Reader.ReadInt8();
235 if (refFlag == (sbyte)RefFlag.Null)
236 {
237 values.Add((T)elementSerializer.DefaultObject!);
238 }
239 else if (refFlag == (sbyte)RefFlag.NotNullValue)
240 {
241 values.Add(elementSerializer.Read(context, RefMode.None, true));
242 }
243 else
244 {
245 throw new RefException($"invalid nullability flag {refFlag}");
246 }
247 }
248 }
249 else
250 {
251 for (int i = 0; i < length; i++)
252 {
253 values.Add(elementSerializer.Read(context, RefMode.None, true));
254 }
255 }

Callers 7

ReadDataMethod · 0.80
ReadDataMethod · 0.80
ReadDataMethod · 0.80
ReadDataMethod · 0.80
ReadDataMethod · 0.80
ReadDataMethod · 0.80
ReadDataMethod · 0.80

Calls 9

ReadVarUInt32Method · 0.80
ReadUInt8Method · 0.80
CheckBoundMethod · 0.80
ClearReadTypeInfoMethod · 0.80
ReadMethod · 0.65
ReadDataMethod · 0.65
AddMethod · 0.45
ReadInt8Method · 0.45
ReadTypeInfoMethod · 0.45

Tested by

no test coverage detected