ToUint8Array converts the value to uint8 slice if it's a Uint8Array or Uint8ClampedArray.
()
| 874 | |
| 875 | // ToUint8Array converts the value to uint8 slice if it's a Uint8Array or Uint8ClampedArray. |
| 876 | func (v *Value) ToUint8Array() ([]uint8, error) { |
| 877 | if !v.IsUint8Array() && !v.IsUint8ClampedArray() { |
| 878 | return nil, errors.New("value is not a Uint8Array or Uint8ClampedArray") |
| 879 | } |
| 880 | |
| 881 | var cSize C.size_t |
| 882 | outBuf := C.JS_GetUint8Array(v.ctx.ref, &cSize, v.ref) |
| 883 | if outBuf == nil { |
| 884 | return nil, errors.New("failed to get Uint8Array data") |
| 885 | } |
| 886 | |
| 887 | return C.GoBytes(unsafe.Pointer(outBuf), C.int(cSize)), nil |
| 888 | } |
| 889 | |
| 890 | // ToInt16Array converts the value to int16 slice if it's an Int16Array. |
| 891 | func (v *Value) ToInt16Array() ([]int16, error) { |