@flighthq/buffer 0.0.0-stage → 0.5.1-next.3302.76ece6b
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 +13 -0
- package/dist/byteReader.d.ts.map +1 -0
- package/dist/byteReader.js +50 -0
- package/dist/byteReader.js.map +1 -0
- package/dist/contract.d.ts +2 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -4
- package/src/byteReader.test.ts +117 -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-next.3302.76ece6b](https://github.com/flighthq/flight/tree/76ece6bee38e3d07816f341b7f017bfcec3e8e29/packages/buffer)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/76ece6bee38e3d07816f341b7f017bfcec3e8e29/LICENSE.md)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { ByteReader } from '@flighthq/types/contract';
|
|
2
|
+
import type { ByteReader, NonEntityCreateResult } from '@flighthq/types/contract';
|
|
3
|
+
export declare function createByteReader(bytes: Readonly<Uint8Array>, offset?: number): NonEntityCreateResult<ByteReader, 'descriptor'>;
|
|
4
|
+
export declare function hasByteReaderBytes(reader: Readonly<ByteReader>, count: number): boolean;
|
|
5
|
+
export declare function readByteReaderU16(reader: ByteReader): number;
|
|
6
|
+
export declare function readByteReaderU24(reader: ByteReader): number;
|
|
7
|
+
export declare function readByteReaderU24BigEndian(reader: ByteReader): number;
|
|
8
|
+
export declare function readByteReaderU32(reader: ByteReader): number;
|
|
9
|
+
export declare function readByteReaderU32BigEndian(reader: ByteReader): number;
|
|
10
|
+
export declare function readByteReaderU64(reader: ByteReader): number;
|
|
11
|
+
export declare function readByteReaderU8(reader: ByteReader): number;
|
|
12
|
+
export declare function skipByteReader(reader: ByteReader, count: number): void;
|
|
13
|
+
//# sourceMappingURL=byteReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byteReader.d.ts","sourceRoot":"","sources":["../src/byteReader.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAElF,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,EAC3B,MAAM,SAAI,GACT,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,CAI5D;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,CAI5D;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAIrE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAK5D;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,50 @@
|
|
|
1
|
+
export function createByteReader(bytes, offset = 0) {
|
|
2
|
+
return { view: new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), offset };
|
|
3
|
+
}
|
|
4
|
+
export function hasByteReaderBytes(reader, count) {
|
|
5
|
+
return count >= 0 && reader.offset + count <= reader.view.byteLength;
|
|
6
|
+
}
|
|
7
|
+
export function readByteReaderU16(reader) {
|
|
8
|
+
const value = reader.view.getUint16(reader.offset, true);
|
|
9
|
+
reader.offset += 2;
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
export function readByteReaderU24(reader) {
|
|
13
|
+
const view = reader.view;
|
|
14
|
+
const offset = reader.offset;
|
|
15
|
+
const value = view.getUint8(offset) | (view.getUint8(offset + 1) << 8) | (view.getUint8(offset + 2) << 16);
|
|
16
|
+
reader.offset += 3;
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
export function readByteReaderU24BigEndian(reader) {
|
|
20
|
+
const view = reader.view;
|
|
21
|
+
const offset = reader.offset;
|
|
22
|
+
const value = (view.getUint8(offset) << 16) | (view.getUint8(offset + 1) << 8) | view.getUint8(offset + 2);
|
|
23
|
+
reader.offset += 3;
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
export function readByteReaderU32(reader) {
|
|
27
|
+
const value = reader.view.getUint32(reader.offset, true);
|
|
28
|
+
reader.offset += 4;
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
export function readByteReaderU32BigEndian(reader) {
|
|
32
|
+
const value = reader.view.getUint32(reader.offset, false);
|
|
33
|
+
reader.offset += 4;
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
export function readByteReaderU64(reader) {
|
|
37
|
+
const low = reader.view.getUint32(reader.offset, true);
|
|
38
|
+
const high = reader.view.getUint32(reader.offset + 4, true);
|
|
39
|
+
reader.offset += 8;
|
|
40
|
+
return high * 0x1_0000_0000 + low;
|
|
41
|
+
}
|
|
42
|
+
export function readByteReaderU8(reader) {
|
|
43
|
+
const value = reader.view.getUint8(reader.offset);
|
|
44
|
+
reader.offset += 1;
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
export function skipByteReader(reader, count) {
|
|
48
|
+
reader.offset += count;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=byteReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byteReader.js","sourceRoot":"","sources":["../src/byteReader.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/buffer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.1-next.3302.76ece6b",
|
|
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
|
+
"test": "vitest run --config vitest.config.ts",
|
|
36
|
+
"test:watch": "vitest --watch --config vitest.config.ts",
|
|
37
|
+
"prepack": "npm run clean && npm run clean:dist && npm run build",
|
|
38
|
+
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@flighthq/types": "0.5.1-next.3302.76ece6b"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "^5.3.0"
|
|
45
|
+
},
|
|
46
|
+
"description": "Byte-level buffer reading utilities",
|
|
47
|
+
"sideEffects": false
|
|
48
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createByteReader,
|
|
3
|
+
hasByteReaderBytes,
|
|
4
|
+
readByteReaderU16,
|
|
5
|
+
readByteReaderU24,
|
|
6
|
+
readByteReaderU24BigEndian,
|
|
7
|
+
readByteReaderU32,
|
|
8
|
+
readByteReaderU32BigEndian,
|
|
9
|
+
readByteReaderU64,
|
|
10
|
+
readByteReaderU8,
|
|
11
|
+
skipByteReader,
|
|
12
|
+
} from './byteReader.ts';
|
|
13
|
+
|
|
14
|
+
describe('createByteReader', () => {
|
|
15
|
+
it('starts at the given offset', () => {
|
|
16
|
+
const reader = createByteReader(new Uint8Array([1, 2, 3, 4]), 2);
|
|
17
|
+
expect(reader.offset).toBe(2);
|
|
18
|
+
expect(readByteReaderU8(reader)).toBe(3);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('views a subarray by its byteOffset', () => {
|
|
22
|
+
const backing = new Uint8Array([9, 9, 0x01, 0x00]);
|
|
23
|
+
const reader = createByteReader(backing.subarray(2));
|
|
24
|
+
expect(readByteReaderU16(reader)).toBe(1);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('hasByteReaderBytes', () => {
|
|
29
|
+
it('reports whether count bytes remain from the current offset', () => {
|
|
30
|
+
const reader = createByteReader(new Uint8Array(8), 4);
|
|
31
|
+
expect(hasByteReaderBytes(reader, 4)).toBe(true);
|
|
32
|
+
expect(hasByteReaderBytes(reader, 5)).toBe(false);
|
|
33
|
+
expect(hasByteReaderBytes(reader, 0)).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('readByteReaderU16', () => {
|
|
38
|
+
it('reads little-endian and advances 2', () => {
|
|
39
|
+
const reader = createByteReader(new Uint8Array([0x34, 0x12]));
|
|
40
|
+
expect(readByteReaderU16(reader)).toBe(0x1234);
|
|
41
|
+
expect(reader.offset).toBe(2);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('readByteReaderU24', () => {
|
|
46
|
+
it('reads a 3-byte little-endian value and advances 3', () => {
|
|
47
|
+
const reader = createByteReader(new Uint8Array([0x56, 0x34, 0x12]));
|
|
48
|
+
expect(readByteReaderU24(reader)).toBe(0x123456);
|
|
49
|
+
expect(reader.offset).toBe(3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('reads the full 24-bit range without sign issues', () => {
|
|
53
|
+
const reader = createByteReader(new Uint8Array([0xff, 0xff, 0xff]));
|
|
54
|
+
expect(readByteReaderU24(reader)).toBe(0xffffff);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('readByteReaderU24BigEndian', () => {
|
|
59
|
+
it('reads a 3-byte big-endian value and advances 3', () => {
|
|
60
|
+
const reader = createByteReader(new Uint8Array([0x12, 0x34, 0x56]));
|
|
61
|
+
expect(readByteReaderU24BigEndian(reader)).toBe(0x123456);
|
|
62
|
+
expect(reader.offset).toBe(3);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('reads the full 24-bit range without sign issues', () => {
|
|
66
|
+
const reader = createByteReader(new Uint8Array([0xff, 0xff, 0xff]));
|
|
67
|
+
expect(readByteReaderU24BigEndian(reader)).toBe(0xffffff);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('readByteReaderU32', () => {
|
|
72
|
+
it('reads little-endian and advances 4', () => {
|
|
73
|
+
const reader = createByteReader(new Uint8Array([0x78, 0x56, 0x34, 0x12]));
|
|
74
|
+
expect(readByteReaderU32(reader)).toBe(0x12345678);
|
|
75
|
+
expect(reader.offset).toBe(4);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('readByteReaderU32BigEndian', () => {
|
|
80
|
+
it('reads a 4-byte big-endian value and advances 4', () => {
|
|
81
|
+
const reader = createByteReader(new Uint8Array([0x12, 0x34, 0x56, 0x78]));
|
|
82
|
+
expect(readByteReaderU32BigEndian(reader)).toBe(0x12345678);
|
|
83
|
+
expect(reader.offset).toBe(4);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('reads the full 32-bit range as an unsigned value', () => {
|
|
87
|
+
const reader = createByteReader(new Uint8Array([0xff, 0xff, 0xff, 0xff]));
|
|
88
|
+
expect(readByteReaderU32BigEndian(reader)).toBe(0xffffffff);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('readByteReaderU64', () => {
|
|
93
|
+
it('reads little-endian as a number and advances 8', () => {
|
|
94
|
+
const bytes = new Uint8Array(8);
|
|
95
|
+
new DataView(bytes.buffer).setUint32(0, 0x1000, true);
|
|
96
|
+
new DataView(bytes.buffer).setUint32(4, 0x2, true);
|
|
97
|
+
const reader = createByteReader(bytes);
|
|
98
|
+
expect(readByteReaderU64(reader)).toBe(0x2 * 0x1_0000_0000 + 0x1000);
|
|
99
|
+
expect(reader.offset).toBe(8);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('readByteReaderU8', () => {
|
|
104
|
+
it('reads one byte and advances 1', () => {
|
|
105
|
+
const reader = createByteReader(new Uint8Array([0xab]));
|
|
106
|
+
expect(readByteReaderU8(reader)).toBe(0xab);
|
|
107
|
+
expect(reader.offset).toBe(1);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('skipByteReader', () => {
|
|
112
|
+
it('advances the offset without reading', () => {
|
|
113
|
+
const reader = createByteReader(new Uint8Array(8));
|
|
114
|
+
skipByteReader(reader, 3);
|
|
115
|
+
expect(reader.offset).toBe(3);
|
|
116
|
+
});
|
|
117
|
+
});
|