@amodx/binary 0.0.12 → 0.0.14
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/Arrays/BitArray.js +2 -2
- package/Struct/Classes/BinraryStructBase.d.ts +4 -3
- package/Struct/Classes/BinraryStructBase.js +5 -6
- package/Struct/Functions/CreateInstance.js +3 -3
- package/Util/BinaryArrays.d.ts +4 -2
- package/Util/BinaryArrays.js +14 -2
- package/Util/ByteEncoder.d.ts +1 -1
- package/package.json +1 -1
package/Arrays/BitArray.js
CHANGED
|
@@ -31,7 +31,7 @@ export class BitArray {
|
|
|
31
31
|
if (index < 0 || index >= this.length) {
|
|
32
32
|
throw new RangeError(`Index ${index} is out of bounds`);
|
|
33
33
|
}
|
|
34
|
-
return BinaryArrays.
|
|
34
|
+
return BinaryArrays.getBitArrayIndexView(this.data, 0, index);
|
|
35
35
|
}
|
|
36
36
|
set(index, value) {
|
|
37
37
|
if (index < 0 || index >= this.length) {
|
|
@@ -40,7 +40,7 @@ export class BitArray {
|
|
|
40
40
|
if (value < 0 || value > 1) {
|
|
41
41
|
throw new RangeError(`Value ${value} is out of bounds for a bit`);
|
|
42
42
|
}
|
|
43
|
-
BinaryArrays.
|
|
43
|
+
BinaryArrays.setBitArrayIndexView(this.data, 0, index, value);
|
|
44
44
|
}
|
|
45
45
|
[Symbol.iterator]() {
|
|
46
46
|
let index = 0;
|
|
@@ -8,11 +8,12 @@ export declare class BinraryStructBase {
|
|
|
8
8
|
structArrayIndexes: number;
|
|
9
9
|
structArrayIndex: number;
|
|
10
10
|
structData: BinaryStructData;
|
|
11
|
-
data: DataView
|
|
11
|
+
data: DataView<ArrayBuffer>;
|
|
12
12
|
indexMap: Record<string, number>;
|
|
13
|
-
index: DataView
|
|
13
|
+
index: DataView<ArrayBuffer>;
|
|
14
14
|
constructor(id: string);
|
|
15
|
-
|
|
15
|
+
setData(data: DataView): void;
|
|
16
|
+
setBuffer(data: BufferTypes): void;
|
|
16
17
|
getBuffer(): ArrayBuffer;
|
|
17
18
|
setStructArrayIndex(index: number): void;
|
|
18
19
|
getProperty(id: string): number;
|
|
@@ -16,11 +16,10 @@ export class BinraryStructBase {
|
|
|
16
16
|
constructor(id) {
|
|
17
17
|
this.id = id;
|
|
18
18
|
}
|
|
19
|
+
setData(data) {
|
|
20
|
+
this.data = data;
|
|
21
|
+
}
|
|
19
22
|
setBuffer(data) {
|
|
20
|
-
if (data instanceof DataView) {
|
|
21
|
-
this.data = data;
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
23
|
this.data = new DataView(data);
|
|
25
24
|
}
|
|
26
25
|
getBuffer() {
|
|
@@ -75,7 +74,7 @@ export class BinraryStructBase {
|
|
|
75
74
|
index * BinaryUtil.getTypedSize(indexData[2]), indexData[2]);
|
|
76
75
|
}
|
|
77
76
|
if (indexData[4] == StructPropertyTypes.BitArray) {
|
|
78
|
-
return BinaryArrays.
|
|
77
|
+
return BinaryArrays.getBitArrayIndexView(this.data, indexData[0] + this.byteOffSet, index);
|
|
79
78
|
}
|
|
80
79
|
throw new Error(`Tag with id: ${id} is not an array.`);
|
|
81
80
|
}
|
|
@@ -110,7 +109,7 @@ export class BinraryStructBase {
|
|
|
110
109
|
index * BinaryUtil.getTypedSize(indexData[2]), indexData[2], value);
|
|
111
110
|
}
|
|
112
111
|
if (indexData[4] == StructPropertyTypes.BitArray) {
|
|
113
|
-
return BinaryArrays.
|
|
112
|
+
return BinaryArrays.setBitArrayIndexView(this.data, indexData[0] + this.byteOffSet, index, value);
|
|
114
113
|
}
|
|
115
114
|
return -Infinity;
|
|
116
115
|
}
|
|
@@ -56,7 +56,7 @@ export function CreateInstance(data) {
|
|
|
56
56
|
const array = new Uint8Array(Math.ceil(length / 8));
|
|
57
57
|
const view = new DataView(array.buffer);
|
|
58
58
|
for (let i = 0; i < length; i++) {
|
|
59
|
-
BinaryArrays.
|
|
59
|
+
BinaryArrays.setBitArrayIndexView(view, 0, i, parent[key][i]);
|
|
60
60
|
}
|
|
61
61
|
object[key] = array;
|
|
62
62
|
}
|
|
@@ -191,10 +191,10 @@ export function CreateInstance(data) {
|
|
|
191
191
|
if (!self._props.has(key)) {
|
|
192
192
|
const proxy = new Proxy(new Array(length), {
|
|
193
193
|
get(target, index) {
|
|
194
|
-
return BinaryArrays.
|
|
194
|
+
return BinaryArrays.getBitArrayIndexView(self.structData, byteIndex + self.structByteOffSet, +index);
|
|
195
195
|
},
|
|
196
196
|
set(target, index, value) {
|
|
197
|
-
BinaryArrays.
|
|
197
|
+
BinaryArrays.setBitArrayIndexView(self.structData, byteIndex + self.structByteOffSet, +index, value);
|
|
198
198
|
return true;
|
|
199
199
|
},
|
|
200
200
|
});
|
package/Util/BinaryArrays.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare class BinaryArrays {
|
|
2
|
-
static
|
|
3
|
-
static
|
|
2
|
+
static getBitArrayIndexView(data: DataView, byteOffset: number, arrayIndex: number): number;
|
|
3
|
+
static setBitArrayIndexView(data: DataView, byteOffset: number, arrayIndex: number, value: number): void;
|
|
4
|
+
static getBitArrayIndex(data: Uint8Array, byteOffset: number, arrayIndex: number): number;
|
|
5
|
+
static setBitArrayIndex(data: Uint8Array, byteOffset: number, arrayIndex: number, value: number): void;
|
|
4
6
|
static getNibbleArrayIndex(data: DataView, byteOffset: number, arrayIndex: number): number;
|
|
5
7
|
static setNibbleArrayIndex(data: DataView, byteOffset: number, arrayIndex: number, value: number): void;
|
|
6
8
|
static getHalfNibbleArrayIndex(data: DataView, byteOffset: number, arrayIndex: number): number;
|
package/Util/BinaryArrays.js
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { BinaryUtil } from "./BinaryUtil";
|
|
2
2
|
export class BinaryArrays {
|
|
3
|
-
static
|
|
3
|
+
static getBitArrayIndexView(data, byteOffset, arrayIndex) {
|
|
4
4
|
const arrayByteIndex = (arrayIndex / 8) >> 0;
|
|
5
5
|
const arrayBitIndex = arrayIndex - arrayByteIndex * 8;
|
|
6
6
|
const arrayByte = data.getUint8(arrayByteIndex + byteOffset);
|
|
7
7
|
return BinaryUtil.getBitValue(arrayByte, arrayBitIndex, 1);
|
|
8
8
|
}
|
|
9
|
-
static
|
|
9
|
+
static setBitArrayIndexView(data, byteOffset, arrayIndex, value) {
|
|
10
10
|
const arrayByteIndex = (arrayIndex / 8) >> 0;
|
|
11
11
|
const arrayBitIndex = arrayIndex - arrayByteIndex * 8;
|
|
12
12
|
const arrayByte = data.getUint8(arrayByteIndex + byteOffset);
|
|
13
13
|
data.setUint8(arrayByteIndex + byteOffset, BinaryUtil.setBitValue(arrayByte, arrayBitIndex, value, 1));
|
|
14
14
|
}
|
|
15
|
+
static getBitArrayIndex(data, byteOffset, arrayIndex) {
|
|
16
|
+
const arrayByteIndex = (arrayIndex / 8) >> 0;
|
|
17
|
+
const arrayBitIndex = arrayIndex - arrayByteIndex * 8;
|
|
18
|
+
const arrayByte = data[arrayByteIndex + byteOffset];
|
|
19
|
+
return BinaryUtil.getBitValue(arrayByte, arrayBitIndex, 1);
|
|
20
|
+
}
|
|
21
|
+
static setBitArrayIndex(data, byteOffset, arrayIndex, value) {
|
|
22
|
+
const arrayByteIndex = (arrayIndex / 8) >> 0;
|
|
23
|
+
const arrayBitIndex = arrayIndex - arrayByteIndex * 8;
|
|
24
|
+
const arrayByte = data[arrayByteIndex + byteOffset];
|
|
25
|
+
data[arrayByteIndex + byteOffset] = BinaryUtil.setBitValue(arrayByte, arrayBitIndex, value, 1);
|
|
26
|
+
}
|
|
15
27
|
static getNibbleArrayIndex(data, byteOffset, arrayIndex) {
|
|
16
28
|
const arrayByteIndex = (arrayIndex / 2) >> 0;
|
|
17
29
|
const isHighNibble = arrayIndex % 2 === 0;
|
package/Util/ByteEncoder.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BinaryNumberTypes } from "../Constants/BinaryTypes";
|
|
2
2
|
export declare class ByteEncoder {
|
|
3
|
-
static view: DataView
|
|
3
|
+
static view: DataView<ArrayBuffer>;
|
|
4
4
|
static count: number;
|
|
5
5
|
static value: number;
|
|
6
6
|
static setValue(type: BinaryNumberTypes, value: number): typeof ByteEncoder;
|