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

Method ReadData

go/fory/slice_primitive.go:1189–1225  ·  view source on GitHub ↗
(ctx *ReadContext, value reflect.Value)

Source from the content-addressed store, hash-verified

1187}
1188
1189func (s float16SliceSerializer) ReadData(ctx *ReadContext, value reflect.Value) {
1190 buf := ctx.Buffer()
1191 ctxErr := ctx.Err()
1192 size := ctx.ReadBinaryLength()
1193 if ctx.HasError() {
1194 return
1195 }
1196 if size%2 != 0 {
1197 ctx.SetError(DeserializationErrorf("float16 array byte length %d is not aligned to element size 2", size))
1198 return
1199 }
1200 length := size / 2
1201
1202 // Ensure capacity
1203 ptr := (*[]float16.Float16)(value.Addr().UnsafePointer())
1204 if length == 0 {
1205 *ptr = make([]float16.Float16, 0)
1206 return
1207 }
1208
1209 if !buf.CheckReadable(size, ctxErr) {
1210 return
1211 }
1212 result := make([]float16.Float16, length)
1213
1214 if isLittleEndian {
1215 // unsafe copy
1216 targetPtr := unsafe.Pointer(&result[0])
1217 buf.Read(unsafe.Slice((*byte)(targetPtr), size))
1218 } else {
1219 for i := 0; i < length; i++ {
1220 // ReadUint16 handles endianness
1221 result[i] = float16.Float16FromBits(buf.ReadUint16(ctxErr))
1222 }
1223 }
1224 *ptr = result
1225}
1226
1227// WriteIntSlice writes []int to buffer using ARRAY protocol
1228func WriteIntSlice(buf *ByteBuffer, value []int) {

Callers 1

ReadMethod · 0.95

Calls 10

DeserializationErrorfFunction · 0.85
ReadBinaryLengthMethod · 0.80
CheckReadableMethod · 0.80
SliceMethod · 0.80
ReadUint16Method · 0.80
ReadMethod · 0.65
BufferMethod · 0.45
ErrMethod · 0.45
HasErrorMethod · 0.45
SetErrorMethod · 0.45

Tested by

no test coverage detected