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

Method Read

go/fory/pointer.go:157–208  ·  view source on GitHub ↗
(ctx *ReadContext, refMode RefMode, readType bool, hasGenerics bool, value reflect.Value)

Source from the content-addressed store, hash-verified

155}
156
157func (s *ptrToValueSerializer) Read(ctx *ReadContext, refMode RefMode, readType bool, hasGenerics bool, value reflect.Value) {
158 buf := ctx.Buffer()
159 ctxErr := ctx.Err()
160 switch refMode {
161 case RefModeTracking:
162 refID, refErr := ctx.RefResolver().TryPreserveRefId(buf)
163 if refErr != nil {
164 ctx.SetError(FromError(refErr))
165 return
166 }
167 if refID < int32(NotNullValueFlag) {
168 // Reference found
169 obj := ctx.RefResolver().GetReadObject(refID)
170 if obj.IsValid() {
171 value.Set(obj)
172 }
173 return
174 }
175 case RefModeNullOnly:
176 flag := buf.ReadInt8(ctxErr)
177 if flag == NullFlag {
178 return
179 }
180 case RefModeNone:
181 // For RefModeNone with nullable=false, no null flag was written.
182 // Just continue to read the value data directly.
183 }
184 if readType {
185 // Read type info - in compatible mode this contains the serializer with fieldDefs
186 typeID := uint32(buf.ReadUint8(ctxErr))
187 if ctx.HasError() {
188 return
189 }
190 internalTypeID := TypeId(typeID)
191 // Check if this is a struct type that needs type meta reading
192 if IsNamespacedType(internalTypeID) || internalTypeID == COMPATIBLE_STRUCT || internalTypeID == STRUCT {
193 typeInfo := ctx.TypeResolver().readTypeInfoWithTypeID(buf, typeID, ctxErr)
194 // Use the serializer from TypeInfo which has the remote field definitions
195 if structSer, ok := typeInfo.Serializer.(*structSerializer); ok && len(structSer.fieldDefs) > 0 {
196 // Allocate the pointer value if needed
197 if value.IsNil() {
198 value.Set(reflect.New(value.Type().Elem()))
199 }
200 ctx.RefResolver().Reference(value)
201 structSer.ReadData(ctx, value.Elem())
202 return
203 }
204 }
205 }
206
207 s.ReadData(ctx, value)
208}
209
210func (s *ptrToValueSerializer) ReadWithTypeInfo(ctx *ReadContext, refMode RefMode, typeInfo *TypeInfo, value reflect.Value) {
211 s.Read(ctx, refMode, false, false, value)

Callers 1

ReadWithTypeInfoMethod · 0.95

Calls 15

ReadDataMethod · 0.95
FromErrorFunction · 0.85
IsNamespacedTypeFunction · 0.85
TryPreserveRefIdMethod · 0.80
GetReadObjectMethod · 0.80
ReadUint8Method · 0.80
ReadDataMethod · 0.65
int32Function · 0.50
uint32Function · 0.50
TypeIdEnum · 0.50
BufferMethod · 0.45

Tested by

no test coverage detected