@flighthq/buffer 0.0.0-stage → 0.5.1-edge.4334.2a5a54c
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/LICENSE.md +9 -0
- package/README.md +16 -2
- package/dist/byteReader.d.ts +20 -0
- package/dist/byteReader.d.ts.map +1 -0
- package/dist/byteReader.js +65 -0
- package/dist/byteReader.js.map +1 -0
- package/dist/contract.d.ts +3 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +4 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -4
- package/src/byteReader.test.ts +134 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-2026 Joshua Granick and other contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @flighthq/buffer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Byte-level buffer reading utilities
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @flighthq/buffer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Import the supported application-facing API from `@flighthq/buffer`. The `@flighthq/buffer/contract` export is the wider package-to-package contract used to compose Flight itself.
|
|
12
|
+
|
|
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
|
+
|
|
15
|
+
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
+
- [Source for @flighthq/buffer@0.5.1-edge.4334.2a5a54c](https://github.com/flighthq/flight/tree/2a5a54c3b182bc9c1ac247df07e9c0fcf44e668b/packages/buffer)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/2a5a54c3b182bc9c1ac247df07e9c0fcf44e668b/LICENSE.md)
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
10
|
+
export declare function createByteReader(bytes: Readonly<Uint8Array>, offset?: number): NonEntityCreateResult<ByteReader, 'descriptor'>;
|
|
11
|
+
export declare function hasByteReaderBytes(reader: Readonly<ByteReader>, count: number): boolean;
|
|
12
|
+
export declare function readByteReaderU16(reader: ByteReader): number;
|
|
13
|
+
export declare function readByteReaderU24(reader: ByteReader): number;
|
|
14
|
+
export declare function readByteReaderU24BigEndian(reader: ByteReader): number;
|
|
15
|
+
export declare function readByteReaderU32(reader: ByteReader): number;
|
|
16
|
+
export declare function readByteReaderU32BigEndian(reader: ByteReader): number;
|
|
17
|
+
export declare function readByteReaderU64(reader: ByteReader): number;
|
|
18
|
+
export declare function readByteReaderU8(reader: ByteReader): number;
|
|
19
|
+
export declare function skipByteReader(reader: ByteReader, count: number): void;
|
|
20
|
+
//# sourceMappingURL=byteReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 };
|
|
5
|
+
}
|
|
6
|
+
export function hasByteReaderBytes(reader, count) {
|
|
7
|
+
return reader.offset <= reader.view.length && count <= reader.view.length - reader.offset;
|
|
8
|
+
}
|
|
9
|
+
export function readByteReaderU16(reader) {
|
|
10
|
+
const offset = reader.offset;
|
|
11
|
+
const value = (reader.view[offset] & 0xffff) | ((reader.view[offset + 1] & 0xffff) << 8);
|
|
12
|
+
reader.offset += 2;
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
export function readByteReaderU24(reader) {
|
|
16
|
+
const offset = reader.offset;
|
|
17
|
+
const value = (reader.view[offset] >>> 0) | ((reader.view[offset + 1] >>> 0) << 8) | ((reader.view[offset + 2] >>> 0) << 16);
|
|
18
|
+
reader.offset += 3;
|
|
19
|
+
return value >>> 0;
|
|
20
|
+
}
|
|
21
|
+
export function readByteReaderU24BigEndian(reader) {
|
|
22
|
+
const offset = reader.offset;
|
|
23
|
+
const value = ((reader.view[offset] >>> 0) << 16) | ((reader.view[offset + 1] >>> 0) << 8) | (reader.view[offset + 2] >>> 0);
|
|
24
|
+
reader.offset += 3;
|
|
25
|
+
return value >>> 0;
|
|
26
|
+
}
|
|
27
|
+
export function readByteReaderU32(reader) {
|
|
28
|
+
const offset = reader.offset;
|
|
29
|
+
const value = readByteReaderU32At(reader.view, offset);
|
|
30
|
+
reader.offset += 4;
|
|
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);
|
|
39
|
+
}
|
|
40
|
+
export function readByteReaderU32BigEndian(reader) {
|
|
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);
|
|
46
|
+
reader.offset += 4;
|
|
47
|
+
return value >>> 0;
|
|
48
|
+
}
|
|
49
|
+
export function readByteReaderU64(reader) {
|
|
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;
|
|
54
|
+
reader.offset += 8;
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
export function readByteReaderU8(reader) {
|
|
58
|
+
const value = reader.view[reader.offset];
|
|
59
|
+
reader.offset += 1;
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
export function skipByteReader(reader, count) {
|
|
63
|
+
reader.offset += count;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=byteReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,M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AI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAClC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;IACnB,OAAO,KAAK,KAAK,CAAC,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAkB;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,GAAG,GAAG,mBAAmB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,mBAAmB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAG,IAAI,GAAG,aAAa,GAAG,GAAG,CAAC;IACzC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;IACnB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;IACnB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAkB,EAAE,KAAa;IAC9D,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createByteReader, hasByteReaderBytes, readByteReaderU16, readByteReaderU24, readByteReaderU24BigEndian, readByteReaderU32, readByteReaderU32BigEndian, readByteReaderU64, readByteReaderU8, skipByteReader, } from './byteReader.ts';
|
|
2
|
+
export type { ByteReader } from './byteReader.ts';
|
|
3
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
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';
|
|
4
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createByteReader, hasByteReaderBytes, readByteReaderU16, readByteReaderU24, readByteReaderU24BigEndian, readByteReaderU32, readByteReaderU32BigEndian, readByteReaderU64, readByteReaderU8, skipByteReader, } from './contract.ts';
|
|
2
|
+
export type { ByteReader } from './contract.ts';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
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';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/buffer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.1-edge.4334.2a5a54c",
|
|
4
|
+
"author": "Joshua Granick and other contributors",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/flighthq/flight.git",
|
|
9
|
+
"directory": "packages/buffer"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./contract": {
|
|
20
|
+
"types": "./dist/contract.d.ts",
|
|
21
|
+
"default": "./dist/contract.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src/**/*.test.ts",
|
|
27
|
+
"!dist/**/*.test.js",
|
|
28
|
+
"!dist/**/*.test.d.ts",
|
|
29
|
+
"!dist/**/*.test.js.map",
|
|
30
|
+
"!dist/**/*.test.d.ts.map"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -b",
|
|
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",
|
|
37
|
+
"test": "vitest run --config vitest.config.ts",
|
|
38
|
+
"test:watch": "vitest --watch --config vitest.config.ts",
|
|
39
|
+
"prepack": "npm run clean && npm run clean:dist && npm run build",
|
|
40
|
+
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@flighthq/entity": "0.5.1-edge.4334.2a5a54c"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"typescript": "^7.0.2"
|
|
47
|
+
},
|
|
48
|
+
"description": "Byte-level buffer reading utilities",
|
|
49
|
+
"sideEffects": false
|
|
50
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
|
|
6
|
+
import {
|
|
7
|
+
createByteReader,
|
|
8
|
+
hasByteReaderBytes,
|
|
9
|
+
readByteReaderU16,
|
|
10
|
+
readByteReaderU24,
|
|
11
|
+
readByteReaderU24BigEndian,
|
|
12
|
+
readByteReaderU32,
|
|
13
|
+
readByteReaderU32BigEndian,
|
|
14
|
+
readByteReaderU64,
|
|
15
|
+
readByteReaderU8,
|
|
16
|
+
skipByteReader,
|
|
17
|
+
} from './contract.ts';
|
|
18
|
+
|
|
19
|
+
describe('createByteReader', () => {
|
|
20
|
+
it('starts at the given offset', () => {
|
|
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);
|
|
25
|
+
});
|
|
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);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('hasByteReaderBytes', () => {
|
|
34
|
+
// Rust-only: rejects a count that would overflow native pointer arithmetic
|
|
35
|
+
it('reports whether count bytes remain from the current offset', () => {
|
|
36
|
+
const bytes = new Uint8Array(8).fill(0);
|
|
37
|
+
const reader = createByteReader(bytes, 4);
|
|
38
|
+
expect(hasByteReaderBytes(reader, 4)).toBe(true);
|
|
39
|
+
expect(!hasByteReaderBytes(reader, 5)).toBe(true);
|
|
40
|
+
expect(hasByteReaderBytes(reader, 0)).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('readByteReaderU16', () => {
|
|
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);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('readByteReaderU24', () => {
|
|
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);
|
|
59
|
+
});
|
|
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);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('readByteReaderU24BigEndian', () => {
|
|
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);
|
|
73
|
+
});
|
|
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);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('readByteReaderU32', () => {
|
|
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);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('readByteReaderU32BigEndian', () => {
|
|
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);
|
|
96
|
+
});
|
|
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);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('readByteReaderU64', () => {
|
|
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);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('readByteReaderU8', () => {
|
|
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);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('skipByteReader', () => {
|
|
128
|
+
it('advances the offset without reading', () => {
|
|
129
|
+
const bytes = new Uint8Array(8).fill(0);
|
|
130
|
+
let reader = createByteReader(bytes, undefined);
|
|
131
|
+
skipByteReader(reader, 3);
|
|
132
|
+
expect(reader.offset).toEqual(3);
|
|
133
|
+
});
|
|
134
|
+
});
|