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

Method ToBigInt64Array

value.go:1031–1051  ·  view source on GitHub ↗

ToBigInt64Array converts the value to int64 slice if it's a BigInt64Array.

()

Source from the content-addressed store, hash-verified

1029
1030// ToBigInt64Array converts the value to int64 slice if it's a BigInt64Array.
1031func (v *Value) ToBigInt64Array() ([]int64, error) {
1032 if !v.IsBigInt64Array() {
1033 return nil, errors.New("value is not a BigInt64Array")
1034 }
1035
1036 buffer, byteOffset, byteLength, _ := v.getTypedArrayInfo()
1037 defer buffer.Free()
1038
1039 totalSize := uint(byteOffset + byteLength)
1040 bytes, err := buffer.ToByteArray(totalSize)
1041 if err != nil {
1042 return nil, err
1043 }
1044
1045 data := bytes[byteOffset : byteOffset+byteLength]
1046 result := make([]int64, len(data)/8)
1047 for i := 0; i < len(result); i++ {
1048 result[i] = int64(binary.LittleEndian.Uint64(data[i*8:]))
1049 }
1050 return result, nil
1051}
1052
1053// ToBigUint64Array converts the value to uint64 slice if it's a BigUint64Array.
1054func (v *Value) ToBigUint64Array() ([]uint64, error) {

Callers 3

TestContextTypedArraysFunction · 0.80
unmarshalSliceMethod · 0.80
TestValueTypedArraysFunction · 0.80

Calls 6

IsBigInt64ArrayMethod · 0.95
getTypedArrayInfoMethod · 0.95
NewMethod · 0.80
ToByteArrayMethod · 0.80
Uint64Method · 0.80
FreeMethod · 0.45

Tested by 2

TestContextTypedArraysFunction · 0.64
TestValueTypedArraysFunction · 0.64