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

Method ToByteArray

value.go:158–170  ·  view source on GitHub ↗
(size uint)

Source from the content-addressed store, hash-verified

156}
157
158func (v *Value) ToByteArray(size uint) ([]byte, error) {
159 if v.ByteLen() < int64(size) {
160 return nil, errors.New("exceeds the maximum length of the current binary array")
161 }
162 cSize := C.size_t(size)
163 outBuf := C.JS_GetArrayBuffer(v.ctx.ref, &cSize, v.ref)
164
165 if outBuf == nil {
166 return nil, errors.New("failed to get ArrayBuffer data")
167 }
168
169 return C.GoBytes(unsafe.Pointer(outBuf), C.int(size)), nil
170}
171
172// Deprecated: Use ToInt64 instead.
173func (v *Value) Int64() int64 {

Callers 12

ToInt8ArrayMethod · 0.80
ToInt16ArrayMethod · 0.80
ToUint16ArrayMethod · 0.80
ToInt32ArrayMethod · 0.80
ToUint32ArrayMethod · 0.80
ToFloat32ArrayMethod · 0.80
ToFloat64ArrayMethod · 0.80
ToBigInt64ArrayMethod · 0.80
ToBigUint64ArrayMethod · 0.80
unmarshalSliceMethod · 0.80
unmarshalInterfaceMethod · 0.80
TestValueArrayBufferFunction · 0.80

Calls 2

ByteLenMethod · 0.95
NewMethod · 0.80

Tested by 1

TestValueArrayBufferFunction · 0.64