MCPcopy Create free account
hub / github.com/buke/quickjs-go / ToUint8Array

Method ToUint8Array

value.go:876–888  ·  view source on GitHub ↗

ToUint8Array converts the value to uint8 slice if it's a Uint8Array or Uint8ClampedArray.

()

Source from the content-addressed store, hash-verified

874
875// ToUint8Array converts the value to uint8 slice if it's a Uint8Array or Uint8ClampedArray.
876func (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.
891func (v *Value) ToInt16Array() ([]int16, error) {

Callers 3

TestContextTypedArraysFunction · 0.80
unmarshalSliceMethod · 0.80
TestValueTypedArraysFunction · 0.80

Calls 3

IsUint8ArrayMethod · 0.95
IsUint8ClampedArrayMethod · 0.95
NewMethod · 0.80

Tested by 2

TestContextTypedArraysFunction · 0.64
TestValueTypedArraysFunction · 0.64