@kaeawc/auto-mobile 0.0.89 → 0.0.91
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 +7 -0
- package/README.md.backup +7 -0
- package/dist/build-info.json +12 -10
- package/dist/schemas/prototype-platform-permissions.json +75 -0
- package/dist/schemas/test-plan.schema.json +2 -2
- package/dist/src/index.js +946 -874
- package/dist/src/utils/workers/iosBundleExtractWorker.js +3 -3
- package/mcp-skills/auto-mobile-usage/SKILL.md +1 -0
- package/node_modules/strtok3/README.md +172 -113
- package/node_modules/strtok3/lib/BufferSizeError.js +1 -1
- package/node_modules/strtok3/lib/TokenWriter.js +151 -0
- package/node_modules/strtok3/lib/core.js +1 -0
- package/node_modules/strtok3/package.json +2 -2
- package/node_modules/token-types/LICENSE.txt +9 -9
- package/node_modules/token-types/README.md +160 -120
- package/node_modules/token-types/{lib → dist/lib}/index.js +21 -3
- package/node_modules/token-types/package.json +81 -81
- package/package.json +11 -9
- package/schemas/prototype-platform-permissions.json +75 -0
- package/schemas/test-plan.schema.json +2 -2
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { BufferSizeError, getMaxBufferSize } from './BufferSizeError.js';
|
|
2
|
+
const DEFAULT_INITIAL_CAPACITY = 1024;
|
|
3
|
+
const MINIMUM_CAPACITY = 16;
|
|
4
|
+
/**
|
|
5
|
+
* Growable byte buffer for serializing tokens.
|
|
6
|
+
*
|
|
7
|
+
* Numeric and structured tokens are written through their `IToken.put`
|
|
8
|
+
* implementation, so encoding and decoding share the same token definition.
|
|
9
|
+
* Encoders must write synchronously within their declared token region and
|
|
10
|
+
* must not retain the destination buffer.
|
|
11
|
+
*/
|
|
12
|
+
export class TokenWriter {
|
|
13
|
+
/**
|
|
14
|
+
* Create a token writer.
|
|
15
|
+
* @param initialCapacity - Initial buffer size in bytes. The writer grows as needed.
|
|
16
|
+
* Defaults to 1024, reduced to maxBufferSize when a smaller cap is configured.
|
|
17
|
+
* @param options - Optional output and backing-buffer limit.
|
|
18
|
+
*/
|
|
19
|
+
constructor(initialCapacity, options) {
|
|
20
|
+
this.offset = 0;
|
|
21
|
+
this.maxBufferSize = getMaxBufferSize(options);
|
|
22
|
+
const capacity = initialCapacity === undefined ? Math.min(DEFAULT_INITIAL_CAPACITY, this.maxBufferSize) : initialCapacity;
|
|
23
|
+
this.validateCapacity(capacity, 'initialCapacity');
|
|
24
|
+
this.buffer = new Uint8Array(Math.min(this.maxBufferSize, Math.max(MINIMUM_CAPACITY, capacity)));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Number of bytes written so far.
|
|
28
|
+
*/
|
|
29
|
+
get length() {
|
|
30
|
+
return this.offset;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reserve a zero-filled region and advance the write position.
|
|
34
|
+
* @param length - Number of bytes to reserve.
|
|
35
|
+
* @returns Offset of the reserved region.
|
|
36
|
+
*/
|
|
37
|
+
reserve(length) {
|
|
38
|
+
this.validateLength(length, 'length');
|
|
39
|
+
const start = this.offset;
|
|
40
|
+
this.ensureCapacity(length);
|
|
41
|
+
this.offset += length;
|
|
42
|
+
return start;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Encode a token at the current write position.
|
|
46
|
+
* If encoding throws, the written bytes and length remain unchanged.
|
|
47
|
+
* @param token - Token providing the byte length and encoder.
|
|
48
|
+
* @param value - Value to encode.
|
|
49
|
+
* @returns Number of bytes written, equal to token.len.
|
|
50
|
+
*/
|
|
51
|
+
writeToken(token, value) {
|
|
52
|
+
const length = token.len;
|
|
53
|
+
this.validateLength(length, 'token length');
|
|
54
|
+
this.ensureCapacity(length);
|
|
55
|
+
const start = this.offset;
|
|
56
|
+
try {
|
|
57
|
+
token.put(this.buffer, start, value);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
this.buffer.fill(0, start, start + length);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
this.offset += length;
|
|
64
|
+
return length;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Append raw bytes.
|
|
68
|
+
* @param value - Bytes to append. The data is copied.
|
|
69
|
+
* @returns Number of bytes written.
|
|
70
|
+
*/
|
|
71
|
+
writeBuffer(value) {
|
|
72
|
+
this.validateLength(value.length, 'value length');
|
|
73
|
+
const start = this.offset;
|
|
74
|
+
this.ensureCapacity(value.length);
|
|
75
|
+
this.buffer.set(value, start);
|
|
76
|
+
this.offset += value.length;
|
|
77
|
+
return value.length;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Alias for writeBuffer. The data is copied.
|
|
81
|
+
* @param value - Bytes to append.
|
|
82
|
+
* @returns Number of bytes written.
|
|
83
|
+
*/
|
|
84
|
+
writeBytes(value) {
|
|
85
|
+
return this.writeBuffer(value);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Append zero bytes.
|
|
89
|
+
* @param length - Number of zero bytes to append.
|
|
90
|
+
* @returns Number of bytes written.
|
|
91
|
+
*/
|
|
92
|
+
writeZeros(length) {
|
|
93
|
+
const start = this.reserve(length);
|
|
94
|
+
this.buffer.fill(0, start, start + length);
|
|
95
|
+
return length;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Overwrite a previously reserved or written region with an encoded token.
|
|
99
|
+
* If encoding throws, the original bytes are restored and length is unchanged.
|
|
100
|
+
* @param token - Token providing the byte length and encoder.
|
|
101
|
+
* @param offset - Absolute offset of the region.
|
|
102
|
+
* @param value - Value to encode.
|
|
103
|
+
*/
|
|
104
|
+
patchToken(token, offset, value) {
|
|
105
|
+
this.validateLength(offset, 'offset');
|
|
106
|
+
const length = token.len;
|
|
107
|
+
this.validateLength(length, 'token length');
|
|
108
|
+
if (offset + length > this.offset) {
|
|
109
|
+
throw new RangeError(`Invalid patch range: offset=${offset}, length=${length}, written=${this.offset}`);
|
|
110
|
+
}
|
|
111
|
+
const original = this.buffer.slice(offset, offset + length);
|
|
112
|
+
try {
|
|
113
|
+
token.put(this.buffer, offset, value);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
this.buffer.set(original, offset);
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Return a copy of the written bytes.
|
|
122
|
+
*/
|
|
123
|
+
toUint8Array() {
|
|
124
|
+
return this.buffer.slice(0, this.offset);
|
|
125
|
+
}
|
|
126
|
+
ensureCapacity(extra) {
|
|
127
|
+
const required = this.offset + extra;
|
|
128
|
+
this.validateCapacity(required, 'required capacity');
|
|
129
|
+
if (required <= this.buffer.length) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let capacity = this.buffer.length;
|
|
133
|
+
while (capacity < required) {
|
|
134
|
+
capacity = Math.min(capacity * 2, this.maxBufferSize);
|
|
135
|
+
}
|
|
136
|
+
const next = new Uint8Array(capacity);
|
|
137
|
+
next.set(this.buffer.subarray(0, this.offset));
|
|
138
|
+
this.buffer = next;
|
|
139
|
+
}
|
|
140
|
+
validateCapacity(value, name) {
|
|
141
|
+
this.validateLength(value, name);
|
|
142
|
+
if (value > this.maxBufferSize) {
|
|
143
|
+
throw new BufferSizeError(value, this.maxBufferSize);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
validateLength(value, name) {
|
|
147
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
148
|
+
throw new RangeError(`${name} must be a non-negative safe integer`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -10,6 +10,7 @@ export { isRandomAccessTokenizer } from './isRandomAccessTokenizer.js';
|
|
|
10
10
|
export { AbortError, EndOfStreamError } from './stream/index.js';
|
|
11
11
|
export { TokenizerBoundaryError } from './TokenizerBoundaryError.js';
|
|
12
12
|
export { createTokenizerView } from './TokenizerView.js';
|
|
13
|
+
export { TokenWriter } from './TokenWriter.js';
|
|
13
14
|
/**
|
|
14
15
|
* Construct ReadStreamTokenizer from given Stream.
|
|
15
16
|
* Will set fileSize, if provided given Stream has set the .path property/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strtok3",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.7.0",
|
|
4
4
|
"description": "A promise based streaming tokenizer",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Borewit",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@tokenizer/token": "^0.3.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@biomejs/biome": "2.
|
|
63
|
+
"@biomejs/biome": "2.6.4",
|
|
64
64
|
"@types/chai": "^5.2.3",
|
|
65
65
|
"@types/chai-as-promised": "^8.0.2",
|
|
66
66
|
"@types/debug": "^4.1.13",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright © 2026 Borewit
|
|
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.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2026 Borewit
|
|
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.
|
|
@@ -1,120 +1,160 @@
|
|
|
1
|
-
[](https://github.com/Borewit/token-types/actions/workflows/nodejs-ci.yml?query=branch%3Amaster)
|
|
2
|
-
[](https://npmjs.org/package/token-types)
|
|
3
|
-
[](https://npmcharts.com/compare/token-types,strtok3?start=1200&interval=30)
|
|
4
|
-
[](https://github.com/Borewit/token-types/actions/workflows/nodejs-ci.yml?query=branch%3Amaster)
|
|
2
|
+
[](https://npmjs.org/package/token-types)
|
|
3
|
+
[](https://npmcharts.com/compare/token-types,strtok3?start=1200&interval=30)
|
|
4
|
+
[](https://codecov.io/gh/Borewit/token-types)
|
|
5
|
+
[](https://deepscan.io/dashboard#view=project&tid=5165&pid=6940&bid=61852)
|
|
6
|
+
[](https://snyk.io/test/github/Borewit/token-types?targetFile=package.json)
|
|
7
|
+
|
|
8
|
+
# token-types
|
|
9
|
+
|
|
10
|
+
A primitive token library used to read and write from a `Uint8Array`.
|
|
11
|
+
Although it is possible to use this module directly, it is primarily designed to be used with [strtok3 tokenizer](https://github.com/Borewit/strtok3).
|
|
12
|
+
|
|
13
|
+
## Compatibility
|
|
14
|
+
|
|
15
|
+
Module: version 5 migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
|
16
|
+
JavaScript is compliant with [ECMAScript 2019 (ES10)](https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_%E2%80%93_ECMAScript_2019).
|
|
17
|
+
|
|
18
|
+
Node.js 18 is supported for running the published package; it is not a supported
|
|
19
|
+
build environment. The test toolchain requires Node.js 22.12 or later. CI builds
|
|
20
|
+
on Node.js 24 and runs the tests on Node.js 22, 24 and 26.
|
|
21
|
+
|
|
22
|
+
## Development
|
|
23
|
+
|
|
24
|
+
Use Node.js 24 and the Yarn version pinned in `package.json` to install development
|
|
25
|
+
dependencies and build from source:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
corepack enable
|
|
29
|
+
yarn install --immutable
|
|
30
|
+
yarn test
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`yarn test` type-checks the sources and runs the Vitest suite against the
|
|
34
|
+
TypeScript sources. `yarn test:watch` runs Vitest in watch mode, and
|
|
35
|
+
`yarn test-coverage` writes text and LCOV reports to `coverage`. `yarn clean`
|
|
36
|
+
removes `dist` and coverage.
|
|
37
|
+
|
|
38
|
+
`yarn lint` checks the Markdown and Biome rules. `yarn format:check` verifies
|
|
39
|
+
Biome formatting, and `yarn fix` applies formatting, import organization and
|
|
40
|
+
safe lint fixes.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm install --save token-types
|
|
46
|
+
```
|
|
47
|
+
Usually in combination with [strtok3](https://github.com/Borewit/strtok3):
|
|
48
|
+
```sh
|
|
49
|
+
npm install --save strtok3
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Using TypeScript you should also install [@tokenizer/token](https://github.com/Borewit/tokenizer-token) as a development
|
|
53
|
+
dependency:
|
|
54
|
+
|
|
55
|
+
```shell
|
|
56
|
+
npm install --save-dev @tokenizer/token
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Example
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import * as strtok3 from 'strtok3';
|
|
64
|
+
import * as token from 'token-types';
|
|
65
|
+
|
|
66
|
+
(async () => {
|
|
67
|
+
|
|
68
|
+
const tokenizer = await strtok3.fromFile("somefile.bin");
|
|
69
|
+
try {
|
|
70
|
+
const myNumber = await tokenizer.readToken(token.Float32_BE);
|
|
71
|
+
console.log(`My number: ${myNumber}`);
|
|
72
|
+
} finally {
|
|
73
|
+
tokenizer.close(); // Close the file
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Tokens
|
|
79
|
+
|
|
80
|
+
### Numeric tokens
|
|
81
|
+
|
|
82
|
+
`token-types` supports a wide variety of numeric tokens out of the box:
|
|
83
|
+
|
|
84
|
+
| Token | Number | Bits | Endianness |
|
|
85
|
+
|---------------|------------------|------|----------------|
|
|
86
|
+
| `UINT8` | Unsigned integer | 8 | n/a |
|
|
87
|
+
| `UINT16_BE` | Unsigned integer | 16 | big endian |
|
|
88
|
+
| `UINT16_LE` | Unsigned integer | 16 | little endian |
|
|
89
|
+
| `UINT24_BE` | Unsigned integer | 24 | big endian |
|
|
90
|
+
| `UINT24_LE` | Unsigned integer | 24 | little endian |
|
|
91
|
+
| `UINT32_BE` | Unsigned integer | 32 | big endian |
|
|
92
|
+
| `UINT32_LE` | Unsigned integer | 32 | little endian |
|
|
93
|
+
| `UINT64_BE` | Unsigned integer | 64 | big endian |
|
|
94
|
+
| `UINT64_LE`* | Unsigned integer | 64 | little endian |
|
|
95
|
+
| `INT8` | Signed integer | 8 | n/a |
|
|
96
|
+
| `INT16_BE` | Signed integer | 16 | big endian |
|
|
97
|
+
| `INT16_LE` | Signed integer | 16 | little endian |
|
|
98
|
+
| `INT24_BE` | Signed integer | 24 | big endian |
|
|
99
|
+
| `INT24_LE` | Signed integer | 24 | little endian |
|
|
100
|
+
| `INT32_BE` | Signed integer | 32 | big endian |
|
|
101
|
+
| `INT32_LE` | Signed integer | 32 | little endian |
|
|
102
|
+
| `INT64_BE` | Signed integer | 64 | big endian |
|
|
103
|
+
| `INT64_LE`* | Signed integer | 64 | little endian |
|
|
104
|
+
| `Float16_BE` | IEEE 754 float | 16 | big endian |
|
|
105
|
+
| `Float16_LE` | IEEE 754 float | 16 | little endian |
|
|
106
|
+
| `Float32_BE` | IEEE 754 float | 32 | big endian |
|
|
107
|
+
| `Float32_LE` | IEEE 754 float | 32 | little endian |
|
|
108
|
+
| `Float64_BE` | IEEE 754 float | 64 | big endian |
|
|
109
|
+
| `Float64_LE` | IEEE 754 float | 64 | little endian |
|
|
110
|
+
| `Float80_BE`* | IEEE 754 float | 80 | big endian |
|
|
111
|
+
| `Float80_LE`* | IEEE 754 float | 80 | little endian |
|
|
112
|
+
|
|
113
|
+
(*) The tokens exceed the JavaScript IEEE 754 64-bit Floating Point precision, decoding and encoding is best effort based.
|
|
114
|
+
|
|
115
|
+
### String and byte tokens
|
|
116
|
+
|
|
117
|
+
`StringType` decoding is using [@borewit/text-codec](https://github.com/Borewit/text-codec).
|
|
118
|
+
|
|
119
|
+
`StringType` and `Uint8ArrayType` implement `IToken`, so the same fixed-size
|
|
120
|
+
token can decode and encode:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import { StringType, Uint8ArrayType } from 'token-types';
|
|
124
|
+
|
|
125
|
+
const ascii = new StringType(4, 'ascii');
|
|
126
|
+
const buffer = new Uint8Array(8);
|
|
127
|
+
ascii.put(buffer, 0, 'fLaC');
|
|
128
|
+
|
|
129
|
+
const bytes = new Uint8ArrayType(4);
|
|
130
|
+
bytes.put(buffer, 4, Uint8Array.from([1, 2, 3, 4]));
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`put` rejects values whose byte length differs from `len`, so a fixed-size
|
|
134
|
+
field is never silently truncated or padded.
|
|
135
|
+
|
|
136
|
+
### Custom tokens
|
|
137
|
+
|
|
138
|
+
Custom tokens can be added, suitable for reading binary files or network messages:
|
|
139
|
+
```js
|
|
140
|
+
ExtendedHeader = {
|
|
141
|
+
len: 10,
|
|
142
|
+
|
|
143
|
+
get: (buf, off) => {
|
|
144
|
+
return {
|
|
145
|
+
// Extended header size
|
|
146
|
+
size: Token.UINT32_BE.get(buf, off),
|
|
147
|
+
// Extended Flags
|
|
148
|
+
extendedFlags: Token.UINT16_BE.get(buf, off + 4),
|
|
149
|
+
// Size of padding
|
|
150
|
+
sizeOfPadding: Token.UINT32_BE.get(buf, off + 6),
|
|
151
|
+
// CRC data present
|
|
152
|
+
crcDataPresent: common.strtokBITSET.get(buf, off + 4, 31)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Licence
|
|
159
|
+
|
|
160
|
+
This project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { textDecode, textEncode } from '@borewit/text-codec';
|
|
1
2
|
import * as ieee754 from 'ieee754';
|
|
2
|
-
import { textDecode } from "@borewit/text-codec";
|
|
3
3
|
// Primitive types
|
|
4
4
|
function dv(array) {
|
|
5
5
|
return new DataView(array.buffer, array.byteOffset);
|
|
@@ -364,10 +364,13 @@ export class IgnoreType {
|
|
|
364
364
|
constructor(len) {
|
|
365
365
|
this.len = len;
|
|
366
366
|
}
|
|
367
|
-
// ToDo: don't read, but skip data
|
|
368
367
|
get(_array, _off) {
|
|
368
|
+
// ToDo: don't read, but skip data
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Fixed-size byte array
|
|
373
|
+
*/
|
|
371
374
|
export class Uint8ArrayType {
|
|
372
375
|
constructor(len) {
|
|
373
376
|
this.len = len;
|
|
@@ -375,9 +378,16 @@ export class Uint8ArrayType {
|
|
|
375
378
|
get(array, offset) {
|
|
376
379
|
return array.subarray(offset, offset + this.len);
|
|
377
380
|
}
|
|
381
|
+
put(array, offset, value) {
|
|
382
|
+
if (value.length !== this.len) {
|
|
383
|
+
throw new RangeError(`Expected a value of ${this.len} byte(s), got ${value.length}`);
|
|
384
|
+
}
|
|
385
|
+
array.set(value, offset);
|
|
386
|
+
return offset + this.len;
|
|
387
|
+
}
|
|
378
388
|
}
|
|
379
389
|
/**
|
|
380
|
-
*
|
|
390
|
+
* Decode or encode a fixed number of bytes as a string with a specified encoding.
|
|
381
391
|
* Supports all encodings supported by TextDecoder, plus 'windows-1252'.
|
|
382
392
|
*/
|
|
383
393
|
export class StringType {
|
|
@@ -389,6 +399,14 @@ export class StringType {
|
|
|
389
399
|
const bytes = data.subarray(offset, offset + this.len);
|
|
390
400
|
return textDecode(bytes, this.encoding);
|
|
391
401
|
}
|
|
402
|
+
put(array, offset, value) {
|
|
403
|
+
const bytes = textEncode(value, this.encoding);
|
|
404
|
+
if (bytes.length !== this.len) {
|
|
405
|
+
throw new RangeError(`Expected an encoded value of ${this.len} byte(s), got ${bytes.length}`);
|
|
406
|
+
}
|
|
407
|
+
array.set(bytes, offset);
|
|
408
|
+
return offset + this.len;
|
|
409
|
+
}
|
|
392
410
|
}
|
|
393
411
|
/**
|
|
394
412
|
* ANSI Latin 1 String using Windows-1252 (Code Page 1252)
|