ToUint32Array converts the value to uint32 slice if it's a Uint32Array.
()
| 958 | |
| 959 | // ToUint32Array converts the value to uint32 slice if it's a Uint32Array. |
| 960 | func (v *Value) ToUint32Array() ([]uint32, error) { |
| 961 | if !v.IsUint32Array() { |
| 962 | return nil, errors.New("value is not a Uint32Array") |
| 963 | } |
| 964 | |
| 965 | buffer, byteOffset, byteLength, _ := v.getTypedArrayInfo() |
| 966 | defer buffer.Free() |
| 967 | |
| 968 | totalSize := uint(byteOffset + byteLength) |
| 969 | bytes, err := buffer.ToByteArray(totalSize) |
| 970 | if err != nil { |
| 971 | return nil, err |
| 972 | } |
| 973 | |
| 974 | data := bytes[byteOffset : byteOffset+byteLength] |
| 975 | result := make([]uint32, len(data)/4) |
| 976 | for i := 0; i < len(result); i++ { |
| 977 | result[i] = binary.LittleEndian.Uint32(data[i*4:]) |
| 978 | } |
| 979 | return result, nil |
| 980 | } |
| 981 | |
| 982 | // ToFloat32Array converts the value to float32 slice if it's a Float32Array. |
| 983 | func (v *Value) ToFloat32Array() ([]float32, error) { |