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

Method WriteData

go/fory/map.go:63–119  ·  view source on GitHub ↗

WriteData serializes map data using chunk protocol

(ctx *WriteContext, value reflect.Value)

Source from the content-addressed store, hash-verified

61
62// WriteData serializes map data using chunk protocol
63func (s mapSerializer) WriteData(ctx *WriteContext, value reflect.Value) {
64 buf := ctx.Buffer()
65 value = unwrapInterface(value)
66 length := value.Len()
67 buf.WriteVarUint32(uint32(length))
68 if length == 0 {
69 return
70 }
71
72 iter := value.MapRange()
73 if !iter.Next() {
74 return
75 }
76
77 typeResolver := ctx.TypeResolver()
78 trackRef := ctx.TrackRef()
79 entryKey := unwrapInterface(iter.Key())
80 entryVal := unwrapInterface(iter.Value())
81 hasNext := true
82
83 for hasNext {
84 // Phase 1: Handle null entries (single-item chunks)
85 for {
86 keyValid := entryKey.IsValid()
87 valValid := entryVal.IsValid()
88
89 if keyValid && valValid {
90 break // Proceed to regular chunk
91 }
92
93 if !keyValid && !valValid {
94 buf.WriteInt8(KV_NULL)
95 } else if !valValid {
96 s.writeNullValueEntry(ctx, entryKey, typeResolver, trackRef)
97 } else {
98 s.writeNullKeyEntry(ctx, entryVal, typeResolver, trackRef)
99 }
100
101 if ctx.HasError() {
102 return
103 }
104
105 if iter.Next() {
106 entryKey = unwrapInterface(iter.Key())
107 entryVal = unwrapInterface(iter.Value())
108 } else {
109 return
110 }
111 }
112
113 // Phase 2: Write regular chunk with same-type entries
114 hasNext = s.writeChunk(ctx, iter, &entryKey, &entryVal, typeResolver, trackRef)
115 if ctx.HasError() {
116 return
117 }
118 }
119}
120

Callers 1

WriteMethod · 0.95

Calls 12

writeNullValueEntryMethod · 0.95
writeNullKeyEntryMethod · 0.95
writeChunkMethod · 0.95
unwrapInterfaceFunction · 0.85
LenMethod · 0.80
uint32Function · 0.50
BufferMethod · 0.45
WriteVarUint32Method · 0.45
TypeResolverMethod · 0.45
TrackRefMethod · 0.45
WriteInt8Method · 0.45
HasErrorMethod · 0.45

Tested by

no test coverage detected