ToInt8Array converts the value to int8 slice if it's an Int8Array.
()
| 851 | |
| 852 | // ToInt8Array converts the value to int8 slice if it's an Int8Array. |
| 853 | func (v *Value) ToInt8Array() ([]int8, error) { |
| 854 | if !v.IsInt8Array() { |
| 855 | return nil, errors.New("value is not an Int8Array") |
| 856 | } |
| 857 | |
| 858 | buffer, byteOffset, byteLength, _ := v.getTypedArrayInfo() |
| 859 | defer buffer.Free() |
| 860 | |
| 861 | totalSize := uint(byteOffset + byteLength) |
| 862 | bytes, err := buffer.ToByteArray(totalSize) |
| 863 | if err != nil { |
| 864 | return nil, err |
| 865 | } |
| 866 | |
| 867 | data := bytes[byteOffset : byteOffset+byteLength] |
| 868 | result := make([]int8, len(data)) |
| 869 | for i, b := range data { |
| 870 | result[i] = int8(b) |
| 871 | } |
| 872 | return result, nil |
| 873 | } |
| 874 | |
| 875 | // ToUint8Array converts the value to uint8 slice if it's a Uint8Array or Uint8ClampedArray. |
| 876 | func (v *Value) ToUint8Array() ([]uint8, error) { |