(ctx *ReadContext, value reflect.Value)
| 1499 | } |
| 1500 | |
| 1501 | func (s bfloat16SliceSerializer) ReadData(ctx *ReadContext, value reflect.Value) { |
| 1502 | buf := ctx.Buffer() |
| 1503 | ctxErr := ctx.Err() |
| 1504 | size := ctx.ReadBinaryLength() |
| 1505 | if ctx.HasError() { |
| 1506 | return |
| 1507 | } |
| 1508 | if size%2 != 0 { |
| 1509 | ctx.SetError(DeserializationErrorf("bfloat16 array byte length %d is not aligned to element size 2", size)) |
| 1510 | return |
| 1511 | } |
| 1512 | length := size / 2 |
| 1513 | |
| 1514 | ptr := (*[]bfloat16.BFloat16)(value.Addr().UnsafePointer()) |
| 1515 | if length == 0 { |
| 1516 | *ptr = make([]bfloat16.BFloat16, 0) |
| 1517 | return |
| 1518 | } |
| 1519 | |
| 1520 | if !buf.CheckReadable(size, ctxErr) { |
| 1521 | return |
| 1522 | } |
| 1523 | result := make([]bfloat16.BFloat16, length) |
| 1524 | |
| 1525 | if isLittleEndian { |
| 1526 | targetPtr := unsafe.Pointer(&result[0]) |
| 1527 | buf.Read(unsafe.Slice((*byte)(targetPtr), size)) |
| 1528 | } else { |
| 1529 | for i := 0; i < length; i++ { |
| 1530 | result[i] = bfloat16.BFloat16FromBits(buf.ReadUint16(ctxErr)) |
| 1531 | } |
| 1532 | } |
| 1533 | *ptr = result |
| 1534 | } |
no test coverage detected