@yume-chan/struct 0.0.18 → 0.0.19
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.json +6 -0
- package/CHANGELOG.md +6 -1
- package/esm/basic/definition.d.ts +43 -43
- package/esm/basic/definition.d.ts.map +1 -1
- package/esm/basic/definition.js +23 -23
- package/esm/basic/field-value.d.ts +38 -38
- package/esm/basic/field-value.d.ts.map +1 -1
- package/esm/basic/field-value.js +45 -45
- package/esm/basic/index.d.ts +5 -5
- package/esm/basic/index.js +5 -5
- package/esm/basic/options.d.ts +9 -9
- package/esm/basic/options.js +3 -3
- package/esm/basic/stream.d.ts +19 -19
- package/esm/basic/stream.d.ts.map +1 -1
- package/esm/basic/stream.js +1 -1
- package/esm/basic/struct-value.d.ts +25 -25
- package/esm/basic/struct-value.d.ts.map +1 -1
- package/esm/basic/struct-value.js +56 -56
- package/esm/index.d.ts +13 -13
- package/esm/index.js +5 -5
- package/esm/struct.d.ts +130 -129
- package/esm/struct.d.ts.map +1 -1
- package/esm/struct.js +210 -210
- package/esm/struct.js.map +1 -1
- package/esm/sync-promise.d.ts +12 -12
- package/esm/sync-promise.js +70 -70
- package/esm/types/bigint.d.ts +25 -24
- package/esm/types/bigint.d.ts.map +1 -1
- package/esm/types/bigint.js +47 -46
- package/esm/types/bigint.js.map +1 -1
- package/esm/types/buffer/base.d.ts +64 -63
- package/esm/types/buffer/base.d.ts.map +1 -1
- package/esm/types/buffer/base.js +102 -100
- package/esm/types/buffer/base.js.map +1 -1
- package/esm/types/buffer/fixed-length.d.ts +8 -7
- package/esm/types/buffer/fixed-length.d.ts.map +1 -1
- package/esm/types/buffer/fixed-length.js +6 -6
- package/esm/types/buffer/fixed-length.js.map +1 -1
- package/esm/types/buffer/index.d.ts +3 -3
- package/esm/types/buffer/index.js +3 -3
- package/esm/types/buffer/variable-length.d.ts +44 -42
- package/esm/types/buffer/variable-length.d.ts.map +1 -1
- package/esm/types/buffer/variable-length.js +75 -75
- package/esm/types/buffer/variable-length.js.map +1 -1
- package/esm/types/index.d.ts +3 -3
- package/esm/types/index.js +3 -3
- package/esm/types/number.d.ts +27 -26
- package/esm/types/number.d.ts.map +1 -1
- package/esm/types/number.js +113 -113
- package/esm/types/number.js.map +1 -1
- package/esm/utils.d.ts +47 -47
- package/esm/utils.js +15 -15
- package/package.json +7 -6
- package/src/basic/definition.ts +6 -6
- package/src/basic/field-value.ts +3 -3
- package/src/basic/index.ts +5 -5
- package/src/basic/stream.ts +1 -1
- package/src/basic/struct-value.ts +1 -1
- package/src/index.ts +5 -5
- package/src/struct.ts +14 -15
- package/src/types/bigint.ts +7 -8
- package/src/types/buffer/base.ts +8 -8
- package/src/types/buffer/fixed-length.ts +2 -1
- package/src/types/buffer/variable-length.ts +8 -11
- package/src/types/number.ts +7 -8
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Change Log - @yume-chan/struct
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Sun, 09 Apr 2023 05:55:33 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.0.19
|
|
6
|
+
Sun, 09 Apr 2023 05:55:33 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
4
9
|
|
|
5
10
|
## 0.0.18
|
|
6
11
|
Wed, 25 Jan 2023 21:33:49 GMT
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
/**
|
|
6
|
-
* A field definition defines how to deserialize a field.
|
|
7
|
-
*
|
|
8
|
-
* @template TOptions TypeScript type of this definition's `options`.
|
|
9
|
-
* @template TValue TypeScript type of this field.
|
|
10
|
-
* @template TOmitInitKey Optionally remove some fields from the init type. Should be a union of string literal types.
|
|
11
|
-
*/
|
|
12
|
-
export declare abstract class StructFieldDefinition<TOptions = void, TValue = unknown, TOmitInitKey extends PropertyKey = never> {
|
|
13
|
-
/**
|
|
14
|
-
* When `T` is a type initiated `StructFieldDefinition`,
|
|
15
|
-
* use `T['TValue']` to retrieve its `TValue` type parameter.
|
|
16
|
-
*/
|
|
17
|
-
readonly TValue: TValue;
|
|
18
|
-
/**
|
|
19
|
-
* When `T` is a type initiated `StructFieldDefinition`,
|
|
20
|
-
* use `T['TOmitInitKey']` to retrieve its `TOmitInitKey` type parameter.
|
|
21
|
-
*/
|
|
22
|
-
readonly TOmitInitKey: TOmitInitKey;
|
|
23
|
-
readonly options: TOptions;
|
|
24
|
-
constructor(options: TOptions);
|
|
25
|
-
/**
|
|
26
|
-
* When implemented in derived classes, returns the size (or minimal size if it's dynamic) of this field.
|
|
27
|
-
*
|
|
28
|
-
* Actual size can be retrieved from `StructFieldValue#getSize`
|
|
29
|
-
*/
|
|
30
|
-
abstract getSize(): number;
|
|
31
|
-
/**
|
|
32
|
-
* When implemented in derived classes, creates a `StructFieldValue` from a given `value`.
|
|
33
|
-
*/
|
|
34
|
-
abstract create(options: Readonly<StructOptions>, structValue: StructValue, value: TValue): StructFieldValue<this>;
|
|
35
|
-
/**
|
|
36
|
-
* When implemented in derived classes,It must be synchronous (returns a value) or asynchronous (returns a `Promise`) depending
|
|
37
|
-
* on the type of `stream`. reads and creates a `StructFieldValue` from `stream`.
|
|
38
|
-
*
|
|
39
|
-
* `SyncPromise` can be used to simplify implementation.
|
|
40
|
-
*/
|
|
41
|
-
abstract deserialize(options: Readonly<StructOptions>, stream: StructDeserializeStream, structValue: StructValue): StructFieldValue<this>;
|
|
42
|
-
abstract deserialize(options: Readonly<StructOptions>, stream: StructAsyncDeserializeStream, struct: StructValue): Promise<StructFieldValue<this>>;
|
|
43
|
-
}
|
|
1
|
+
import type { StructFieldValue } from "./field-value.js";
|
|
2
|
+
import type { StructOptions } from "./options.js";
|
|
3
|
+
import type { StructAsyncDeserializeStream, StructDeserializeStream } from "./stream.js";
|
|
4
|
+
import type { StructValue } from "./struct-value.js";
|
|
5
|
+
/**
|
|
6
|
+
* A field definition defines how to deserialize a field.
|
|
7
|
+
*
|
|
8
|
+
* @template TOptions TypeScript type of this definition's `options`.
|
|
9
|
+
* @template TValue TypeScript type of this field.
|
|
10
|
+
* @template TOmitInitKey Optionally remove some fields from the init type. Should be a union of string literal types.
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class StructFieldDefinition<TOptions = void, TValue = unknown, TOmitInitKey extends PropertyKey = never> {
|
|
13
|
+
/**
|
|
14
|
+
* When `T` is a type initiated `StructFieldDefinition`,
|
|
15
|
+
* use `T['TValue']` to retrieve its `TValue` type parameter.
|
|
16
|
+
*/
|
|
17
|
+
readonly TValue: TValue;
|
|
18
|
+
/**
|
|
19
|
+
* When `T` is a type initiated `StructFieldDefinition`,
|
|
20
|
+
* use `T['TOmitInitKey']` to retrieve its `TOmitInitKey` type parameter.
|
|
21
|
+
*/
|
|
22
|
+
readonly TOmitInitKey: TOmitInitKey;
|
|
23
|
+
readonly options: TOptions;
|
|
24
|
+
constructor(options: TOptions);
|
|
25
|
+
/**
|
|
26
|
+
* When implemented in derived classes, returns the size (or minimal size if it's dynamic) of this field.
|
|
27
|
+
*
|
|
28
|
+
* Actual size can be retrieved from `StructFieldValue#getSize`
|
|
29
|
+
*/
|
|
30
|
+
abstract getSize(): number;
|
|
31
|
+
/**
|
|
32
|
+
* When implemented in derived classes, creates a `StructFieldValue` from a given `value`.
|
|
33
|
+
*/
|
|
34
|
+
abstract create(options: Readonly<StructOptions>, structValue: StructValue, value: TValue): StructFieldValue<this>;
|
|
35
|
+
/**
|
|
36
|
+
* When implemented in derived classes,It must be synchronous (returns a value) or asynchronous (returns a `Promise`) depending
|
|
37
|
+
* on the type of `stream`. reads and creates a `StructFieldValue` from `stream`.
|
|
38
|
+
*
|
|
39
|
+
* `SyncPromise` can be used to simplify implementation.
|
|
40
|
+
*/
|
|
41
|
+
abstract deserialize(options: Readonly<StructOptions>, stream: StructDeserializeStream, structValue: StructValue): StructFieldValue<this>;
|
|
42
|
+
abstract deserialize(options: Readonly<StructOptions>, stream: StructAsyncDeserializeStream, struct: StructValue): Promise<StructFieldValue<this>>;
|
|
43
|
+
}
|
|
44
44
|
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/basic/definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/basic/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACR,4BAA4B,EAC5B,uBAAuB,EAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;GAMG;AACH,8BAAsB,qBAAqB,CACvC,QAAQ,GAAG,IAAI,EACf,MAAM,GAAG,OAAO,EAChB,YAAY,SAAS,WAAW,GAAG,KAAK;IAExC;;;OAGG;IACH,SAAgB,MAAM,EAAG,MAAM,CAAC;IAEhC;;;OAGG;IACH,SAAgB,YAAY,EAAG,YAAY,CAAC;IAE5C,SAAgB,OAAO,EAAE,QAAQ,CAAC;gBAEf,OAAO,EAAE,QAAQ;IAIpC;;;;OAIG;aACa,OAAO,IAAI,MAAM;IAEjC;;OAEG;aACa,MAAM,CAClB,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,EAChC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,MAAM,GACd,gBAAgB,CAAC,IAAI,CAAC;IAEzB;;;;;OAKG;aACa,WAAW,CACvB,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,EAChC,MAAM,EAAE,uBAAuB,EAC/B,WAAW,EAAE,WAAW,GACzB,gBAAgB,CAAC,IAAI,CAAC;aACT,WAAW,CACvB,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,EAChC,MAAM,EAAE,4BAA4B,EACpC,MAAM,EAAE,WAAW,GACpB,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;CACrC"}
|
package/esm/basic/definition.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A field definition defines how to deserialize a field.
|
|
3
|
-
*
|
|
4
|
-
* @template TOptions TypeScript type of this definition's `options`.
|
|
5
|
-
* @template TValue TypeScript type of this field.
|
|
6
|
-
* @template TOmitInitKey Optionally remove some fields from the init type. Should be a union of string literal types.
|
|
7
|
-
*/
|
|
8
|
-
export class StructFieldDefinition {
|
|
9
|
-
/**
|
|
10
|
-
* When `T` is a type initiated `StructFieldDefinition`,
|
|
11
|
-
* use `T['TValue']` to retrieve its `TValue` type parameter.
|
|
12
|
-
*/
|
|
13
|
-
TValue;
|
|
14
|
-
/**
|
|
15
|
-
* When `T` is a type initiated `StructFieldDefinition`,
|
|
16
|
-
* use `T['TOmitInitKey']` to retrieve its `TOmitInitKey` type parameter.
|
|
17
|
-
*/
|
|
18
|
-
TOmitInitKey;
|
|
19
|
-
options;
|
|
20
|
-
constructor(options) {
|
|
21
|
-
this.options = options;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* A field definition defines how to deserialize a field.
|
|
3
|
+
*
|
|
4
|
+
* @template TOptions TypeScript type of this definition's `options`.
|
|
5
|
+
* @template TValue TypeScript type of this field.
|
|
6
|
+
* @template TOmitInitKey Optionally remove some fields from the init type. Should be a union of string literal types.
|
|
7
|
+
*/
|
|
8
|
+
export class StructFieldDefinition {
|
|
9
|
+
/**
|
|
10
|
+
* When `T` is a type initiated `StructFieldDefinition`,
|
|
11
|
+
* use `T['TValue']` to retrieve its `TValue` type parameter.
|
|
12
|
+
*/
|
|
13
|
+
TValue;
|
|
14
|
+
/**
|
|
15
|
+
* When `T` is a type initiated `StructFieldDefinition`,
|
|
16
|
+
* use `T['TOmitInitKey']` to retrieve its `TOmitInitKey` type parameter.
|
|
17
|
+
*/
|
|
18
|
+
TOmitInitKey;
|
|
19
|
+
options;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
24
|
//# sourceMappingURL=definition.js.map
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
/**
|
|
5
|
-
* A field value defines how to serialize a field.
|
|
6
|
-
*
|
|
7
|
-
* It may contains extra metadata about the value which are essential or
|
|
8
|
-
* helpful for the serialization process.
|
|
9
|
-
*/
|
|
10
|
-
export declare abstract class StructFieldValue<TDefinition extends StructFieldDefinition<any, any, any> = StructFieldDefinition<any, any, any>> {
|
|
11
|
-
/** Gets the definition associated with this runtime value */
|
|
12
|
-
readonly definition: TDefinition;
|
|
13
|
-
/** Gets the options of the associated `Struct` */
|
|
14
|
-
readonly options: Readonly<StructOptions>;
|
|
15
|
-
/** Gets the associated `Struct` instance */
|
|
16
|
-
readonly struct: StructValue;
|
|
17
|
-
get hasCustomAccessors(): boolean;
|
|
18
|
-
protected value: TDefinition["TValue"];
|
|
19
|
-
constructor(definition: TDefinition, options: Readonly<StructOptions>, struct: StructValue, value: TDefinition["TValue"]);
|
|
20
|
-
/**
|
|
21
|
-
* Gets size of this field. By default, it returns its `definition`'s size.
|
|
22
|
-
*
|
|
23
|
-
* When overridden in derived classes, can have custom logic to calculate the actual size.
|
|
24
|
-
*/
|
|
25
|
-
getSize(): number;
|
|
26
|
-
/**
|
|
27
|
-
* When implemented in derived classes, reads current field's value.
|
|
28
|
-
*/
|
|
29
|
-
get(): TDefinition["TValue"];
|
|
30
|
-
/**
|
|
31
|
-
* When implemented in derived classes, updates current field's value.
|
|
32
|
-
*/
|
|
33
|
-
set(value: TDefinition["TValue"]): void;
|
|
34
|
-
/**
|
|
35
|
-
* When implemented in derived classes, serializes this field into `dataView` at `offset`
|
|
36
|
-
*/
|
|
37
|
-
abstract serialize(dataView: DataView, offset: number): void;
|
|
38
|
-
}
|
|
1
|
+
import type { StructFieldDefinition } from "./definition.js";
|
|
2
|
+
import type { StructOptions } from "./options.js";
|
|
3
|
+
import type { StructValue } from "./struct-value.js";
|
|
4
|
+
/**
|
|
5
|
+
* A field value defines how to serialize a field.
|
|
6
|
+
*
|
|
7
|
+
* It may contains extra metadata about the value which are essential or
|
|
8
|
+
* helpful for the serialization process.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class StructFieldValue<TDefinition extends StructFieldDefinition<any, any, any> = StructFieldDefinition<any, any, any>> {
|
|
11
|
+
/** Gets the definition associated with this runtime value */
|
|
12
|
+
readonly definition: TDefinition;
|
|
13
|
+
/** Gets the options of the associated `Struct` */
|
|
14
|
+
readonly options: Readonly<StructOptions>;
|
|
15
|
+
/** Gets the associated `Struct` instance */
|
|
16
|
+
readonly struct: StructValue;
|
|
17
|
+
get hasCustomAccessors(): boolean;
|
|
18
|
+
protected value: TDefinition["TValue"];
|
|
19
|
+
constructor(definition: TDefinition, options: Readonly<StructOptions>, struct: StructValue, value: TDefinition["TValue"]);
|
|
20
|
+
/**
|
|
21
|
+
* Gets size of this field. By default, it returns its `definition`'s size.
|
|
22
|
+
*
|
|
23
|
+
* When overridden in derived classes, can have custom logic to calculate the actual size.
|
|
24
|
+
*/
|
|
25
|
+
getSize(): number;
|
|
26
|
+
/**
|
|
27
|
+
* When implemented in derived classes, reads current field's value.
|
|
28
|
+
*/
|
|
29
|
+
get(): TDefinition["TValue"];
|
|
30
|
+
/**
|
|
31
|
+
* When implemented in derived classes, updates current field's value.
|
|
32
|
+
*/
|
|
33
|
+
set(value: TDefinition["TValue"]): void;
|
|
34
|
+
/**
|
|
35
|
+
* When implemented in derived classes, serializes this field into `dataView` at `offset`
|
|
36
|
+
*/
|
|
37
|
+
abstract serialize(dataView: DataView, offset: number): void;
|
|
38
|
+
}
|
|
39
39
|
//# sourceMappingURL=field-value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-value.d.ts","sourceRoot":"","sources":["../../src/basic/field-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"field-value.d.ts","sourceRoot":"","sources":["../../src/basic/field-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;GAKG;AACH,8BAAsB,gBAAgB,CAClC,WAAW,SAAS,qBAAqB,CACrC,GAAG,EACH,GAAG,EACH,GAAG,CACN,GAAG,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAExC,6DAA6D;IAC7D,SAAgB,UAAU,EAAE,WAAW,CAAC;IAExC,kDAAkD;IAClD,SAAgB,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEjD,4CAA4C;IAC5C,SAAgB,MAAM,EAAE,WAAW,CAAC;IAEpC,IAAW,kBAAkB,IAAI,OAAO,CAKvC;IAED,SAAS,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;gBAGnC,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,EAChC,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC;IAQhC;;;;OAIG;IACI,OAAO,IAAI,MAAM;IAIxB;;OAEG;IACI,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC;IAInC;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,IAAI;IAI9C;;OAEG;aACa,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CACtE"}
|
package/esm/basic/field-value.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A field value defines how to serialize a field.
|
|
3
|
-
*
|
|
4
|
-
* It may contains extra metadata about the value which are essential or
|
|
5
|
-
* helpful for the serialization process.
|
|
6
|
-
*/
|
|
7
|
-
export class StructFieldValue {
|
|
8
|
-
/** Gets the definition associated with this runtime value */
|
|
9
|
-
definition;
|
|
10
|
-
/** Gets the options of the associated `Struct` */
|
|
11
|
-
options;
|
|
12
|
-
/** Gets the associated `Struct` instance */
|
|
13
|
-
struct;
|
|
14
|
-
get hasCustomAccessors() {
|
|
15
|
-
return (this.get !== StructFieldValue.prototype.get ||
|
|
16
|
-
this.set !== StructFieldValue.prototype.set);
|
|
17
|
-
}
|
|
18
|
-
value;
|
|
19
|
-
constructor(definition, options, struct, value) {
|
|
20
|
-
this.definition = definition;
|
|
21
|
-
this.options = options;
|
|
22
|
-
this.struct = struct;
|
|
23
|
-
this.value = value;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Gets size of this field. By default, it returns its `definition`'s size.
|
|
27
|
-
*
|
|
28
|
-
* When overridden in derived classes, can have custom logic to calculate the actual size.
|
|
29
|
-
*/
|
|
30
|
-
getSize() {
|
|
31
|
-
return this.definition.getSize();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* When implemented in derived classes, reads current field's value.
|
|
35
|
-
*/
|
|
36
|
-
get() {
|
|
37
|
-
return this.value;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* When implemented in derived classes, updates current field's value.
|
|
41
|
-
*/
|
|
42
|
-
set(value) {
|
|
43
|
-
this.value = value;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* A field value defines how to serialize a field.
|
|
3
|
+
*
|
|
4
|
+
* It may contains extra metadata about the value which are essential or
|
|
5
|
+
* helpful for the serialization process.
|
|
6
|
+
*/
|
|
7
|
+
export class StructFieldValue {
|
|
8
|
+
/** Gets the definition associated with this runtime value */
|
|
9
|
+
definition;
|
|
10
|
+
/** Gets the options of the associated `Struct` */
|
|
11
|
+
options;
|
|
12
|
+
/** Gets the associated `Struct` instance */
|
|
13
|
+
struct;
|
|
14
|
+
get hasCustomAccessors() {
|
|
15
|
+
return (this.get !== StructFieldValue.prototype.get ||
|
|
16
|
+
this.set !== StructFieldValue.prototype.set);
|
|
17
|
+
}
|
|
18
|
+
value;
|
|
19
|
+
constructor(definition, options, struct, value) {
|
|
20
|
+
this.definition = definition;
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.struct = struct;
|
|
23
|
+
this.value = value;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets size of this field. By default, it returns its `definition`'s size.
|
|
27
|
+
*
|
|
28
|
+
* When overridden in derived classes, can have custom logic to calculate the actual size.
|
|
29
|
+
*/
|
|
30
|
+
getSize() {
|
|
31
|
+
return this.definition.getSize();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* When implemented in derived classes, reads current field's value.
|
|
35
|
+
*/
|
|
36
|
+
get() {
|
|
37
|
+
return this.value;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* When implemented in derived classes, updates current field's value.
|
|
41
|
+
*/
|
|
42
|
+
set(value) {
|
|
43
|
+
this.value = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
46
|
//# sourceMappingURL=field-value.js.map
|
package/esm/basic/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./definition.js";
|
|
2
|
+
export * from "./field-value.js";
|
|
3
|
+
export * from "./options.js";
|
|
4
|
+
export * from "./stream.js";
|
|
5
|
+
export * from "./struct-value.js";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/basic/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./definition.js";
|
|
2
|
+
export * from "./field-value.js";
|
|
3
|
+
export * from "./options.js";
|
|
4
|
+
export * from "./stream.js";
|
|
5
|
+
export * from "./struct-value.js";
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/esm/basic/options.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export interface StructOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Whether all multi-byte fields in this struct are little-endian encoded.
|
|
4
|
-
*
|
|
5
|
-
* @default false
|
|
6
|
-
*/
|
|
7
|
-
littleEndian: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare const StructDefaultOptions: Readonly<StructOptions>;
|
|
1
|
+
export interface StructOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Whether all multi-byte fields in this struct are little-endian encoded.
|
|
4
|
+
*
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
littleEndian: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const StructDefaultOptions: Readonly<StructOptions>;
|
|
10
10
|
//# sourceMappingURL=options.d.ts.map
|
package/esm/basic/options.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const StructDefaultOptions = {
|
|
2
|
-
littleEndian: false,
|
|
3
|
-
};
|
|
1
|
+
export const StructDefaultOptions = {
|
|
2
|
+
littleEndian: false,
|
|
3
|
+
};
|
|
4
4
|
//# sourceMappingURL=options.js.map
|
package/esm/basic/stream.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface StructDeserializeStream {
|
|
3
|
-
/**
|
|
4
|
-
* Read data from the underlying data source.
|
|
5
|
-
*
|
|
6
|
-
* The stream must return exactly `length` bytes or data. If that's not possible
|
|
7
|
-
* (due to end of file or other error condition), it must throw an error.
|
|
8
|
-
*/
|
|
9
|
-
read(length: number): Uint8Array;
|
|
10
|
-
}
|
|
11
|
-
export interface StructAsyncDeserializeStream {
|
|
12
|
-
/**
|
|
13
|
-
* Read data from the underlying data source.
|
|
14
|
-
*
|
|
15
|
-
* The stream must return exactly `length` bytes or data. If that's not possible
|
|
16
|
-
* (due to end of file or other error condition), it must throw an error.
|
|
17
|
-
*/
|
|
18
|
-
read(length: number): ValueOrPromise<Uint8Array>;
|
|
19
|
-
}
|
|
1
|
+
import type { ValueOrPromise } from "../utils.js";
|
|
2
|
+
export interface StructDeserializeStream {
|
|
3
|
+
/**
|
|
4
|
+
* Read data from the underlying data source.
|
|
5
|
+
*
|
|
6
|
+
* The stream must return exactly `length` bytes or data. If that's not possible
|
|
7
|
+
* (due to end of file or other error condition), it must throw an error.
|
|
8
|
+
*/
|
|
9
|
+
read(length: number): Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
export interface StructAsyncDeserializeStream {
|
|
12
|
+
/**
|
|
13
|
+
* Read data from the underlying data source.
|
|
14
|
+
*
|
|
15
|
+
* The stream must return exactly `length` bytes or data. If that's not possible
|
|
16
|
+
* (due to end of file or other error condition), it must throw an error.
|
|
17
|
+
*/
|
|
18
|
+
read(length: number): ValueOrPromise<Uint8Array>;
|
|
19
|
+
}
|
|
20
20
|
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/basic/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/basic/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD,MAAM,WAAW,uBAAuB;IACpC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;CACpC;AAED,MAAM,WAAW,4BAA4B;IACzC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;CACpD"}
|
package/esm/basic/stream.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=stream.js.map
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const STRUCT_VALUE_SYMBOL: unique symbol;
|
|
3
|
-
/**
|
|
4
|
-
* A struct value is a map between keys in a struct and their field values.
|
|
5
|
-
*/
|
|
6
|
-
export declare class StructValue {
|
|
7
|
-
/**
|
|
8
|
-
* Gets the result struct value object
|
|
9
|
-
*/
|
|
10
|
-
readonly value: Record<PropertyKey, unknown>;
|
|
11
|
-
constructor(prototype: object);
|
|
12
|
-
/**
|
|
13
|
-
* Sets a `StructFieldValue` for `key`
|
|
14
|
-
*
|
|
15
|
-
* @param name The field name
|
|
16
|
-
* @param fieldValue The associated `StructFieldValue`
|
|
17
|
-
*/
|
|
18
|
-
set(name: PropertyKey, fieldValue: StructFieldValue): void;
|
|
19
|
-
/**
|
|
20
|
-
* Gets the `StructFieldValue` for `key`
|
|
21
|
-
*
|
|
22
|
-
* @param name The field name
|
|
23
|
-
*/
|
|
24
|
-
get(name: PropertyKey): StructFieldValue;
|
|
25
|
-
}
|
|
1
|
+
import type { StructFieldValue } from "./field-value.js";
|
|
2
|
+
export declare const STRUCT_VALUE_SYMBOL: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* A struct value is a map between keys in a struct and their field values.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StructValue {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the result struct value object
|
|
9
|
+
*/
|
|
10
|
+
readonly value: Record<PropertyKey, unknown>;
|
|
11
|
+
constructor(prototype: object);
|
|
12
|
+
/**
|
|
13
|
+
* Sets a `StructFieldValue` for `key`
|
|
14
|
+
*
|
|
15
|
+
* @param name The field name
|
|
16
|
+
* @param fieldValue The associated `StructFieldValue`
|
|
17
|
+
*/
|
|
18
|
+
set(name: PropertyKey, fieldValue: StructFieldValue): void;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the `StructFieldValue` for `key`
|
|
21
|
+
*
|
|
22
|
+
* @param name The field name
|
|
23
|
+
*/
|
|
24
|
+
get(name: PropertyKey): StructFieldValue;
|
|
25
|
+
}
|
|
26
26
|
//# sourceMappingURL=struct-value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct-value.d.ts","sourceRoot":"","sources":["../../src/basic/struct-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"struct-value.d.ts","sourceRoot":"","sources":["../../src/basic/struct-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,eAAO,MAAM,mBAAmB,eAAyB,CAAC;AAE1D;;GAEG;AACH,qBAAa,WAAW;IAMpB;;OAEG;IACH,SAAgB,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBAEjC,SAAS,EAAE,MAAM;IAapC;;;;;OAKG;IACI,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,gBAAgB,GAAG,IAAI;IAqBjE;;;;OAIG;IACI,GAAG,CAAC,IAAI,EAAE,WAAW,GAAG,gBAAgB;CAGlD"}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
export const STRUCT_VALUE_SYMBOL = Symbol("struct-value");
|
|
2
|
-
/**
|
|
3
|
-
* A struct value is a map between keys in a struct and their field values.
|
|
4
|
-
*/
|
|
5
|
-
export class StructValue {
|
|
6
|
-
/** @internal */ fieldValues = {};
|
|
7
|
-
/**
|
|
8
|
-
* Gets the result struct value object
|
|
9
|
-
*/
|
|
10
|
-
value;
|
|
11
|
-
constructor(prototype) {
|
|
12
|
-
// PERF: `Object.create(extra)` is 50% faster
|
|
13
|
-
// than `Object.defineProperties(this.value, extra)`
|
|
14
|
-
this.value = Object.create(prototype);
|
|
15
|
-
// PERF: `Object.defineProperty` is slow
|
|
16
|
-
// but we need it to be non-enumerable
|
|
17
|
-
Object.defineProperty(this.value, STRUCT_VALUE_SYMBOL, {
|
|
18
|
-
enumerable: false,
|
|
19
|
-
value: this,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Sets a `StructFieldValue` for `key`
|
|
24
|
-
*
|
|
25
|
-
* @param name The field name
|
|
26
|
-
* @param fieldValue The associated `StructFieldValue`
|
|
27
|
-
*/
|
|
28
|
-
set(name, fieldValue) {
|
|
29
|
-
this.fieldValues[name] = fieldValue;
|
|
30
|
-
// PERF: `Object.defineProperty` is slow
|
|
31
|
-
// use normal property when possible
|
|
32
|
-
if (fieldValue.hasCustomAccessors) {
|
|
33
|
-
Object.defineProperty(this.value, name, {
|
|
34
|
-
configurable: true,
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get() {
|
|
37
|
-
return fieldValue.get();
|
|
38
|
-
},
|
|
39
|
-
set(v) {
|
|
40
|
-
fieldValue.set(v);
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.value[name] = fieldValue.get();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Gets the `StructFieldValue` for `key`
|
|
50
|
-
*
|
|
51
|
-
* @param name The field name
|
|
52
|
-
*/
|
|
53
|
-
get(name) {
|
|
54
|
-
return this.fieldValues[name];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
export const STRUCT_VALUE_SYMBOL = Symbol("struct-value");
|
|
2
|
+
/**
|
|
3
|
+
* A struct value is a map between keys in a struct and their field values.
|
|
4
|
+
*/
|
|
5
|
+
export class StructValue {
|
|
6
|
+
/** @internal */ fieldValues = {};
|
|
7
|
+
/**
|
|
8
|
+
* Gets the result struct value object
|
|
9
|
+
*/
|
|
10
|
+
value;
|
|
11
|
+
constructor(prototype) {
|
|
12
|
+
// PERF: `Object.create(extra)` is 50% faster
|
|
13
|
+
// than `Object.defineProperties(this.value, extra)`
|
|
14
|
+
this.value = Object.create(prototype);
|
|
15
|
+
// PERF: `Object.defineProperty` is slow
|
|
16
|
+
// but we need it to be non-enumerable
|
|
17
|
+
Object.defineProperty(this.value, STRUCT_VALUE_SYMBOL, {
|
|
18
|
+
enumerable: false,
|
|
19
|
+
value: this,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets a `StructFieldValue` for `key`
|
|
24
|
+
*
|
|
25
|
+
* @param name The field name
|
|
26
|
+
* @param fieldValue The associated `StructFieldValue`
|
|
27
|
+
*/
|
|
28
|
+
set(name, fieldValue) {
|
|
29
|
+
this.fieldValues[name] = fieldValue;
|
|
30
|
+
// PERF: `Object.defineProperty` is slow
|
|
31
|
+
// use normal property when possible
|
|
32
|
+
if (fieldValue.hasCustomAccessors) {
|
|
33
|
+
Object.defineProperty(this.value, name, {
|
|
34
|
+
configurable: true,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get() {
|
|
37
|
+
return fieldValue.get();
|
|
38
|
+
},
|
|
39
|
+
set(v) {
|
|
40
|
+
fieldValue.set(v);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.value[name] = fieldValue.get();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the `StructFieldValue` for `key`
|
|
50
|
+
*
|
|
51
|
+
* @param name The field name
|
|
52
|
+
*/
|
|
53
|
+
get(name) {
|
|
54
|
+
return this.fieldValues[name];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
57
|
//# sourceMappingURL=struct-value.js.map
|