ToUint16Array converts the value to uint16 slice if it's a Uint16Array.
()
| 912 | |
| 913 | // ToUint16Array converts the value to uint16 slice if it's a Uint16Array. |
| 914 | func (v *Value) ToUint16Array() ([]uint16, error) { |
| 915 | if !v.IsUint16Array() { |
| 916 | return nil, errors.New("value is not a Uint16Array") |
| 917 | } |
| 918 | |
| 919 | buffer, byteOffset, byteLength, _ := v.getTypedArrayInfo() |
| 920 | defer buffer.Free() |
| 921 | |
| 922 | totalSize := uint(byteOffset + byteLength) |
| 923 | bytes, err := buffer.ToByteArray(totalSize) |
| 924 | if err != nil { |
| 925 | return nil, err |
| 926 | } |
| 927 | |
| 928 | data := bytes[byteOffset : byteOffset+byteLength] |
| 929 | result := make([]uint16, len(data)/2) |
| 930 | for i := 0; i < len(result); i++ { |
| 931 | result[i] = binary.LittleEndian.Uint16(data[i*2:]) |
| 932 | } |
| 933 | return result, nil |
| 934 | } |
| 935 | |
| 936 | // ToInt32Array converts the value to int32 slice if it's an Int32Array. |
| 937 | func (v *Value) ToInt32Array() ([]int32, error) { |