@yume-chan/struct 2.0.0 → 2.3.2
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/CHANGELOG.md +37 -25
- package/esm/buffer.d.ts +65 -20
- package/esm/buffer.d.ts.map +1 -1
- package/esm/buffer.js +114 -117
- package/esm/buffer.js.map +1 -1
- package/esm/field/types.d.ts +8 -2
- package/esm/field/types.d.ts.map +1 -1
- package/esm/struct.d.ts +2 -2
- package/esm/struct.d.ts.map +1 -1
- package/esm/struct.js +11 -6
- package/esm/struct.js.map +1 -1
- package/esm/types.d.ts +0 -2
- package/esm/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/buffer.ts +226 -228
- package/src/field/types.ts +8 -2
- package/src/struct.ts +15 -7
- package/src/types.ts +0 -3
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
# Change Log - @yume-chan/struct
|
|
2
2
|
|
|
3
|
+
## 2.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8ba86f7: Fix an issue that some overloads of `buffer` (and `string`) ignores specified value converter
|
|
8
|
+
|
|
9
|
+
## 2.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 0bcb9b8: Fix `buffer` and `struct` may not have correct size
|
|
14
|
+
|
|
3
15
|
## 2.0.0
|
|
4
16
|
|
|
5
17
|
### Major Changes
|
|
6
18
|
|
|
7
|
-
-
|
|
19
|
+
- b79df96: Refactor struct package to allow `struct`s to be used as `field`
|
|
8
20
|
|
|
9
21
|
### Patch Changes
|
|
10
22
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
- @yume-chan/no-data-view@2.0.0
|
|
13
25
|
|
|
14
26
|
## 1.0.1
|
|
15
27
|
|
|
16
28
|
### Patch Changes
|
|
17
29
|
|
|
18
|
-
-
|
|
30
|
+
- 53688d3: Use PNPM workspace and Changesets to manage the monorepo.
|
|
19
31
|
|
|
20
32
|
Because Changesets doesn't support alpha versions (`0.x.x`), this version is `1.0.0`. Future versions will follow SemVer rules, for example, breaking API changes will introduce a new major version.
|
|
21
33
|
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
34
|
+
- db8466f: Rewrite the struct API completely
|
|
35
|
+
- db8466f: Improve tree-shaking by removing TypeScript enum and namespace
|
|
36
|
+
- Updated dependencies [53688d3]
|
|
37
|
+
- @yume-chan/no-data-view@1.0.1
|
|
26
38
|
|
|
27
39
|
This log was last generated on Tue, 18 Jun 2024 02:49:43 GMT and should not be manually modified.
|
|
28
40
|
|
|
@@ -32,7 +44,7 @@ Tue, 18 Jun 2024 02:49:43 GMT
|
|
|
32
44
|
|
|
33
45
|
### Updates
|
|
34
46
|
|
|
35
|
-
-
|
|
47
|
+
- Rename some internal types to make them more distinguishable
|
|
36
48
|
|
|
37
49
|
## 0.0.23
|
|
38
50
|
|
|
@@ -58,10 +70,10 @@ Mon, 05 Jun 2023 02:51:41 GMT
|
|
|
58
70
|
|
|
59
71
|
### Updates
|
|
60
72
|
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
73
|
+
- Rename `StructDeserializeStream` and `StructAsyncDeserializeStream` to `ExactReadable` and `AsyncExactReadable`. Rename its `read` method to `readExactly`. Add a `position` field so the caller can check how many bytes have been read.
|
|
74
|
+
- Improve performance for decoding integers.
|
|
75
|
+
- Rename `Struct#fields` to `Struct#concat`. Now `Struct#fields` returns an array of `[name: PropertyKey, definition: StructFieldDefinition<any, any, any>]` tuples.
|
|
76
|
+
- Use ECMAScript private class fields syntax (supported by Chrome 74, Firefox 90, Safari 14.1 and Node.js 12.0.0).
|
|
65
77
|
|
|
66
78
|
## 0.0.19
|
|
67
79
|
|
|
@@ -75,7 +87,7 @@ Wed, 25 Jan 2023 21:33:49 GMT
|
|
|
75
87
|
|
|
76
88
|
### Updates
|
|
77
89
|
|
|
78
|
-
-
|
|
90
|
+
- Refactor number types for easier extending (see `ScrcpyFloatToInt16FieldDefinition` for an example)
|
|
79
91
|
|
|
80
92
|
## 0.0.17
|
|
81
93
|
|
|
@@ -89,10 +101,10 @@ Sat, 28 May 2022 03:56:37 GMT
|
|
|
89
101
|
|
|
90
102
|
### Updates
|
|
91
103
|
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
-
|
|
104
|
+
- Add support for custom TypeScript type for `uint8Array`
|
|
105
|
+
- Upgrade TypeScript to 4.7.2 to enable Node.js ESM
|
|
106
|
+
- Improve performance of `Struct#deserialize()` by up to 200%.
|
|
107
|
+
- Remove `SyncBird`, it's replaced by `SyncPromise`, which is based on native Promise and is 200% faster.
|
|
96
108
|
|
|
97
109
|
## 0.0.15
|
|
98
110
|
|
|
@@ -112,8 +124,8 @@ Thu, 28 Apr 2022 01:23:53 GMT
|
|
|
112
124
|
|
|
113
125
|
### Updates
|
|
114
126
|
|
|
115
|
-
-
|
|
116
|
-
-
|
|
127
|
+
- Fix an issue that `uint64` still deserialize to negative numbers
|
|
128
|
+
- Fix an issue where `Syncbird` can't synchronously invoke `then` on some Bluebird internal methods (for example `reduce`)
|
|
117
129
|
|
|
118
130
|
## 0.0.12
|
|
119
131
|
|
|
@@ -127,10 +139,10 @@ Sun, 03 Apr 2022 11:18:11 GMT
|
|
|
127
139
|
|
|
128
140
|
### Updates
|
|
129
141
|
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
-
-
|
|
142
|
+
- Update to use Web Streams API
|
|
143
|
+
- Improve compatibility with Node.js 12 ESM format
|
|
144
|
+
- Update compatibility matrix
|
|
145
|
+
- Update license year
|
|
134
146
|
|
|
135
147
|
## 0.0.10
|
|
136
148
|
|
|
@@ -138,7 +150,7 @@ Sun, 09 Jan 2022 15:52:20 GMT
|
|
|
138
150
|
|
|
139
151
|
### Updates
|
|
140
152
|
|
|
141
|
-
-
|
|
153
|
+
- Add synchronized deserialize support
|
|
142
154
|
|
|
143
155
|
## 0.0.9
|
|
144
156
|
|
package/esm/buffer.d.ts
CHANGED
|
@@ -7,24 +7,69 @@ export interface Converter<From, To> {
|
|
|
7
7
|
export interface BufferLengthConverter<K, KT> extends Converter<KT, number> {
|
|
8
8
|
field: K;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
declare function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export
|
|
10
|
+
/**
|
|
11
|
+
* Create a fixed-length `Uint8Array` field.
|
|
12
|
+
*
|
|
13
|
+
* @param length Length of the field
|
|
14
|
+
*/
|
|
15
|
+
export declare function buffer(length: number): Field<Uint8Array, never, never, Uint8Array>;
|
|
16
|
+
/**
|
|
17
|
+
* Create a custom-typed field, backed by a fixed-length `Uint8Array`.
|
|
18
|
+
*
|
|
19
|
+
* @param length Length of the field
|
|
20
|
+
* @param converter A value converter to convert between `Uint8Array` and the target type
|
|
21
|
+
*/
|
|
22
|
+
export declare function buffer<U>(length: number, converter: Converter<Uint8Array, U>): Field<U, never, never, Uint8Array>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a variable-length `Uint8Array` field.
|
|
25
|
+
* The length is determined by another number-typed field.
|
|
26
|
+
*
|
|
27
|
+
* @param lengthField Name of the length field. Must be declared before this field
|
|
28
|
+
*/
|
|
29
|
+
export declare function buffer<K extends string>(lengthField: K): Field<Uint8Array, K, Record<K, number>, Uint8Array>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a custom-typed field, backed by a variable-length `Uint8Array`.
|
|
32
|
+
* The length is determined by another number-typed field.
|
|
33
|
+
*
|
|
34
|
+
* @param lengthField Name of the length field. Must be declared before this field
|
|
35
|
+
* @param converter A value converter to convert between `Uint8Array` and the target type
|
|
36
|
+
*/
|
|
37
|
+
export declare function buffer<K extends string, U>(lengthField: K, converter: Converter<Uint8Array, U>): Field<U, K, Record<K, number>, Uint8Array>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a variable-length `Uint8Array` field.
|
|
40
|
+
* The length is determined by converting another field to `number`.
|
|
41
|
+
*
|
|
42
|
+
* @param length
|
|
43
|
+
* Name of the length field,
|
|
44
|
+
* and a converter to convert between source type and `number`.
|
|
45
|
+
* Must be declared before this field
|
|
46
|
+
*/
|
|
47
|
+
export declare function buffer<K extends string, KT>(length: BufferLengthConverter<K, KT>): Field<Uint8Array, K, Record<K, KT>, Uint8Array>;
|
|
48
|
+
/**
|
|
49
|
+
* Create a custom-typed field, backed by a variable-length `Uint8Array`.
|
|
50
|
+
* The length is determined by converting another field to `number`.
|
|
51
|
+
*
|
|
52
|
+
* @param length
|
|
53
|
+
* Name of the length field,
|
|
54
|
+
* and a converter to convert between source type and `number`.
|
|
55
|
+
* Must be declared before this field
|
|
56
|
+
* @param converter
|
|
57
|
+
* A value converter to convert between `Uint8Array` and the target type
|
|
58
|
+
*/
|
|
59
|
+
export declare function buffer<K extends string, KT, U>(length: BufferLengthConverter<K, KT>, converter: Converter<Uint8Array, U>): Field<U, K, Record<K, KT>, Uint8Array>;
|
|
60
|
+
/**
|
|
61
|
+
* Create a length field, and a variable-length `Uint8Array` field.
|
|
62
|
+
* This is a shortcut when the length field is directly before the data field.
|
|
63
|
+
*
|
|
64
|
+
* @param length The length field declaration
|
|
65
|
+
*/
|
|
66
|
+
export declare function buffer<LengthOmitInit extends string, LengthDependencies>(length: Field<number, LengthOmitInit, LengthDependencies, number>): Field<Uint8Array, LengthOmitInit, LengthDependencies, Uint8Array>;
|
|
67
|
+
/**
|
|
68
|
+
* Create a length field, and a custom-typed field, backed by a variable-length `Uint8Array`.
|
|
69
|
+
* This is a shortcut when the length field is directly before the data field.
|
|
70
|
+
*
|
|
71
|
+
* @param length The length field declaration
|
|
72
|
+
* @param converter A value converter to convert between `Uint8Array` and the target type
|
|
73
|
+
*/
|
|
74
|
+
export declare function buffer<LengthOmitInit extends string, LengthDependencies, U>(length: Field<number, LengthOmitInit, LengthDependencies, number>, converter: Converter<Uint8Array, U>): Field<U, LengthOmitInit, LengthDependencies, Uint8Array>;
|
|
30
75
|
//# sourceMappingURL=buffer.d.ts.map
|
package/esm/buffer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,KAAK,EACR,MAAM,kBAAkB,CAAC;AAG1B,eAAO,MAAM,eAAe,yBAAoB,CAAC;AAmBjD,MAAM,WAAW,SAAS,CAAC,IAAI,EAAE,EAAE;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,EAAE,CAAC;IAC7B,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB,CAAC,CAAC,EAAE,EAAE,CAAE,SAAQ,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC;IACvE,KAAK,EAAE,CAAC,CAAC;CACZ;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,GACf,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AAC/C;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,GACpC,KAAK,CAAC,CAAC,EAAE,KAAK,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U,CAAC,CAAC;AACrE;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,cAAc,SAAS,MAAM,EAAE,kBAAkB,EAAE,CAAC,EACvE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,CAAC,EACjE,SAAS,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,GACpC,KAAK,CAAC,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE,UAAU,CAAC,CAAC"}
|
package/esm/buffer.js
CHANGED
|
@@ -1,82 +1,89 @@
|
|
|
1
1
|
import { field } from "./field/index.js";
|
|
2
2
|
export const EmptyUint8Array = new Uint8Array(0);
|
|
3
|
+
function copyMaybeDifferentLength(dest, source, index, length) {
|
|
4
|
+
if (source.length < length) {
|
|
5
|
+
dest.set(source, index);
|
|
6
|
+
// Clear trailing bytes
|
|
7
|
+
dest.fill(0, index + source.length, index + length);
|
|
8
|
+
}
|
|
9
|
+
else if (source.length === length) {
|
|
10
|
+
dest.set(source, index);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
dest.set(source.subarray(0, length), index);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
3
16
|
/* #__NO_SIDE_EFFECTS__ */
|
|
4
|
-
function
|
|
17
|
+
export function buffer(lengthOrField, converter) {
|
|
5
18
|
// Fixed length
|
|
6
19
|
if (typeof lengthOrField === "number") {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
20
|
+
let serialize;
|
|
21
|
+
let deserialize;
|
|
22
|
+
let init;
|
|
23
|
+
if (lengthOrField === 0) {
|
|
24
|
+
serialize = () => { };
|
|
25
|
+
if (converter) {
|
|
10
26
|
// eslint-disable-next-line require-yield
|
|
11
|
-
function* () {
|
|
27
|
+
deserialize = function* () {
|
|
12
28
|
return converter.convert(EmptyUint8Array);
|
|
13
|
-
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// eslint-disable-next-line require-yield
|
|
33
|
+
deserialize = function* () {
|
|
34
|
+
return EmptyUint8Array;
|
|
35
|
+
};
|
|
14
36
|
}
|
|
15
|
-
return field(0, "byob", (value, { buffer, index }) => {
|
|
16
|
-
buffer.set(value.slice(0, lengthOrField), index);
|
|
17
|
-
}, function* (then, reader) {
|
|
18
|
-
const array = yield* then(reader.readExactly(lengthOrField));
|
|
19
|
-
return converter.convert(array);
|
|
20
|
-
}, {
|
|
21
|
-
init(value) {
|
|
22
|
-
return converter.back(value);
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
37
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
else {
|
|
39
|
+
serialize = (value, { buffer, index }) => copyMaybeDifferentLength(buffer, value, index, lengthOrField);
|
|
40
|
+
if (converter) {
|
|
41
|
+
deserialize = function* (then, reader) {
|
|
42
|
+
const array = reader.readExactly(lengthOrField);
|
|
43
|
+
return converter.convert(yield* then(array));
|
|
44
|
+
};
|
|
45
|
+
init = (value) => converter.back(value);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// eslint-disable-next-line require-yield
|
|
49
|
+
deserialize = function* (_then, reader) {
|
|
50
|
+
const array = reader.readExactly(lengthOrField);
|
|
51
|
+
return array;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
32
54
|
}
|
|
33
|
-
return field(
|
|
34
|
-
buffer.set(value.slice(0, lengthOrField), index);
|
|
35
|
-
},
|
|
36
|
-
// eslint-disable-next-line require-yield
|
|
37
|
-
function* (_then, reader) {
|
|
38
|
-
return reader.readExactly(lengthOrField);
|
|
39
|
-
});
|
|
55
|
+
return field(lengthOrField, "byob", serialize, deserialize, { init });
|
|
40
56
|
}
|
|
41
57
|
// Declare length field
|
|
42
58
|
// Some field types are `function`s
|
|
43
59
|
if ((typeof lengthOrField === "object" ||
|
|
44
60
|
typeof lengthOrField === "function") &&
|
|
45
61
|
"serialize" in lengthOrField) {
|
|
62
|
+
let deserialize;
|
|
63
|
+
let init;
|
|
46
64
|
if (converter) {
|
|
47
|
-
|
|
48
|
-
if (lengthOrField.type === "default") {
|
|
49
|
-
const lengthBuffer = lengthOrField.serialize(value.length, { littleEndian });
|
|
50
|
-
const result = new Uint8Array(lengthBuffer.length + value.length);
|
|
51
|
-
result.set(lengthBuffer, 0);
|
|
52
|
-
result.set(value, lengthBuffer.length);
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const result = new Uint8Array(lengthOrField.size + value.length);
|
|
57
|
-
lengthOrField.serialize(value.length, {
|
|
58
|
-
buffer: result,
|
|
59
|
-
index: 0,
|
|
60
|
-
littleEndian,
|
|
61
|
-
});
|
|
62
|
-
result.set(value, lengthOrField.size);
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
}, function* (then, reader, context) {
|
|
65
|
+
deserialize = function* (then, reader, context) {
|
|
66
66
|
const length = yield* then(lengthOrField.deserialize(reader, context));
|
|
67
|
-
const array =
|
|
68
|
-
return converter.convert(array);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const array = length !== 0 ? reader.readExactly(length) : EmptyUint8Array;
|
|
68
|
+
return converter.convert(yield* then(array));
|
|
69
|
+
};
|
|
70
|
+
init = (value) => converter.back(value);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
deserialize = function* (then, reader, context) {
|
|
74
|
+
const length = yield* then(lengthOrField.deserialize(reader, context));
|
|
75
|
+
const array = length !== 0 ? reader.readExactly(length) : EmptyUint8Array;
|
|
76
|
+
return array;
|
|
77
|
+
};
|
|
74
78
|
}
|
|
75
79
|
return field(lengthOrField.size, "default", (value, { littleEndian }) => {
|
|
76
80
|
if (lengthOrField.type === "default") {
|
|
77
81
|
const lengthBuffer = lengthOrField.serialize(value.length, {
|
|
78
82
|
littleEndian,
|
|
79
83
|
});
|
|
84
|
+
if (value.length === 0) {
|
|
85
|
+
return lengthBuffer;
|
|
86
|
+
}
|
|
80
87
|
const result = new Uint8Array(lengthBuffer.length + value.length);
|
|
81
88
|
result.set(lengthBuffer, 0);
|
|
82
89
|
result.set(value, lengthBuffer.length);
|
|
@@ -92,79 +99,69 @@ function _buffer(lengthOrField, converter) {
|
|
|
92
99
|
result.set(value, lengthOrField.size);
|
|
93
100
|
return result;
|
|
94
101
|
}
|
|
95
|
-
},
|
|
96
|
-
const length = yield* then(lengthOrField.deserialize(reader, context));
|
|
97
|
-
return yield* then(reader.readExactly(length));
|
|
98
|
-
});
|
|
102
|
+
}, deserialize, { init });
|
|
99
103
|
}
|
|
100
|
-
// Reference
|
|
104
|
+
// Reference existing length field
|
|
101
105
|
if (typeof lengthOrField === "string") {
|
|
106
|
+
let deserialize;
|
|
107
|
+
let init;
|
|
102
108
|
if (converter) {
|
|
103
|
-
|
|
109
|
+
deserialize = function* (then, reader, { dependencies }) {
|
|
110
|
+
const length = dependencies[lengthOrField];
|
|
111
|
+
const array = length !== 0 ? reader.readExactly(length) : EmptyUint8Array;
|
|
112
|
+
return converter.convert(yield* then(array));
|
|
113
|
+
};
|
|
114
|
+
init = (value, dependencies) => {
|
|
115
|
+
const array = converter.back(value);
|
|
116
|
+
dependencies[lengthOrField] = array.length;
|
|
117
|
+
return array;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
104
121
|
// eslint-disable-next-line require-yield
|
|
105
|
-
function* (_then, reader, { dependencies }) {
|
|
122
|
+
deserialize = function* (_then, reader, { dependencies }) {
|
|
106
123
|
const length = dependencies[lengthOrField];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return array;
|
|
116
|
-
},
|
|
117
|
-
});
|
|
124
|
+
const array = length !== 0 ? reader.readExactly(length) : EmptyUint8Array;
|
|
125
|
+
return array;
|
|
126
|
+
};
|
|
127
|
+
init = (value, dependencies) => {
|
|
128
|
+
const array = value;
|
|
129
|
+
dependencies[lengthOrField] = array.length;
|
|
130
|
+
return array;
|
|
131
|
+
};
|
|
118
132
|
}
|
|
119
|
-
return field(0, "default", (source) => source,
|
|
120
|
-
// eslint-disable-next-line require-yield
|
|
121
|
-
function* (_then, reader, { dependencies }) {
|
|
122
|
-
const length = dependencies[lengthOrField];
|
|
123
|
-
if (length === 0) {
|
|
124
|
-
return EmptyUint8Array;
|
|
125
|
-
}
|
|
126
|
-
return reader.readExactly(length);
|
|
127
|
-
}, {
|
|
128
|
-
init(value, dependencies) {
|
|
129
|
-
dependencies[lengthOrField] = value.length;
|
|
130
|
-
return undefined;
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
+
return field(0, "default", (source) => source, deserialize, { init });
|
|
133
134
|
}
|
|
134
|
-
|
|
135
|
+
let deserialize;
|
|
136
|
+
let init;
|
|
137
|
+
// Reference existing length field + length converter
|
|
135
138
|
if (converter) {
|
|
136
|
-
|
|
139
|
+
deserialize = function* (then, reader, { dependencies }) {
|
|
140
|
+
const rawLength = dependencies[lengthOrField.field];
|
|
141
|
+
const length = lengthOrField.convert(rawLength);
|
|
142
|
+
const array = length !== 0 ? reader.readExactly(length) : EmptyUint8Array;
|
|
143
|
+
return converter.convert(yield* then(array));
|
|
144
|
+
};
|
|
145
|
+
init = (value, dependencies) => {
|
|
146
|
+
const array = converter.back(value);
|
|
147
|
+
dependencies[lengthOrField.field] = lengthOrField.back(array.length);
|
|
148
|
+
return array;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
137
152
|
// eslint-disable-next-line require-yield
|
|
138
|
-
function* (_then, reader, { dependencies }) {
|
|
153
|
+
deserialize = function* (_then, reader, { dependencies }) {
|
|
139
154
|
const rawLength = dependencies[lengthOrField.field];
|
|
140
155
|
const length = lengthOrField.convert(rawLength);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return array;
|
|
150
|
-
},
|
|
151
|
-
});
|
|
156
|
+
const array = length !== 0 ? reader.readExactly(length) : EmptyUint8Array;
|
|
157
|
+
return array;
|
|
158
|
+
};
|
|
159
|
+
init = (value, dependencies) => {
|
|
160
|
+
const array = value;
|
|
161
|
+
dependencies[lengthOrField.field] = lengthOrField.back(array.length);
|
|
162
|
+
return array;
|
|
163
|
+
};
|
|
152
164
|
}
|
|
153
|
-
return field(0, "default", (source) => source,
|
|
154
|
-
// eslint-disable-next-line require-yield
|
|
155
|
-
function* (_then, reader, { dependencies }) {
|
|
156
|
-
const rawLength = dependencies[lengthOrField.field];
|
|
157
|
-
const length = lengthOrField.convert(rawLength);
|
|
158
|
-
if (length === 0) {
|
|
159
|
-
return EmptyUint8Array;
|
|
160
|
-
}
|
|
161
|
-
return reader.readExactly(length);
|
|
162
|
-
}, {
|
|
163
|
-
init(value, dependencies) {
|
|
164
|
-
dependencies[lengthOrField.field] = lengthOrField.back(value.length);
|
|
165
|
-
return undefined;
|
|
166
|
-
},
|
|
167
|
-
});
|
|
165
|
+
return field(0, "default", (source) => source, deserialize, { init });
|
|
168
166
|
}
|
|
169
|
-
export const buffer = _buffer;
|
|
170
167
|
//# sourceMappingURL=buffer.js.map
|
package/esm/buffer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAEjD,SAAS,wBAAwB,CAC7B,IAAgB,EAChB,MAAkB,EAClB,KAAa,EACb,MAAc;IAEd,IAAI,MAAM,CAAC,MAAM,GA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AS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpC,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,IAAI,CAClD,KAAK,CAAC,MAAM,CACf,CAAC;YACF,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC;IACN,CAAC;SAAM,CAAC;QACJ,yCAAyC;QACzC,WAAW,GAAG,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE;YACpD,MAAM,SAAS,GAAG,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACpD,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,KAAK,GACP,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;YAChE,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC;QACF,IAAI,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;YAC3B,MAAM,KAAK,GAAG,KAAmB,CAAC;YAClC,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,IAAI,CAClD,KAAK,CAAC,MAAM,CACf,CAAC;YACF,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC;IACN,CAAC;IAED,OAAO,KAAK,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
package/esm/field/types.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ export interface FieldSerializer<T> {
|
|
|
15
15
|
}
|
|
16
16
|
export interface Field<T, OmitInit extends string, D, Raw = T> extends FieldSerializer<Raw>, FieldDeserializer<T, D> {
|
|
17
17
|
omitInit: OmitInit | undefined;
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* A function to convert deserialized value back to raw value for serialization.
|
|
20
|
+
*/
|
|
21
|
+
init?(value: T, dependencies: D): Raw;
|
|
19
22
|
}
|
|
20
23
|
export interface FieldDeserializeContext<D> {
|
|
21
24
|
littleEndian: boolean;
|
|
@@ -28,6 +31,9 @@ export interface FieldDeserializer<T, D> {
|
|
|
28
31
|
export interface FieldOptions<T, OmitInit extends string, D, Raw = T> {
|
|
29
32
|
omitInit?: OmitInit;
|
|
30
33
|
dependencies?: D;
|
|
31
|
-
|
|
34
|
+
/**
|
|
35
|
+
* A function to convert deserialized value back to raw value for serialization.
|
|
36
|
+
*/
|
|
37
|
+
init?: ((value: T, dependencies: D) => Raw) | undefined;
|
|
32
38
|
}
|
|
33
39
|
//# sourceMappingURL=types.d.ts.map
|
package/esm/field/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/field/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,WAAW,4BAA4B;IACzC,YAAY,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,yBACb,SAAQ,4BAA4B;IACpC,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAC9B,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IAEb,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,4BAA4B,GAAG,UAAU,CAAC;IACxE,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAAC;CACpE;AAED,MAAM,WAAW,KAAK,CAAC,CAAC,EAAE,QAAQ,SAAS,MAAM,EAA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M,WAAW,uBAAuB,CAAC,CAAC;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,CAAC,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,EAAE,CAAC;IACnC,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3E,WAAW,CACP,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GACpC,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,EAAE,QAAQ,SAAS,MAAM,EAAE,CAAC,EAAE,GAAG,GAAG,CAAC;IAChE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC;CAC3D"}
|
package/esm/struct.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Field, FieldDeserializer } from "./field/index.js";
|
|
2
|
-
import type { StructDeserializer, StructSerializer } from "./types.js";
|
|
2
|
+
import type { StructDeserializer, StructLike, StructSerializer } from "./types.js";
|
|
3
3
|
export type StructField = Field<unknown, string, unknown, unknown> | (StructSerializer<unknown> & StructDeserializer<unknown>);
|
|
4
4
|
export type StructFields = Record<string, StructField>;
|
|
5
5
|
export type FieldsValue<T extends StructFields> = {
|
|
@@ -25,7 +25,7 @@ export interface Struct<Fields extends StructFields, Extra extends Record<Proper
|
|
|
25
25
|
fields: Fields;
|
|
26
26
|
extra: Extra;
|
|
27
27
|
}
|
|
28
|
-
export declare function struct<Fields extends Record<string, Field<unknown, string, Partial<FieldsValue<Fields>>, unknown> |
|
|
28
|
+
export declare function struct<Fields extends Record<string, Field<unknown, string, Partial<FieldsValue<Fields>>, unknown> | StructLike<unknown>>, Extra extends Record<PropertyKey, unknown> | undefined = undefined, PostDeserialize = FieldsValue<Fields> & ExtraToIntersection<Extra>>(fields: Fields, options: {
|
|
29
29
|
littleEndian: boolean;
|
|
30
30
|
extra?: (Extra & ThisType<FieldsValue<Fields>>) | undefined;
|
|
31
31
|
postDeserialize?: ((this: FieldsValue<Fields> & ExtraToIntersection<Extra>, value: FieldsValue<Fields> & ExtraToIntersection<Extra>) => PostDeserialize) | undefined;
|
package/esm/struct.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct.d.ts","sourceRoot":"","sources":["../src/struct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,KAAK,EAIL,iBAAiB,EACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EACR,kBAAkB,
|
|
1
|
+
{"version":3,"file":"struct.d.ts","sourceRoot":"","sources":["../src/struct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,KAAK,EAIL,iBAAiB,EACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EACR,kBAAkB,EAClB,UAAU,EAEV,gBAAgB,EACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,WAAW,GACjB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,GACxC,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAEhE,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAEvD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,YAAY,IAAI;KAC7C,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,iBAAiB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,GAC1D,CAAC,GACD,KAAK;CACd,CAAC;AAEF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