ToInt32Array converts the value to int32 slice if it's an Int32Array.
()
| 935 | |
| 936 | // ToInt32Array converts the value to int32 slice if it's an Int32Array. |
| 937 | func (v *Value) ToInt32Array() ([]int32, error) { |
| 938 | if !v.IsInt32Array() { |
| 939 | return nil, errors.New("value is not an Int32Array") |
| 940 | } |
| 941 | |
| 942 | buffer, byteOffset, byteLength, _ := v.getTypedArrayInfo() |
| 943 | defer buffer.Free() |
| 944 | |
| 945 | totalSize := uint(byteOffset + byteLength) |
| 946 | bytes, err := buffer.ToByteArray(totalSize) |
| 947 | if err != nil { |
| 948 | return nil, err |
| 949 | } |
| 950 | |
| 951 | data := bytes[byteOffset : byteOffset+byteLength] |
| 952 | result := make([]int32, len(data)/4) |
| 953 | for i := 0; i < len(result); i++ { |
| 954 | result[i] = int32(binary.LittleEndian.Uint32(data[i*4:])) |
| 955 | } |
| 956 | return result, nil |
| 957 | } |
| 958 | |
| 959 | // ToUint32Array converts the value to uint32 slice if it's a Uint32Array. |
| 960 | func (v *Value) ToUint32Array() ([]uint32, error) { |