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

Method ReadArrayValue

go/fory/reader.go:966–1029  ·  view source on GitHub ↗

ReadArrayValue handles array targets with configurable ref mode and type reading. Arrays are serialized as slices in xlang protocol.

(target reflect.Value, refMode RefMode, readType bool)

Source from the content-addressed store, hash-verified

964// ReadArrayValue handles array targets with configurable ref mode and type reading.
965// Arrays are serialized as slices in xlang protocol.
966func (c *ReadContext) ReadArrayValue(target reflect.Value, refMode RefMode, readType bool) {
967 var refID int32 = int32(NotNullValueFlag)
968
969 // Handle ref tracking based on refMode
970 if refMode == RefModeTracking {
971 var err error
972 refID, err = c.RefResolver().TryPreserveRefId(c.buffer)
973 if err != nil {
974 c.SetError(FromError(err))
975 return
976 }
977 if refID < int32(NotNullValueFlag) {
978 // Reference to existing object
979 obj := c.RefResolver().GetReadObject(refID)
980 if obj.IsValid() {
981 reflect.Copy(target, obj)
982 }
983 return
984 }
985 } else if refMode == RefModeNullOnly {
986 flag := c.buffer.ReadInt8(c.Err())
987 if flag == NullFlag {
988 return
989 }
990 }
991
992 // Read type ID if requested (will be slice type in stream)
993 if readType {
994 c.buffer.ReadUint8(c.Err())
995 }
996
997 // Get slice serializer to read the data
998 sliceType := reflect.SliceOf(target.Type().Elem())
999 serializer, err := c.typeResolver.getSerializerByType(sliceType, false)
1000 if err != nil {
1001 c.SetError(DeserializationErrorf("failed to get serializer for slice type %v: %v", sliceType, err))
1002 return
1003 }
1004
1005 // Create addressable temporary slice using reflect.New
1006 tempSlicePtr := reflect.New(sliceType)
1007 tempSlice := tempSlicePtr.Elem()
1008 tempSlice.Set(reflect.MakeSlice(sliceType, target.Len(), target.Len()))
1009
1010 // Use ReadData to read slice data (ref/type already handled)
1011 serializer.ReadData(c, tempSlice)
1012 if c.HasError() {
1013 return
1014 }
1015
1016 // Verify length matches
1017 if tempSlice.Len() != target.Len() {
1018 c.SetError(DeserializationErrorf("array length mismatch: got %d, want %d", tempSlice.Len(), target.Len()))
1019 return
1020 }
1021
1022 // Copy to array
1023 reflect.Copy(target, tempSlice)

Callers 1

ReadValueMethod · 0.95

Calls 15

RefResolverMethod · 0.95
SetErrorMethod · 0.95
ErrMethod · 0.95
HasErrorMethod · 0.95
FromErrorFunction · 0.85
DeserializationErrorfFunction · 0.85
TryPreserveRefIdMethod · 0.80
GetReadObjectMethod · 0.80
ReadUint8Method · 0.80
getSerializerByTypeMethod · 0.80
LenMethod · 0.80
SetReadObjectMethod · 0.80

Tested by

no test coverage detected