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

Method WriteData

go/fory/slice_dyn.go:78–99  ·  view source on GitHub ↗
(ctx *WriteContext, value reflect.Value)

Source from the content-addressed store, hash-verified

76}
77
78func (s sliceDynSerializer) WriteData(ctx *WriteContext, value reflect.Value) {
79 buf := ctx.Buffer()
80 // Get slice length and handle empty slice case
81 length := value.Len()
82 if length == 0 {
83 buf.WriteVarUint32(0) // WriteData 0 for empty slice
84 return
85 }
86
87 // WriteData collection header and get type information
88 collectFlag, elemTypeInfo := s.writeHeader(ctx, buf, value)
89 if ctx.HasError() {
90 return
91 }
92
93 // Choose serialization path based on type consistency
94 if (collectFlag & CollectionIsSameType) != 0 {
95 s.writeSameType(ctx, buf, value, elemTypeInfo, collectFlag) // Optimized path for same-type elements
96 } else {
97 s.writeDifferentTypes(ctx, buf, value, collectFlag) // Fallback path for mixed-type elements
98 }
99}
100
101// writeHeader prepares and writes collection metadata including:
102// - Collection size

Callers 1

WriteMethod · 0.95

Calls 7

writeHeaderMethod · 0.95
writeSameTypeMethod · 0.95
writeDifferentTypesMethod · 0.95
LenMethod · 0.80
BufferMethod · 0.45
WriteVarUint32Method · 0.45
HasErrorMethod · 0.45

Tested by

no test coverage detected