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

Function ReadInt16Slice

go/fory/slice_primitive.go:792–819  ·  view source on GitHub ↗

ReadInt16Slice reads []int16 from buffer using ARRAY protocol

(buf *ByteBuffer, err *Error)

Source from the content-addressed store, hash-verified

790
791// ReadInt16Slice reads []int16 from buffer using ARRAY protocol
792func ReadInt16Slice(buf *ByteBuffer, err *Error) []int16 {
793 byteSize := buf.ReadLength(err)
794 if err.HasError() {
795 return nil
796 }
797 if byteSize%2 != 0 {
798 *err = DeserializationErrorf("array byte size %d is not aligned to element size %d", byteSize, 2)
799 return nil
800 }
801 if byteSize == 0 {
802 return make([]int16, 0)
803 }
804 if !buf.CheckReadable(byteSize, err) {
805 return nil
806 }
807 length := byteSize / 2
808 if isLittleEndian {
809 result := make([]int16, length)
810 buf.Read(unsafe.Slice((*byte)(unsafe.Pointer(&result[0])), byteSize))
811 return result
812 } else {
813 result := make([]int16, length)
814 for i := 0; i < length; i++ {
815 result[i] = buf.ReadInt16(err)
816 }
817 return result
818 }
819}
820
821// WriteInt32Slice writes []int32 to buffer using ARRAY protocol
822func WriteInt32Slice(buf *ByteBuffer, value []int32) {

Callers 3

ReadDataMethod · 0.85
ReadInt16SliceMethod · 0.85

Calls 7

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

Tested by 1