@flighthq/buffer 0.5.1-next.3308.79ae053 → 0.5.1-next.4304.322dc96
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/README.md +2 -2
- package/dist/byteReader.d.ts +9 -2
- package/dist/byteReader.d.ts.map +1 -1
- package/dist/byteReader.js +33 -18
- package/dist/byteReader.js.map +1 -1
- package/dist/contract.d.ts +2 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +3 -1
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/byteReader.test.ts +73 -56
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/buffer`. The `@fligh
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/buffer@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/buffer@0.5.1-next.4304.322dc96](https://github.com/flighthq/flight/tree/322dc963fc5a404a31bc0cc612e906de504ea024/packages/buffer)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/322dc963fc5a404a31bc0cc612e906de504ea024/LICENSE.md)
|
package/dist/byteReader.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { NonEntityCreateResult } from '@flighthq/entity/contract';
|
|
2
|
+
/**
|
|
3
|
+
* A forward-only little/big-endian cursor over a byte view (TS `ByteReader`), shared by the
|
|
4
|
+
* binary format parsers.
|
|
5
|
+
*/
|
|
6
|
+
export interface ByteReader {
|
|
7
|
+
view: Readonly<Uint8Array>;
|
|
8
|
+
offset: number;
|
|
9
|
+
}
|
|
3
10
|
export declare function createByteReader(bytes: Readonly<Uint8Array>, offset?: number): NonEntityCreateResult<ByteReader, 'descriptor'>;
|
|
4
11
|
export declare function hasByteReaderBytes(reader: Readonly<ByteReader>, count: number): boolean;
|
|
5
12
|
export declare function readByteReaderU16(reader: ByteReader): number;
|
package/dist/byteReader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"byteReader.d.ts","sourceRoot":"","sources":["../src/byteReader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"byteReader.d.ts","sourceRoot":"","sources":["../src/byteReader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,EAC3B,MAAM,CAAC,EAAE,MAAM,GACd,qBAAqB,CAAC,UAAU,EAAE,YAAY,CAAC,CAEjD;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAK5D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAM5D;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAMrE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAK5D;AAYD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CASrE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAO5D;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAI3D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAEtE"}
|
package/dist/byteReader.js
CHANGED
|
@@ -1,46 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Generated from crates/flight-buffer/src/byte_reader.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
export function createByteReader(bytes, offset) {
|
|
4
|
+
return { view: bytes, offset: offset ?? 0 };
|
|
3
5
|
}
|
|
4
6
|
export function hasByteReaderBytes(reader, count) {
|
|
5
|
-
return
|
|
7
|
+
return reader.offset <= reader.view.length && count <= reader.view.length - reader.offset;
|
|
6
8
|
}
|
|
7
9
|
export function readByteReaderU16(reader) {
|
|
8
|
-
const
|
|
10
|
+
const offset = reader.offset;
|
|
11
|
+
const value = (reader.view[offset] & 0xffff) | ((reader.view[offset + 1] & 0xffff) << 8);
|
|
9
12
|
reader.offset += 2;
|
|
10
13
|
return value;
|
|
11
14
|
}
|
|
12
15
|
export function readByteReaderU24(reader) {
|
|
13
|
-
const view = reader.view;
|
|
14
16
|
const offset = reader.offset;
|
|
15
|
-
const value = view
|
|
17
|
+
const value = (reader.view[offset] >>> 0) | ((reader.view[offset + 1] >>> 0) << 8) | ((reader.view[offset + 2] >>> 0) << 16);
|
|
16
18
|
reader.offset += 3;
|
|
17
|
-
return value;
|
|
19
|
+
return value >>> 0;
|
|
18
20
|
}
|
|
19
21
|
export function readByteReaderU24BigEndian(reader) {
|
|
20
|
-
const view = reader.view;
|
|
21
22
|
const offset = reader.offset;
|
|
22
|
-
const value = (view
|
|
23
|
+
const value = ((reader.view[offset] >>> 0) << 16) | ((reader.view[offset + 1] >>> 0) << 8) | (reader.view[offset + 2] >>> 0);
|
|
23
24
|
reader.offset += 3;
|
|
24
|
-
return value;
|
|
25
|
+
return value >>> 0;
|
|
25
26
|
}
|
|
26
27
|
export function readByteReaderU32(reader) {
|
|
27
|
-
const
|
|
28
|
+
const offset = reader.offset;
|
|
29
|
+
const value = readByteReaderU32At(reader.view, offset);
|
|
28
30
|
reader.offset += 4;
|
|
29
|
-
return value;
|
|
31
|
+
return value >>> 0;
|
|
32
|
+
}
|
|
33
|
+
function readByteReaderU32At(view, offset) {
|
|
34
|
+
return (((view[offset] >>> 0) |
|
|
35
|
+
((view[offset + 1] >>> 0) << 8) |
|
|
36
|
+
((view[offset + 2] >>> 0) << 16) |
|
|
37
|
+
((view[offset + 3] >>> 0) << 24)) >>>
|
|
38
|
+
0);
|
|
30
39
|
}
|
|
31
40
|
export function readByteReaderU32BigEndian(reader) {
|
|
32
|
-
const
|
|
41
|
+
const offset = reader.offset;
|
|
42
|
+
const value = ((reader.view[offset] >>> 0) << 24) |
|
|
43
|
+
((reader.view[offset + 1] >>> 0) << 16) |
|
|
44
|
+
((reader.view[offset + 2] >>> 0) << 8) |
|
|
45
|
+
(reader.view[offset + 3] >>> 0);
|
|
33
46
|
reader.offset += 4;
|
|
34
|
-
return value;
|
|
47
|
+
return value >>> 0;
|
|
35
48
|
}
|
|
36
49
|
export function readByteReaderU64(reader) {
|
|
37
|
-
const
|
|
38
|
-
const
|
|
50
|
+
const offset = reader.offset;
|
|
51
|
+
const low = readByteReaderU32At(reader.view, offset);
|
|
52
|
+
const high = readByteReaderU32At(reader.view, offset + 4);
|
|
53
|
+
const value = high * 0x1_0000_0000 + low;
|
|
39
54
|
reader.offset += 8;
|
|
40
|
-
return
|
|
55
|
+
return value;
|
|
41
56
|
}
|
|
42
57
|
export function readByteReaderU8(reader) {
|
|
43
|
-
const value = reader.view
|
|
58
|
+
const value = reader.view[reader.offset];
|
|
44
59
|
reader.offset += 1;
|
|
45
60
|
return value;
|
|
46
61
|
}
|
package/dist/byteReader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"byteReader.js","sourceRoot":"","sources":["../src/byteReader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"byteReader.js","sourceRoot":"","sources":["../src/byteReader.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,mEAAmE;AAanE,MAAM,UAAU,gBAAgB,CAC9B,KAA2B,EAC3B,MAAe;IAEf,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAA4B,EAAE,KAAa;IAC5E,OAAO,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AAC5F,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAkB;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACzF,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;IACnB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAkB;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,KAAK,GACT,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,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,CAAC,MAAkB,EAAE,KAAa;IAC9D,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC;AACzB,CAAC"}
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { createByteReader, hasByteReaderBytes, readByteReaderU16, readByteReaderU24, readByteReaderU24BigEndian, readByteReaderU32, readByteReaderU32BigEndian, readByteReaderU64, readByteReaderU8, skipByteReader, } from './byteReader.ts';
|
|
2
|
+
export type { ByteReader } from './byteReader.ts';
|
|
2
3
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated from crates/flight-buffer/src/lib.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
export { createByteReader, hasByteReaderBytes, readByteReaderU16, readByteReaderU24, readByteReaderU24BigEndian, readByteReaderU32, readByteReaderU32BigEndian, readByteReaderU64, readByteReaderU8, skipByteReader, } from "./byteReader.js";
|
|
2
4
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,mEAAmE;AAEnE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,iBAAiB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { createByteReader, hasByteReaderBytes, readByteReaderU16, readByteReaderU24, readByteReaderU24BigEndian, readByteReaderU32, readByteReaderU32BigEndian, readByteReaderU64, readByteReaderU8, skipByteReader, } from './contract.ts';
|
|
2
|
+
export type { ByteReader } from './contract.ts';
|
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated from crates/flight-buffer/src/lib.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
export { createByteReader, hasByteReaderBytes, readByteReaderU16, readByteReaderU24, readByteReaderU24BigEndian, readByteReaderU32, readByteReaderU32BigEndian, readByteReaderU64, readByteReaderU8, skipByteReader, } from "./contract.js";
|
|
2
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,mEAAmE;AAEnE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/buffer",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.4304.322dc96",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,13 +32,15 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc -b",
|
|
34
34
|
"clean": "tsc -b --clean",
|
|
35
|
+
"generate": "tsx ../../scripts/generate-rust-package.ts --crate flight-buffer --package buffer",
|
|
36
|
+
"generate:check": "tsx ../../scripts/generate-rust-package.ts --crate flight-buffer --package buffer --check",
|
|
35
37
|
"test": "vitest run --config vitest.config.ts",
|
|
36
38
|
"test:watch": "vitest --watch --config vitest.config.ts",
|
|
37
39
|
"prepack": "npm run clean && npm run clean:dist && npm run build",
|
|
38
40
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"@flighthq/
|
|
43
|
+
"@flighthq/entity": "0.5.1-next.4304.322dc96"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"typescript": "^5.3.0"
|
package/src/byteReader.test.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Generated from crates/flight-buffer/tests/byte_reader_test.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
|
|
1
6
|
import {
|
|
2
7
|
createByteReader,
|
|
3
8
|
hasByteReaderBytes,
|
|
@@ -9,109 +14,121 @@ import {
|
|
|
9
14
|
readByteReaderU64,
|
|
10
15
|
readByteReaderU8,
|
|
11
16
|
skipByteReader,
|
|
12
|
-
} from './
|
|
17
|
+
} from './contract.ts';
|
|
13
18
|
|
|
14
19
|
describe('createByteReader', () => {
|
|
15
20
|
it('starts at the given offset', () => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
expect(
|
|
21
|
+
const bytes: Uint8Array = new Uint8Array([1, 2, 3, 4]);
|
|
22
|
+
let reader = createByteReader(bytes, 2);
|
|
23
|
+
expect(reader.offset).toEqual(2);
|
|
24
|
+
expect(readByteReaderU8(reader)).toEqual(3);
|
|
19
25
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
expect(readByteReaderU16(reader)).toBe(1);
|
|
26
|
+
it('views a subslice at its own start', () => {
|
|
27
|
+
const backing: Uint8Array = new Uint8Array([9, 9, 0x01, 0x00]);
|
|
28
|
+
let reader = createByteReader(backing.slice(2), undefined);
|
|
29
|
+
expect(readByteReaderU16(reader)).toEqual(1);
|
|
25
30
|
});
|
|
26
31
|
});
|
|
27
32
|
|
|
28
33
|
describe('hasByteReaderBytes', () => {
|
|
34
|
+
// Rust-only: rejects a count that would overflow native pointer arithmetic
|
|
29
35
|
it('reports whether count bytes remain from the current offset', () => {
|
|
30
|
-
const
|
|
36
|
+
const bytes = new Uint8Array(8).fill(0);
|
|
37
|
+
const reader = createByteReader(bytes, 4);
|
|
31
38
|
expect(hasByteReaderBytes(reader, 4)).toBe(true);
|
|
32
|
-
expect(hasByteReaderBytes(reader, 5)).toBe(
|
|
39
|
+
expect(!hasByteReaderBytes(reader, 5)).toBe(true);
|
|
33
40
|
expect(hasByteReaderBytes(reader, 0)).toBe(true);
|
|
34
41
|
});
|
|
35
42
|
});
|
|
36
43
|
|
|
37
44
|
describe('readByteReaderU16', () => {
|
|
38
|
-
it('reads little
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
expect(reader
|
|
45
|
+
it('reads little endian and advances two', () => {
|
|
46
|
+
const bytes: Uint8Array = new Uint8Array([0x34, 0x12]);
|
|
47
|
+
let reader = createByteReader(bytes, undefined);
|
|
48
|
+
expect(readByteReaderU16(reader)).toEqual(0x1234);
|
|
49
|
+
expect(reader.offset).toEqual(2);
|
|
42
50
|
});
|
|
43
51
|
});
|
|
44
52
|
|
|
45
53
|
describe('readByteReaderU24', () => {
|
|
46
|
-
it('reads a
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
expect(reader
|
|
54
|
+
it('reads a three byte little endian value and advances three', () => {
|
|
55
|
+
const bytes: Uint8Array = new Uint8Array([0x56, 0x34, 0x12]);
|
|
56
|
+
let reader = createByteReader(bytes, undefined);
|
|
57
|
+
expect(readByteReaderU24(reader)).toEqual(0x123456);
|
|
58
|
+
expect(reader.offset).toEqual(3);
|
|
50
59
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
expect(readByteReaderU24(reader)).
|
|
60
|
+
it('reads the full unsigned range', () => {
|
|
61
|
+
const bytes: Uint8Array = new Uint8Array([0xff, 0xff, 0xff]);
|
|
62
|
+
let reader = createByteReader(bytes, undefined);
|
|
63
|
+
expect(readByteReaderU24(reader)).toEqual(0xff_ffff);
|
|
55
64
|
});
|
|
56
65
|
});
|
|
57
66
|
|
|
58
67
|
describe('readByteReaderU24BigEndian', () => {
|
|
59
|
-
it('reads a
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
expect(reader
|
|
68
|
+
it('reads a three byte big endian value and advances three', () => {
|
|
69
|
+
const bytes: Uint8Array = new Uint8Array([0x12, 0x34, 0x56]);
|
|
70
|
+
let reader = createByteReader(bytes, undefined);
|
|
71
|
+
expect(readByteReaderU24BigEndian(reader)).toEqual(0x123456);
|
|
72
|
+
expect(reader.offset).toEqual(3);
|
|
63
73
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
expect(readByteReaderU24BigEndian(reader)).
|
|
74
|
+
it('reads the full unsigned range', () => {
|
|
75
|
+
const bytes: Uint8Array = new Uint8Array([0xff, 0xff, 0xff]);
|
|
76
|
+
let reader = createByteReader(bytes, undefined);
|
|
77
|
+
expect(readByteReaderU24BigEndian(reader)).toEqual(0xff_ffff);
|
|
68
78
|
});
|
|
69
79
|
});
|
|
70
80
|
|
|
71
81
|
describe('readByteReaderU32', () => {
|
|
72
|
-
it('reads little
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
expect(reader
|
|
82
|
+
it('reads little endian and advances four', () => {
|
|
83
|
+
const bytes: Uint8Array = new Uint8Array([0x78, 0x56, 0x34, 0x12]);
|
|
84
|
+
let reader = createByteReader(bytes, undefined);
|
|
85
|
+
expect(readByteReaderU32(reader)).toEqual(0x1234_5678);
|
|
86
|
+
expect(reader.offset).toEqual(4);
|
|
76
87
|
});
|
|
77
88
|
});
|
|
78
89
|
|
|
79
90
|
describe('readByteReaderU32BigEndian', () => {
|
|
80
|
-
it('reads
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
expect(reader
|
|
91
|
+
it('reads big endian and advances four', () => {
|
|
92
|
+
const bytes: Uint8Array = new Uint8Array([0x12, 0x34, 0x56, 0x78]);
|
|
93
|
+
let reader = createByteReader(bytes, undefined);
|
|
94
|
+
expect(readByteReaderU32BigEndian(reader)).toEqual(0x1234_5678);
|
|
95
|
+
expect(reader.offset).toEqual(4);
|
|
84
96
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
expect(readByteReaderU32BigEndian(reader)).
|
|
97
|
+
it('reads the full unsigned range', () => {
|
|
98
|
+
const bytes: Uint8Array = new Uint8Array([0xff, 0xff, 0xff, 0xff]);
|
|
99
|
+
let reader = createByteReader(bytes, undefined);
|
|
100
|
+
expect(readByteReaderU32BigEndian(reader)).toEqual(0xffffffff);
|
|
89
101
|
});
|
|
90
102
|
});
|
|
91
103
|
|
|
92
104
|
describe('readByteReaderU64', () => {
|
|
93
|
-
it('reads little
|
|
94
|
-
const bytes = new Uint8Array(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
it('reads little endian exactly and advances eight', () => {
|
|
106
|
+
const bytes: Uint8Array = new Uint8Array([0, 0x10, 0, 0, 2, 0, 0, 0]);
|
|
107
|
+
let reader = createByteReader(bytes, undefined);
|
|
108
|
+
expect(readByteReaderU64(reader)).toEqual(2 * 0x1_0000_0000 + 0x1000);
|
|
109
|
+
expect(reader.offset).toEqual(8);
|
|
110
|
+
});
|
|
111
|
+
it('reads the low word as unsigned when combining the result', () => {
|
|
112
|
+
const bytes: Uint8Array = new Uint8Array([0xff, 0xff, 0xff, 0xff, 2, 0, 0, 0]);
|
|
113
|
+
let reader = createByteReader(bytes, undefined);
|
|
114
|
+
expect(readByteReaderU64(reader)).toEqual(3 * 0x1_0000_0000 - 1);
|
|
100
115
|
});
|
|
101
116
|
});
|
|
102
117
|
|
|
103
118
|
describe('readByteReaderU8', () => {
|
|
104
|
-
it('reads one byte and advances
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
expect(reader
|
|
119
|
+
it('reads one byte and advances one', () => {
|
|
120
|
+
const bytes: Uint8Array = new Uint8Array([0xab]);
|
|
121
|
+
let reader = createByteReader(bytes, undefined);
|
|
122
|
+
expect(readByteReaderU8(reader)).toEqual(0xab);
|
|
123
|
+
expect(reader.offset).toEqual(1);
|
|
108
124
|
});
|
|
109
125
|
});
|
|
110
126
|
|
|
111
127
|
describe('skipByteReader', () => {
|
|
112
128
|
it('advances the offset without reading', () => {
|
|
113
|
-
const
|
|
129
|
+
const bytes = new Uint8Array(8).fill(0);
|
|
130
|
+
let reader = createByteReader(bytes, undefined);
|
|
114
131
|
skipByteReader(reader, 3);
|
|
115
|
-
expect(reader.offset).
|
|
132
|
+
expect(reader.offset).toEqual(3);
|
|
116
133
|
});
|
|
117
134
|
});
|