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

Method WriteData

go/fory/slice_primitive.go:1142–1163  ·  view source on GitHub ↗
(ctx *WriteContext, value reflect.Value)

Source from the content-addressed store, hash-verified

1140type float16SliceSerializer struct{}
1141
1142func (s float16SliceSerializer) WriteData(ctx *WriteContext, value reflect.Value) {
1143 // Cast to []float16.Float16
1144 v := value.Interface().([]float16.Float16)
1145 buf := ctx.Buffer()
1146 length := len(v)
1147 size := length * 2
1148 buf.WriteLength(size)
1149 if length > 0 {
1150 // Float16 is uint16 underneath, so we can cast slice pointer
1151 ptr := unsafe.Pointer(&v[0])
1152 if isLittleEndian {
1153 buf.WriteBinary(unsafe.Slice((*byte)(ptr), size))
1154 } else {
1155 // Big-endian architectures need explicit byte swapping
1156 for i := 0; i < length; i++ {
1157 // We can just write as uint16, WriteUint16 handles endianness for us
1158 // Float16.Bits() returns uint16
1159 buf.WriteUint16(v[i].Bits())
1160 }
1161 }
1162 }
1163}
1164
1165func (s float16SliceSerializer) Write(ctx *WriteContext, refMode RefMode, writeType bool, hasGenerics bool, value reflect.Value) {
1166 done := writeSliceRefAndType(ctx, refMode, writeType, value, FLOAT16_ARRAY)

Callers 1

WriteMethod · 0.95

Calls 6

SliceMethod · 0.80
WriteUint16Method · 0.80
BufferMethod · 0.45
WriteLengthMethod · 0.45
WriteBinaryMethod · 0.45
BitsMethod · 0.45

Tested by

no test coverage detected