ripple-binary-codec 2.0.0-beta.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/binary.d.ts +12 -13
- package/dist/binary.js +6 -5
- package/dist/binary.js.map +1 -1
- package/dist/enums/bytes.d.ts +1 -2
- package/dist/enums/bytes.js +1 -2
- package/dist/enums/bytes.js.map +1 -1
- package/dist/enums/definitions.json +36 -11
- package/dist/enums/field.d.ts +1 -2
- package/dist/enums/field.js +1 -2
- package/dist/enums/field.js.map +1 -1
- package/dist/enums/index.js +4 -24
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/src/enums/definitions.json +36 -11
- package/dist/hash-prefixes.d.ts +1 -2
- package/dist/hash-prefixes.js +6 -6
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.d.ts +5 -6
- package/dist/hashes.js +1 -2
- package/dist/hashes.js.map +1 -1
- package/dist/index.js +7 -14
- package/dist/index.js.map +1 -1
- package/dist/quality.d.ts +1 -2
- package/dist/quality.js +3 -3
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +2 -3
- package/dist/serdes/binary-parser.js +2 -2
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.d.ts +6 -7
- package/dist/serdes/binary-serializer.js +9 -9
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +4 -5
- package/dist/shamap.js +2 -3
- package/dist/shamap.js.map +1 -1
- package/dist/src/binary.d.ts +90 -0
- package/dist/src/binary.js +128 -0
- package/dist/src/binary.js.map +1 -0
- package/dist/src/coretypes.d.ts +9 -0
- package/dist/src/coretypes.js +48 -0
- package/dist/src/coretypes.js.map +1 -0
- package/dist/src/enums/bytes.d.ts +25 -0
- package/dist/src/enums/bytes.js +63 -0
- package/dist/src/enums/bytes.js.map +1 -0
- package/dist/src/enums/constants.d.ts +4 -0
- package/dist/src/enums/constants.js +8 -0
- package/dist/src/enums/constants.js.map +1 -0
- package/dist/src/enums/definitions.json +2866 -0
- package/dist/src/enums/field.d.ts +28 -0
- package/dist/src/enums/field.js +58 -0
- package/dist/src/enums/field.js.map +1 -0
- package/dist/src/enums/index.d.ts +12 -0
- package/dist/src/enums/index.js +31 -0
- package/dist/src/enums/index.js.map +1 -0
- package/dist/src/enums/utils-renumber.d.ts +101 -0
- package/dist/src/enums/utils-renumber.js +127 -0
- package/dist/src/enums/utils-renumber.js.map +1 -0
- package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
- package/dist/src/enums/xrpl-definitions-base.js +59 -0
- package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/src/enums/xrpl-definitions.d.ts +21 -0
- package/dist/src/enums/xrpl-definitions.js +29 -0
- package/dist/src/enums/xrpl-definitions.js.map +1 -0
- package/dist/src/hash-prefixes.d.ts +5 -0
- package/dist/src/hash-prefixes.js +41 -0
- package/dist/src/hash-prefixes.js.map +1 -0
- package/dist/src/hashes.d.ts +50 -0
- package/dist/src/hashes.js +76 -0
- package/dist/src/hashes.js.map +1 -0
- package/dist/src/index.d.ts +64 -0
- package/dist/src/index.js +123 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ledger-hashes.d.ts +48 -0
- package/dist/src/ledger-hashes.js +141 -0
- package/dist/src/ledger-hashes.js.map +1 -0
- package/dist/src/quality.d.ts +21 -0
- package/dist/src/quality.js +42 -0
- package/dist/src/quality.js.map +1 -0
- package/dist/src/serdes/binary-parser.d.ts +100 -0
- package/dist/src/serdes/binary-parser.js +194 -0
- package/dist/src/serdes/binary-parser.js.map +1 -0
- package/dist/src/serdes/binary-serializer.d.ts +81 -0
- package/dist/src/serdes/binary-serializer.js +149 -0
- package/dist/src/serdes/binary-serializer.js.map +1 -0
- package/dist/src/shamap.d.ts +102 -0
- package/dist/src/shamap.js +172 -0
- package/dist/src/shamap.js.map +1 -0
- package/dist/src/types/account-id.d.ts +35 -0
- package/dist/src/types/account-id.js +69 -0
- package/dist/src/types/account-id.js.map +1 -0
- package/dist/src/types/amount.d.ts +67 -0
- package/dist/src/types/amount.js +212 -0
- package/dist/src/types/amount.js.map +1 -0
- package/dist/src/types/blob.d.ts +24 -0
- package/dist/src/types/blob.js +40 -0
- package/dist/src/types/blob.js.map +1 -0
- package/dist/src/types/currency.d.ts +28 -0
- package/dist/src/types/currency.js +127 -0
- package/dist/src/types/currency.js.map +1 -0
- package/dist/src/types/hash-128.d.ts +16 -0
- package/dist/src/types/hash-128.js +32 -0
- package/dist/src/types/hash-128.js.map +1 -0
- package/dist/src/types/hash-160.d.ts +10 -0
- package/dist/src/types/hash-160.js +19 -0
- package/dist/src/types/hash-160.js.map +1 -0
- package/dist/src/types/hash-256.d.ts +10 -0
- package/dist/src/types/hash-256.js +16 -0
- package/dist/src/types/hash-256.js.map +1 -0
- package/dist/src/types/hash.d.ts +40 -0
- package/dist/src/types/hash.js +73 -0
- package/dist/src/types/hash.js.map +1 -0
- package/dist/src/types/index.d.ts +18 -0
- package/dist/src/types/index.js +61 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/issue.d.ts +38 -0
- package/dist/src/types/issue.js +81 -0
- package/dist/src/types/issue.js.map +1 -0
- package/dist/src/types/path-set.d.ts +36 -0
- package/dist/src/types/path-set.js +233 -0
- package/dist/src/types/path-set.js.map +1 -0
- package/dist/src/types/serialized-type.d.ts +70 -0
- package/dist/src/types/serialized-type.js +105 -0
- package/dist/src/types/serialized-type.js.map +1 -0
- package/dist/src/types/st-array.d.ts +31 -0
- package/dist/src/types/st-array.js +83 -0
- package/dist/src/types/st-array.js.map +1 -0
- package/dist/src/types/st-object.d.ts +32 -0
- package/dist/src/types/st-object.js +155 -0
- package/dist/src/types/st-object.js.map +1 -0
- package/dist/src/types/uint-16.d.ts +24 -0
- package/dist/src/types/uint-16.js +45 -0
- package/dist/src/types/uint-16.js.map +1 -0
- package/dist/src/types/uint-32.d.ts +24 -0
- package/dist/src/types/uint-32.js +50 -0
- package/dist/src/types/uint-32.js.map +1 -0
- package/dist/src/types/uint-64.d.ts +37 -0
- package/dist/src/types/uint-64.js +86 -0
- package/dist/src/types/uint-64.js.map +1 -0
- package/dist/src/types/uint-8.d.ts +24 -0
- package/dist/src/types/uint-8.js +46 -0
- package/dist/src/types/uint-8.js.map +1 -0
- package/dist/src/types/uint.d.ts +29 -0
- package/dist/src/types/uint.js +47 -0
- package/dist/src/types/uint.js.map +1 -0
- package/dist/src/types/vector-256.d.ts +30 -0
- package/dist/src/types/vector-256.js +73 -0
- package/dist/src/types/vector-256.js.map +1 -0
- package/dist/src/types/xchain-bridge.d.ts +44 -0
- package/dist/src/types/xchain-bridge.js +102 -0
- package/dist/src/types/xchain-bridge.js.map +1 -0
- package/dist/src/utils.d.ts +47 -0
- package/dist/src/utils.js +137 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/account-id.d.ts +1 -2
- package/dist/types/account-id.js +4 -6
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +1 -2
- package/dist/types/amount.js +16 -15
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +1 -2
- package/dist/types/blob.js +2 -2
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +1 -2
- package/dist/types/currency.js +10 -10
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-128.d.ts +1 -2
- package/dist/types/hash-128.js +3 -3
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.d.ts +1 -2
- package/dist/types/hash-160.js +1 -2
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-256.d.ts +1 -2
- package/dist/types/hash-256.js +1 -2
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +2 -3
- package/dist/types/hash.js +5 -4
- package/dist/types/hash.js.map +1 -1
- package/dist/types/issue.d.ts +1 -2
- package/dist/types/issue.js +4 -4
- package/dist/types/issue.js.map +1 -1
- package/dist/types/path-set.js +12 -12
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +17 -13
- package/dist/types/serialized-type.js +11 -6
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.js +5 -5
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-object.js +1 -2
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.d.ts +1 -2
- package/dist/types/uint-16.js +6 -5
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.d.ts +1 -2
- package/dist/types/uint-32.js +7 -6
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +2 -3
- package/dist/types/uint-64.js +16 -15
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.d.ts +1 -2
- package/dist/types/uint-8.js +7 -5
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +4 -4
- package/dist/types/uint.js +5 -0
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.d.ts +1 -2
- package/dist/types/vector-256.js +2 -4
- package/dist/types/vector-256.js.map +1 -1
- package/dist/types/xchain-bridge.d.ts +1 -2
- package/dist/types/xchain-bridge.js +20 -20
- package/dist/types/xchain-bridge.js.map +1 -1
- package/dist/utils.d.ts +47 -0
- package/dist/utils.js +137 -0
- package/dist/utils.js.map +1 -0
- package/package.json +8 -11
- package/src/README.md +3 -1
- package/src/binary.ts +21 -14
- package/src/enums/bytes.ts +2 -3
- package/src/enums/definitions.json +36 -11
- package/src/enums/field.ts +3 -4
- package/src/enums/index.ts +1 -1
- package/src/hash-prefixes.ts +8 -8
- package/src/hashes.ts +6 -7
- package/src/index.ts +12 -15
- package/src/quality.ts +4 -4
- package/src/serdes/binary-parser.ts +5 -5
- package/src/serdes/binary-serializer.ts +14 -14
- package/src/shamap.ts +5 -6
- package/src/types/account-id.ts +8 -8
- package/src/types/amount.ts +17 -18
- package/src/types/blob.ts +3 -3
- package/src/types/currency.ts +16 -16
- package/src/types/hash-128.ts +4 -4
- package/src/types/hash-160.ts +2 -3
- package/src/types/hash-256.ts +2 -3
- package/src/types/hash.ts +8 -6
- package/src/types/issue.ts +5 -5
- package/src/types/path-set.ts +16 -16
- package/src/types/serialized-type.ts +20 -15
- package/src/types/st-array.ts +7 -7
- package/src/types/st-object.ts +2 -2
- package/src/types/uint-16.ts +10 -6
- package/src/types/uint-32.ts +10 -7
- package/src/types/uint-64.ts +20 -17
- package/src/types/uint-8.ts +9 -6
- package/src/types/uint.ts +11 -4
- package/src/types/vector-256.ts +3 -8
- package/src/types/xchain-bridge.ts +22 -22
- package/src/utils.ts +152 -0
|
@@ -2,8 +2,8 @@ import { BinaryParser } from '../serdes/binary-parser'
|
|
|
2
2
|
|
|
3
3
|
import { AccountID } from './account-id'
|
|
4
4
|
import { JsonObject, SerializedType } from './serialized-type'
|
|
5
|
-
import { Buffer } from 'buffer/'
|
|
6
5
|
import { Issue, IssueObject } from './issue'
|
|
6
|
+
import { concat } from '@xrplf/isomorphic/utils'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Interface for JSON objects that represent cross-chain bridges
|
|
@@ -34,11 +34,11 @@ function isXChainBridgeObject(arg): arg is XChainBridgeObject {
|
|
|
34
34
|
*/
|
|
35
35
|
class XChainBridge extends SerializedType {
|
|
36
36
|
static readonly ZERO_XCHAIN_BRIDGE: XChainBridge = new XChainBridge(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
concat([
|
|
38
|
+
Uint8Array.from([0x14]),
|
|
39
|
+
new Uint8Array(40),
|
|
40
|
+
Uint8Array.from([0x14]),
|
|
41
|
+
new Uint8Array(40),
|
|
42
42
|
]),
|
|
43
43
|
)
|
|
44
44
|
|
|
@@ -50,7 +50,7 @@ class XChainBridge extends SerializedType {
|
|
|
50
50
|
{ name: 'IssuingChainIssue', type: Issue },
|
|
51
51
|
]
|
|
52
52
|
|
|
53
|
-
constructor(bytes:
|
|
53
|
+
constructor(bytes: Uint8Array) {
|
|
54
54
|
super(bytes ?? XChainBridge.ZERO_XCHAIN_BRIDGE.bytes)
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -67,20 +67,20 @@ class XChainBridge extends SerializedType {
|
|
|
67
67
|
return value
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
if (isXChainBridgeObject(value)) {
|
|
71
|
-
|
|
72
|
-
this.TYPE_ORDER.forEach((item) => {
|
|
73
|
-
const { name, type } = item
|
|
74
|
-
if (type === AccountID) {
|
|
75
|
-
bytes.push(Buffer.from([0x14]))
|
|
76
|
-
}
|
|
77
|
-
const object = type.from(value[name])
|
|
78
|
-
bytes.push(object.toBytes())
|
|
79
|
-
})
|
|
80
|
-
return new XChainBridge(Buffer.concat(bytes))
|
|
70
|
+
if (!isXChainBridgeObject(value)) {
|
|
71
|
+
throw new Error('Invalid type to construct an XChainBridge')
|
|
81
72
|
}
|
|
82
73
|
|
|
83
|
-
|
|
74
|
+
const bytes: Array<Uint8Array> = []
|
|
75
|
+
this.TYPE_ORDER.forEach((item) => {
|
|
76
|
+
const { name, type } = item
|
|
77
|
+
if (type === AccountID) {
|
|
78
|
+
bytes.push(Uint8Array.from([0x14]))
|
|
79
|
+
}
|
|
80
|
+
const object = type.from(value[name])
|
|
81
|
+
bytes.push(object.toBytes())
|
|
82
|
+
})
|
|
83
|
+
return new XChainBridge(concat(bytes))
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
@@ -90,19 +90,19 @@ class XChainBridge extends SerializedType {
|
|
|
90
90
|
* @returns An XChainBridge object
|
|
91
91
|
*/
|
|
92
92
|
static fromParser(parser: BinaryParser): XChainBridge {
|
|
93
|
-
const bytes: Array<
|
|
93
|
+
const bytes: Array<Uint8Array> = []
|
|
94
94
|
|
|
95
95
|
this.TYPE_ORDER.forEach((item) => {
|
|
96
96
|
const { type } = item
|
|
97
97
|
if (type === AccountID) {
|
|
98
98
|
parser.skip(1)
|
|
99
|
-
bytes.push(
|
|
99
|
+
bytes.push(Uint8Array.from([0x14]))
|
|
100
100
|
}
|
|
101
101
|
const object = type.fromParser(parser)
|
|
102
102
|
bytes.push(object.toBytes())
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
-
return new XChainBridge(
|
|
105
|
+
return new XChainBridge(concat(bytes))
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Even though this comes from NodeJS it is valid in the browser
|
|
2
|
+
import TypedArray = NodeJS.TypedArray
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Writes value to array at the specified offset. The value must be a valid unsigned 8-bit integer.
|
|
6
|
+
* @param array Uint8Array to be written to
|
|
7
|
+
* @param value Number to be written to array.
|
|
8
|
+
* @param offset plus the number of bytes written.
|
|
9
|
+
*/
|
|
10
|
+
export function writeUInt8(
|
|
11
|
+
array: Uint8Array,
|
|
12
|
+
value: number,
|
|
13
|
+
offset: number,
|
|
14
|
+
): void {
|
|
15
|
+
value = Number(value)
|
|
16
|
+
array[offset] = value
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Writes value to array at the specified offset as big-endian. The value must be a valid unsigned 16-bit integer.
|
|
21
|
+
* @param array Uint8Array to be written to
|
|
22
|
+
* @param value Number to be written to array.
|
|
23
|
+
* @param offset plus the number of bytes written.
|
|
24
|
+
*/
|
|
25
|
+
export function writeUInt16BE(
|
|
26
|
+
array: Uint8Array,
|
|
27
|
+
value: number,
|
|
28
|
+
offset: number,
|
|
29
|
+
): void {
|
|
30
|
+
value = Number(value)
|
|
31
|
+
|
|
32
|
+
array[offset] = value >>> 8
|
|
33
|
+
array[offset + 1] = value
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Writes value to array at the specified offset as big-endian. The value must be a valid unsigned 32-bit integer.
|
|
38
|
+
* @param array Uint8Array to be written to
|
|
39
|
+
* @param value Number to be written to array.
|
|
40
|
+
* @param offset plus the number of bytes written.
|
|
41
|
+
*/
|
|
42
|
+
export function writeUInt32BE(
|
|
43
|
+
array: Uint8Array,
|
|
44
|
+
value: number,
|
|
45
|
+
offset: number,
|
|
46
|
+
): void {
|
|
47
|
+
array[offset] = (value >>> 24) & 0xff
|
|
48
|
+
array[offset + 1] = (value >>> 16) & 0xff
|
|
49
|
+
array[offset + 2] = (value >>> 8) & 0xff
|
|
50
|
+
array[offset + 3] = value & 0xff
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
|
|
55
|
+
* @param array Uint8Array to read
|
|
56
|
+
* @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2
|
|
57
|
+
*/
|
|
58
|
+
export function readUInt16BE(array: Uint8Array, offset: number): string {
|
|
59
|
+
return new DataView(array.buffer).getUint16(offset, false).toString(10)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
|
|
64
|
+
* @param array Uint8Array to read
|
|
65
|
+
* @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
|
|
66
|
+
*/
|
|
67
|
+
export function readUInt32BE(array: Uint8Array, offset: number): string {
|
|
68
|
+
return new DataView(array.buffer).getUint32(offset, false).toString(10)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Compares two Uint8Array or ArrayBuffers
|
|
73
|
+
* @param a first array to compare
|
|
74
|
+
* @param b second array to compare
|
|
75
|
+
*/
|
|
76
|
+
export function equal(
|
|
77
|
+
a: Uint8Array | ArrayBuffer,
|
|
78
|
+
b: Uint8Array | ArrayBuffer,
|
|
79
|
+
): boolean {
|
|
80
|
+
const aUInt = a instanceof ArrayBuffer ? new Uint8Array(a, 0) : a
|
|
81
|
+
const bUInt = b instanceof ArrayBuffer ? new Uint8Array(b, 0) : b
|
|
82
|
+
if (aUInt.byteLength != bUInt.byteLength) return false
|
|
83
|
+
if (aligned32(aUInt) && aligned32(bUInt)) return compare32(aUInt, bUInt) === 0
|
|
84
|
+
if (aligned16(aUInt) && aligned16(bUInt)) return compare16(aUInt, bUInt) === 0
|
|
85
|
+
return compare8(aUInt, bUInt) === 0
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Compares two 8 bit aligned arrays
|
|
90
|
+
* @param a first array to compare
|
|
91
|
+
* @param b second array to compare
|
|
92
|
+
*/
|
|
93
|
+
function compare8(a, b) {
|
|
94
|
+
const ua = new Uint8Array(a.buffer, a.byteOffset, a.byteLength)
|
|
95
|
+
const ub = new Uint8Array(b.buffer, b.byteOffset, b.byteLength)
|
|
96
|
+
return compare(ua, ub)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Compares two 16 bit aligned arrays
|
|
101
|
+
* @param a first array to compare
|
|
102
|
+
* @param b second array to compare
|
|
103
|
+
*/
|
|
104
|
+
function compare16(a: Uint8Array, b: Uint8Array) {
|
|
105
|
+
const ua = new Uint16Array(a.buffer, a.byteOffset, a.byteLength / 2)
|
|
106
|
+
const ub = new Uint16Array(b.buffer, b.byteOffset, b.byteLength / 2)
|
|
107
|
+
return compare(ua, ub)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Compares two 32 bit aligned arrays
|
|
112
|
+
* @param a first array to compare
|
|
113
|
+
* @param b second array to compare
|
|
114
|
+
*/
|
|
115
|
+
function compare32(a: Uint8Array, b: Uint8Array) {
|
|
116
|
+
const ua = new Uint32Array(a.buffer, a.byteOffset, a.byteLength / 4)
|
|
117
|
+
const ub = new Uint32Array(b.buffer, b.byteOffset, b.byteLength / 4)
|
|
118
|
+
return compare(ua, ub)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Compare two TypedArrays
|
|
123
|
+
* @param a first array to compare
|
|
124
|
+
* @param b second array to compare
|
|
125
|
+
*/
|
|
126
|
+
export function compare(a: TypedArray, b: TypedArray): 1 | -1 | 0 {
|
|
127
|
+
if (a.byteLength !== b.byteLength) {
|
|
128
|
+
throw new Error('Cannot compare arrays of different length')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (let i = 0; i < a.length - 1; i += 1) {
|
|
132
|
+
if (a[i] > b[i]) return 1
|
|
133
|
+
if (a[i] < b[i]) return -1
|
|
134
|
+
}
|
|
135
|
+
return 0
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Determine if TypedArray is 16 bit aligned
|
|
140
|
+
* @param array The array to check
|
|
141
|
+
*/
|
|
142
|
+
function aligned16(array: TypedArray) {
|
|
143
|
+
return array.byteOffset % 2 === 0 && array.byteLength % 2 === 0
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Determine if TypedArray is 32 bit aligned
|
|
148
|
+
* @param array The array to check
|
|
149
|
+
*/
|
|
150
|
+
function aligned32(array: TypedArray) {
|
|
151
|
+
return array.byteOffset % 4 === 0 && array.byteLength % 4 === 0
|
|
152
|
+
}
|