(ctx *ReadContext, value reflect.Value)
| 1187 | } |
| 1188 | |
| 1189 | func (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 |
| 1228 | func WriteIntSlice(buf *ByteBuffer, value []int) { |
no test coverage detected