ReadInt16Slice reads []int16 from buffer using ARRAY protocol
(buf *ByteBuffer, err *Error)
| 790 | |
| 791 | // ReadInt16Slice reads []int16 from buffer using ARRAY protocol |
| 792 | func 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 |
| 822 | func WriteInt32Slice(buf *ByteBuffer, value []int32) { |