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

Function ReadFloat32Slice

go/fory/slice_primitive.go:1062–1089  ·  view source on GitHub ↗

ReadFloat32Slice reads []float32 from buffer using ARRAY protocol

(buf *ByteBuffer, err *Error)

Source from the content-addressed store, hash-verified

1060
1061// ReadFloat32Slice reads []float32 from buffer using ARRAY protocol
1062func ReadFloat32Slice(buf *ByteBuffer, err *Error) []float32 {
1063 byteSize := buf.ReadLength(err)
1064 if err.HasError() {
1065 return nil
1066 }
1067 if byteSize%4 != 0 {
1068 *err = DeserializationErrorf("array byte size %d is not aligned to element size %d", byteSize, 4)
1069 return nil
1070 }
1071 if byteSize == 0 {
1072 return make([]float32, 0)
1073 }
1074 if !buf.CheckReadable(byteSize, err) {
1075 return nil
1076 }
1077 length := byteSize / 4
1078 if isLittleEndian {
1079 result := make([]float32, length)
1080 buf.Read(unsafe.Slice((*byte)(unsafe.Pointer(&result[0])), byteSize))
1081 return result
1082 } else {
1083 result := make([]float32, length)
1084 for i := 0; i < length; i++ {
1085 result[i] = buf.ReadFloat32(err)
1086 }
1087 return result
1088 }
1089}
1090
1091// WriteFloat64Slice writes []float64 to buffer using ARRAY protocol
1092func WriteFloat64Slice(buf *ByteBuffer, value []float64) {

Callers 2

ReadDataMethod · 0.85
ReadFloat32SliceMethod · 0.85

Calls 7

DeserializationErrorfFunction · 0.85
ReadLengthMethod · 0.80
CheckReadableMethod · 0.80
SliceMethod · 0.80
ReadMethod · 0.65
HasErrorMethod · 0.45
ReadFloat32Method · 0.45

Tested by

no test coverage detected