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

Method WriteData

go/fory/array.go:121–217  ·  view source on GitHub ↗
(ctx *WriteContext, value reflect.Value)

Source from the content-addressed store, hash-verified

119}
120
121func (s *arrayConcreteValueSerializer) WriteData(ctx *WriteContext, value reflect.Value) {
122 length := value.Len()
123 buf := ctx.Buffer()
124
125 // Write length
126 buf.WriteVarUint32(uint32(length))
127 if length == 0 {
128 return
129 }
130
131 // Determine collection flags - same logic as slices
132 collectFlag := CollectionIsSameType
133 hasNull := false
134 elemType := s.type_.Elem()
135 isPointerElem := elemType.Kind() == reflect.Ptr
136
137 // Check for null values (only for pointer element types)
138 if isPointerElem {
139 for i := 0; i < length; i++ {
140 elem := value.Index(i)
141 if elem.IsNil() {
142 hasNull = true
143 break
144 }
145 }
146 }
147
148 if hasNull {
149 collectFlag |= CollectionHasNull
150 }
151 if ctx.TrackRef() && s.referencable {
152 collectFlag |= CollectionTrackingRef
153 }
154 buf.WriteInt8(int8(collectFlag))
155
156 // Write element type info
157 var elemTypeInfo *TypeInfo
158 if length > 0 {
159 // Get type info for the first non-nil element
160 for i := 0; i < length; i++ {
161 elem := value.Index(i)
162 if isPointerElem {
163 if !elem.IsNil() {
164 elemTypeInfo, _ = ctx.TypeResolver().getTypeInfo(elem.Elem(), true)
165 break
166 }
167 } else {
168 elemTypeInfo, _ = ctx.TypeResolver().getTypeInfo(elem, true)
169 break
170 }
171 }
172 }
173
174 // Write element type info (handles namespaced types)
175 var internalTypeID uint32
176 if elemTypeInfo != nil {
177 internalTypeID = elemTypeInfo.TypeID
178 }

Callers 1

WriteMethod · 0.95

Calls 15

LenMethod · 0.80
KindMethod · 0.80
WriteUint8Method · 0.80
WriteMethod · 0.65
WriteDataMethod · 0.65
uint32Function · 0.50
int8Function · 0.50
uint8Function · 0.50
BufferMethod · 0.45
WriteVarUint32Method · 0.45
TrackRefMethod · 0.45
WriteInt8Method · 0.45

Tested by

no test coverage detected