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

Method ToBigUint64Array

value.go:1054–1074  ·  view source on GitHub ↗

ToBigUint64Array converts the value to uint64 slice if it's a BigUint64Array.

()

Source from the content-addressed store, hash-verified

1052
1053// ToBigUint64Array converts the value to uint64 slice if it's a BigUint64Array.
1054func (v *Value) ToBigUint64Array() ([]uint64, error) {
1055 if !v.IsBigUint64Array() {
1056 return nil, errors.New("value is not a BigUint64Array")
1057 }
1058
1059 buffer, byteOffset, byteLength, _ := v.getTypedArrayInfo()
1060 defer buffer.Free()
1061
1062 totalSize := uint(byteOffset + byteLength)
1063 bytes, err := buffer.ToByteArray(totalSize)
1064 if err != nil {
1065 return nil, err
1066 }
1067
1068 data := bytes[byteOffset : byteOffset+byteLength]
1069 result := make([]uint64, len(data)/8)
1070 for i := 0; i < len(result); i++ {
1071 result[i] = binary.LittleEndian.Uint64(data[i*8:])
1072 }
1073 return result, nil
1074}
1075
1076// =============================================================================
1077// BASIC TYPE CHECKING METHODS

Callers 3

TestContextTypedArraysFunction · 0.80
unmarshalSliceMethod · 0.80
TestValueTypedArraysFunction · 0.80

Calls 6

IsBigUint64ArrayMethod · 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