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

Method writeSameType

go/fory/set.go:220–260  ·  view source on GitHub ↗

writeSameType efficiently serializes a collection where all elements share the same type

(ctx *WriteContext, buf *ByteBuffer, keys []reflect.Value, typeInfo *TypeInfo, flag byte)

Source from the content-addressed store, hash-verified

218
219// writeSameType efficiently serializes a collection where all elements share the same type
220func (s setSerializer) writeSameType(ctx *WriteContext, buf *ByteBuffer, keys []reflect.Value, typeInfo *TypeInfo, flag byte) {
221 if typeInfo == nil && s.elemSerializer == nil {
222 return
223 }
224 serializer := s.elemSerializer
225 if serializer == nil {
226 serializer = typeInfo.Serializer
227 }
228 trackRefs := (flag & CollectionTrackingRef) != 0 // Check if reference tracking is enabled
229 declaredGenerics := (flag & CollectionIsDeclElementType) != 0
230
231 for _, key := range keys {
232 key = UnwrapReflectValue(key)
233 if isNull(key) {
234 buf.WriteInt8(NullFlag) // WriteData null marker
235 continue
236 }
237
238 if trackRefs {
239 // Handle reference tracking if enabled
240 refWritten, err := ctx.RefResolver().WriteRefOrNull(buf, key)
241 if err != nil {
242 ctx.SetError(FromError(err))
243 return
244 }
245 if !refWritten {
246 // WriteData actual value if not a reference
247 writeSerializerData(ctx, serializer, declaredGenerics, key)
248 if ctx.HasError() {
249 return
250 }
251 }
252 } else {
253 // Directly write value without reference tracking
254 writeSerializerData(ctx, serializer, declaredGenerics, key)
255 if ctx.HasError() {
256 return
257 }
258 }
259 }
260}
261
262// writeDifferentTypes handles serialization of collections with mixed element types
263func (s setSerializer) writeDifferentTypes(ctx *WriteContext, buf *ByteBuffer, keys []reflect.Value, flag byte) {

Callers 1

writeDataWithGenericsMethod · 0.95

Calls 9

UnwrapReflectValueFunction · 0.85
isNullFunction · 0.85
FromErrorFunction · 0.85
writeSerializerDataFunction · 0.85
WriteRefOrNullMethod · 0.80
WriteInt8Method · 0.45
RefResolverMethod · 0.45
SetErrorMethod · 0.45
HasErrorMethod · 0.45

Tested by

no test coverage detected