@yume-chan/struct 0.0.23 → 1.0.0
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 -2
- package/LICENSE +1 -1
- package/README.md +85 -714
- package/esm/bipedal.d.ts +5 -0
- package/esm/bipedal.d.ts.map +1 -0
- package/esm/bipedal.js +31 -0
- package/esm/bipedal.js.map +1 -0
- package/esm/buffer.d.ts +21 -0
- package/esm/buffer.d.ts.map +1 -0
- package/esm/buffer.js +173 -0
- package/esm/buffer.js.map +1 -0
- package/esm/field.d.ts +21 -0
- package/esm/field.d.ts.map +1 -0
- package/esm/field.js +2 -0
- package/esm/field.js.map +1 -0
- package/esm/index.d.ts +6 -4
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +6 -4
- package/esm/index.js.map +1 -1
- package/esm/number.d.ts +13 -0
- package/esm/number.d.ts.map +1 -0
- package/esm/number.js +59 -0
- package/esm/number.js.map +1 -0
- package/esm/{basic/stream.d.ts → readable.d.ts} +3 -3
- package/esm/readable.d.ts.map +1 -0
- package/esm/{basic/stream.js → readable.js} +1 -2
- package/esm/readable.js.map +1 -0
- package/esm/string.d.ts +16 -0
- package/esm/string.d.ts.map +1 -0
- package/esm/string.js +14 -0
- package/esm/string.js.map +1 -0
- package/esm/struct.d.ts +24 -127
- package/esm/struct.d.ts.map +1 -1
- package/esm/struct.js +72 -214
- package/esm/struct.js.map +1 -1
- package/esm/utils.d.ts +10 -45
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +12 -11
- package/esm/utils.js.map +1 -1
- package/package.json +11 -14
- package/src/bipedal.ts +55 -0
- package/src/buffer.ts +260 -0
- package/src/field.ts +27 -0
- package/src/index.ts +6 -4
- package/src/number.ts +123 -0
- package/src/{basic/stream.ts → readable.ts} +3 -4
- package/src/string.ts +43 -0
- package/src/struct.ts +156 -628
- package/src/utils.ts +18 -69
- package/tsconfig.build.json +6 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/CHANGELOG.json +0 -161
- package/esm/basic/definition.d.ts +0 -44
- package/esm/basic/definition.d.ts.map +0 -1
- package/esm/basic/definition.js +0 -24
- package/esm/basic/definition.js.map +0 -1
- package/esm/basic/field-value.d.ts +0 -39
- package/esm/basic/field-value.d.ts.map +0 -1
- package/esm/basic/field-value.js +0 -46
- package/esm/basic/field-value.js.map +0 -1
- package/esm/basic/index.d.ts +0 -6
- package/esm/basic/index.d.ts.map +0 -1
- package/esm/basic/index.js +0 -6
- package/esm/basic/index.js.map +0 -1
- package/esm/basic/options.d.ts +0 -10
- package/esm/basic/options.d.ts.map +0 -1
- package/esm/basic/options.js +0 -4
- package/esm/basic/options.js.map +0 -1
- package/esm/basic/stream.d.ts.map +0 -1
- package/esm/basic/stream.js.map +0 -1
- package/esm/basic/struct-value.d.ts +0 -26
- package/esm/basic/struct-value.d.ts.map +0 -1
- package/esm/basic/struct-value.js +0 -57
- package/esm/basic/struct-value.js.map +0 -1
- package/esm/sync-promise.d.ts +0 -13
- package/esm/sync-promise.d.ts.map +0 -1
- package/esm/sync-promise.js +0 -71
- package/esm/sync-promise.js.map +0 -1
- package/esm/types/bigint.d.ts +0 -26
- package/esm/types/bigint.d.ts.map +0 -1
- package/esm/types/bigint.js +0 -47
- package/esm/types/bigint.js.map +0 -1
- package/esm/types/buffer/base.d.ts +0 -65
- package/esm/types/buffer/base.d.ts.map +0 -1
- package/esm/types/buffer/base.js +0 -101
- package/esm/types/buffer/base.js.map +0 -1
- package/esm/types/buffer/fixed-length.d.ts +0 -9
- package/esm/types/buffer/fixed-length.d.ts.map +0 -1
- package/esm/types/buffer/fixed-length.js +0 -7
- package/esm/types/buffer/fixed-length.js.map +0 -1
- package/esm/types/buffer/index.d.ts +0 -4
- package/esm/types/buffer/index.d.ts.map +0 -1
- package/esm/types/buffer/index.js +0 -4
- package/esm/types/buffer/index.js.map +0 -1
- package/esm/types/buffer/variable-length.d.ts +0 -45
- package/esm/types/buffer/variable-length.d.ts.map +0 -1
- package/esm/types/buffer/variable-length.js +0 -76
- package/esm/types/buffer/variable-length.js.map +0 -1
- package/esm/types/index.d.ts +0 -4
- package/esm/types/index.d.ts.map +0 -1
- package/esm/types/index.js +0 -4
- package/esm/types/index.js.map +0 -1
- package/esm/types/number.d.ts +0 -28
- package/esm/types/number.d.ts.map +0 -1
- package/esm/types/number.js +0 -111
- package/esm/types/number.js.map +0 -1
- package/src/basic/definition.ts +0 -68
- package/src/basic/field-value.ts +0 -75
- package/src/basic/index.ts +0 -5
- package/src/basic/options.ts +0 -19
- package/src/basic/struct-value.ts +0 -67
- package/src/sync-promise.ts +0 -134
- package/src/types/bigint.ts +0 -121
- package/src/types/buffer/base.ts +0 -197
- package/src/types/buffer/fixed-length.ts +0 -17
- package/src/types/buffer/index.ts +0 -3
- package/src/types/buffer/variable-length.ts +0 -174
- package/src/types/index.ts +0 -3
- package/src/types/number.ts +0 -173
package/esm/struct.d.ts
CHANGED
|
@@ -1,27 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type StructValueType<T extends StructLike<unknown>> = Awaited<ReturnType<T["deserialize"]>>;
|
|
12
|
-
/**
|
|
13
|
-
* Create a new `Struct` type with `TDefinition` appended
|
|
14
|
-
*/
|
|
15
|
-
type AddFieldDescriptor<TFields extends object, TOmitInitKey extends PropertyKey, TExtra extends object, TPostDeserialized, TFieldName extends PropertyKey, TDefinition extends StructFieldDefinition<any, any, any>> = Identity<Struct<Evaluate<TFields & Record<TFieldName, TDefinition["TValue"]>>, TOmitInitKey | TDefinition["TOmitInitKey"], TExtra, TPostDeserialized>>;
|
|
16
|
-
/**
|
|
17
|
-
* Similar to `ArrayBufferLikeFieldCreator`, but bind to `TType`
|
|
18
|
-
*/
|
|
19
|
-
interface BoundArrayBufferLikeFieldDefinitionCreator<TFields extends object, TOmitInitKey extends PropertyKey, TExtra extends object, TPostDeserialized, TType extends BufferFieldSubType<any, any>> {
|
|
20
|
-
<TName extends PropertyKey, TTypeScriptType = TType["TTypeScriptType"]>(name: TName, options: FixedLengthBufferLikeFieldOptions, typeScriptType?: TTypeScriptType): AddFieldDescriptor<TFields, TOmitInitKey, TExtra, TPostDeserialized, TName, FixedLengthBufferLikeFieldDefinition<TType, FixedLengthBufferLikeFieldOptions, TTypeScriptType>>;
|
|
21
|
-
<TName extends PropertyKey, TLengthField extends LengthField<TFields>, TOptions extends VariableLengthBufferLikeFieldOptions<TFields, TLengthField>, TTypeScriptType = TType["TTypeScriptType"]>(name: TName, options: TOptions, typeScriptType?: TTypeScriptType): AddFieldDescriptor<TFields, TOmitInitKey, TExtra, TPostDeserialized, TName, VariableLengthBufferLikeFieldDefinition<TType, TOptions, TTypeScriptType>>;
|
|
22
|
-
}
|
|
23
|
-
export type StructPostDeserialized<TFields, TPostDeserialized> = (this: TFields, object: TFields) => TPostDeserialized;
|
|
24
|
-
export type StructDeserializedResult<TFields extends object, TExtra extends object, TPostDeserialized> = TPostDeserialized extends undefined ? Overwrite<TExtra, TFields> : TPostDeserialized;
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
2
|
+
import type { Field } from "./field.js";
|
|
3
|
+
import type { AsyncExactReadable, ExactReadable } from "./readable.js";
|
|
4
|
+
export type FieldsType<T extends Record<string, Field<unknown, string, unknown>>> = {
|
|
5
|
+
[K in keyof T]: T[K] extends Field<infer TK, string, unknown> ? TK : never;
|
|
6
|
+
};
|
|
7
|
+
export type StructInit<T extends Struct<any, any, any>> = Omit<FieldsType<T["fields"]>, {
|
|
8
|
+
[K in keyof T["fields"]]: T["fields"][K] extends Field<unknown, infer U, unknown> ? U : never;
|
|
9
|
+
}[keyof T["fields"]]>;
|
|
10
|
+
export type StructValue<T extends Struct<any, any, any>> = T extends Struct<any, any, infer P> ? P : never;
|
|
25
11
|
export declare class StructDeserializeError extends Error {
|
|
26
12
|
constructor(message: string);
|
|
27
13
|
}
|
|
@@ -31,108 +17,19 @@ export declare class StructNotEnoughDataError extends StructDeserializeError {
|
|
|
31
17
|
export declare class StructEmptyError extends StructDeserializeError {
|
|
32
18
|
constructor();
|
|
33
19
|
}
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* Gets the static size (exclude fields that can change size at runtime)
|
|
44
|
-
*/
|
|
45
|
-
get size(): number;
|
|
46
|
-
get fields(): readonly [
|
|
47
|
-
name: PropertyKey,
|
|
48
|
-
definition: StructFieldDefinition<any, any, any>
|
|
49
|
-
][];
|
|
50
|
-
constructor(options?: Partial<Readonly<StructOptions>>);
|
|
51
|
-
/**
|
|
52
|
-
* Appends a `StructFieldDefinition` to the `Struct
|
|
53
|
-
*/
|
|
54
|
-
field<TName extends PropertyKey, TDefinition extends StructFieldDefinition<any, any, any>>(name: TName, definition: TDefinition): AddFieldDescriptor<TFields, TOmitInitKey, TExtra, TPostDeserialized, TName, TDefinition>;
|
|
55
|
-
/**
|
|
56
|
-
* Merges (flats) another `Struct`'s fields and extra fields into this one.
|
|
57
|
-
*/
|
|
58
|
-
concat<TOther extends Struct<any, any, any, any>>(other: TOther): Struct<TFields & TOther["TFields"], TOmitInitKey | TOther["TOmitInitKey"], TExtra & TOther["TExtra"], TPostDeserialized>;
|
|
59
|
-
/**
|
|
60
|
-
* Appends an `int8` field to the `Struct`
|
|
61
|
-
*/
|
|
62
|
-
int8<TName extends PropertyKey, TTypeScriptType = number>(name: TName, typeScriptType?: TTypeScriptType): Struct<Evaluate<TFields & Record<TName, TTypeScriptType>>, TOmitInitKey, TExtra, TPostDeserialized>;
|
|
63
|
-
/**
|
|
64
|
-
* Appends an `uint8` field to the `Struct`
|
|
65
|
-
*/
|
|
66
|
-
uint8<TName extends PropertyKey, TTypeScriptType = number>(name: TName, typeScriptType?: TTypeScriptType): Struct<Evaluate<TFields & Record<TName, TTypeScriptType>>, TOmitInitKey, TExtra, TPostDeserialized>;
|
|
67
|
-
/**
|
|
68
|
-
* Appends an `int16` field to the `Struct`
|
|
69
|
-
*/
|
|
70
|
-
int16<TName extends PropertyKey, TTypeScriptType = number>(name: TName, typeScriptType?: TTypeScriptType): Struct<Evaluate<TFields & Record<TName, TTypeScriptType>>, TOmitInitKey, TExtra, TPostDeserialized>;
|
|
71
|
-
/**
|
|
72
|
-
* Appends an `uint16` field to the `Struct`
|
|
73
|
-
*/
|
|
74
|
-
uint16<TName extends PropertyKey, TTypeScriptType = number>(name: TName, typeScriptType?: TTypeScriptType): Struct<Evaluate<TFields & Record<TName, TTypeScriptType>>, TOmitInitKey, TExtra, TPostDeserialized>;
|
|
75
|
-
/**
|
|
76
|
-
* Appends an `int32` field to the `Struct`
|
|
77
|
-
*/
|
|
78
|
-
int32<TName extends PropertyKey, TTypeScriptType = number>(name: TName, typeScriptType?: TTypeScriptType): Struct<Evaluate<TFields & Record<TName, TTypeScriptType>>, TOmitInitKey, TExtra, TPostDeserialized>;
|
|
79
|
-
/**
|
|
80
|
-
* Appends an `uint32` field to the `Struct`
|
|
81
|
-
*/
|
|
82
|
-
uint32<TName extends PropertyKey, TTypeScriptType = number>(name: TName, typeScriptType?: TTypeScriptType): Struct<Evaluate<TFields & Record<TName, TTypeScriptType>>, TOmitInitKey, TExtra, TPostDeserialized>;
|
|
83
|
-
/**
|
|
84
|
-
* Appends an `int64` field to the `Struct`
|
|
85
|
-
*
|
|
86
|
-
* Requires native `BigInt` support
|
|
87
|
-
*/
|
|
88
|
-
int64<TName extends PropertyKey, TTypeScriptType = BigIntFieldType["TTypeScriptType"]>(name: TName, typeScriptType?: TTypeScriptType): Struct<Evaluate<TFields & Record<TName, TTypeScriptType>>, TOmitInitKey, TExtra, TPostDeserialized>;
|
|
89
|
-
/**
|
|
90
|
-
* Appends an `uint64` field to the `Struct`
|
|
91
|
-
*
|
|
92
|
-
* Requires native `BigInt` support
|
|
93
|
-
*/
|
|
94
|
-
uint64<TName extends PropertyKey, TTypeScriptType = BigIntFieldType["TTypeScriptType"]>(name: TName, typeScriptType?: TTypeScriptType): Struct<Evaluate<TFields & Record<TName, TTypeScriptType>>, TOmitInitKey, TExtra, TPostDeserialized>;
|
|
95
|
-
uint8Array: BoundArrayBufferLikeFieldDefinitionCreator<TFields, TOmitInitKey, TExtra, TPostDeserialized, Uint8ArrayBufferFieldSubType>;
|
|
96
|
-
string: BoundArrayBufferLikeFieldDefinitionCreator<TFields, TOmitInitKey, TExtra, TPostDeserialized, StringBufferFieldSubType>;
|
|
97
|
-
/**
|
|
98
|
-
* Adds some extra properties into every `Struct` value.
|
|
99
|
-
*
|
|
100
|
-
* Extra properties will not affect serialize or deserialize process.
|
|
101
|
-
*
|
|
102
|
-
* Multiple calls to `extra` will merge all properties together.
|
|
103
|
-
*
|
|
104
|
-
* @param value
|
|
105
|
-
* An object containing properties to be added to the result value. Accessors and methods are also allowed.
|
|
106
|
-
*/
|
|
107
|
-
extra<T extends Record<Exclude<keyof T, Exclude<keyof T, keyof TFields>>, never>>(value: T & ThisType<Overwrite<Overwrite<TExtra, T>, TFields>>): Struct<TFields, TOmitInitKey, Overwrite<TExtra, T>, TPostDeserialized>;
|
|
108
|
-
/**
|
|
109
|
-
* Registers (or replaces) a custom callback to be run after deserialized.
|
|
110
|
-
*
|
|
111
|
-
* A callback returning `never` (always throw an error)
|
|
112
|
-
* will also change the return type of `deserialize` to `never`.
|
|
113
|
-
*/
|
|
114
|
-
postDeserialize(callback: StructPostDeserialized<TFields, never>): Struct<TFields, TOmitInitKey, TExtra, never>;
|
|
115
|
-
/**
|
|
116
|
-
* Registers (or replaces) a custom callback to be run after deserialized.
|
|
117
|
-
*
|
|
118
|
-
* A callback returning `void` means it modify the result object in-place
|
|
119
|
-
* (or doesn't modify it at all), so `deserialize` will still return the result object.
|
|
120
|
-
*/
|
|
121
|
-
postDeserialize(callback?: StructPostDeserialized<TFields, void>): Struct<TFields, TOmitInitKey, TExtra, undefined>;
|
|
122
|
-
/**
|
|
123
|
-
* Registers (or replaces) a custom callback to be run after deserialized.
|
|
124
|
-
*
|
|
125
|
-
* A callback returning anything other than `undefined`
|
|
126
|
-
* will `deserialize` to return that object instead.
|
|
127
|
-
*/
|
|
128
|
-
postDeserialize<TPostSerialize>(callback?: StructPostDeserialized<TFields, TPostSerialize>): Struct<TFields, TOmitInitKey, TExtra, TPostSerialize>;
|
|
129
|
-
/**
|
|
130
|
-
* Deserialize a struct value from `stream`.
|
|
131
|
-
*/
|
|
132
|
-
deserialize(stream: ExactReadable): StructDeserializedResult<TFields, TExtra, TPostDeserialized>;
|
|
133
|
-
deserialize(stream: AsyncExactReadable): Promise<StructDeserializedResult<TFields, TExtra, TPostDeserialized>>;
|
|
134
|
-
serialize(init: Evaluate<Omit<TFields, TOmitInitKey>>): Uint8Array;
|
|
135
|
-
serialize(init: Evaluate<Omit<TFields, TOmitInitKey>>, output: Uint8Array): number;
|
|
20
|
+
export type StructLike<T> = Struct<any, any, T>;
|
|
21
|
+
export interface Struct<T extends Record<string, Field<unknown, string, Partial<FieldsType<T>>>>, Extra extends Record<PropertyKey, unknown> | undefined = undefined, PostDeserialize = FieldsType<T> & Extra> {
|
|
22
|
+
fields: T;
|
|
23
|
+
size: number;
|
|
24
|
+
extra: Extra;
|
|
25
|
+
serialize(runtimeStruct: StructInit<this>): Uint8Array;
|
|
26
|
+
serialize(runtimeStruct: StructInit<this>, buffer: Uint8Array): number;
|
|
27
|
+
deserialize(reader: ExactReadable): PostDeserialize;
|
|
28
|
+
deserialize(reader: AsyncExactReadable): MaybePromiseLike<PostDeserialize>;
|
|
136
29
|
}
|
|
137
|
-
export {}
|
|
30
|
+
export declare function struct<T extends Record<string, Field<unknown, string, Partial<FieldsType<T>>>>, Extra extends Record<PropertyKey, unknown> = {}, PostDeserialize = FieldsType<T> & Extra>(fields: T, options: {
|
|
31
|
+
littleEndian?: boolean;
|
|
32
|
+
extra?: Extra & ThisType<FieldsType<T>>;
|
|
33
|
+
postDeserialize?: (this: FieldsType<T> & Extra, fields: FieldsType<T> & Extra) => PostDeserialize;
|
|
34
|
+
}): Struct<T, Extra, PostDeserialize>;
|
|
138
35
|
//# sourceMappingURL=struct.d.ts.map
|
package/esm/struct.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct.d.ts","sourceRoot":"","sources":["../src/struct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"struct.d.ts","sourceRoot":"","sources":["../src/struct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,KAAK,EAAsB,KAAK,EAAoB,MAAM,YAAY,CAAC;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGvE,MAAM,MAAM,UAAU,CAClB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IACzD;KACC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,KAAK;CAC7E,CAAC;AAEF,MAAM,MAAM,UAAU,CAElB,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAC/B,IAAI,CACJ,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EACvB;KACK,CAAC,IAAI,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAClD,OAAO,EACP,MAAM,CAAC,EACP,OAAO,CACV,GACK,CAAC,GACD,KAAK;CACd,CAAC,MAAM,CAAC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AAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAExE,KAAK,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,EAAE,EAC/C,eAAe,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,EAEvC,MAAM,EAAE,CAAC,EACT,OAAO,EAAE;IACL,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,eAAe,CAAC,EAAE,CACd,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,EAC3B,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,KAC5B,eAAe,CAAC;CACxB,GACF,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CA0GnC"}
|
package/esm/struct.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { BigIntFieldDefinition, BigIntFieldType, FixedLengthBufferLikeFieldDefinition, NumberFieldDefinition, NumberFieldType, StringBufferFieldSubType, Uint8ArrayBufferFieldSubType, VariableLengthBufferLikeFieldDefinition, } from "./types/index.js";
|
|
1
|
+
import { bipedal } from "./bipedal.js";
|
|
2
|
+
import { ExactReadableEndedError } from "./readable.js";
|
|
4
3
|
export class StructDeserializeError extends Error {
|
|
5
4
|
constructor(message) {
|
|
6
5
|
super(message);
|
|
7
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
8
6
|
}
|
|
9
7
|
}
|
|
10
8
|
export class StructNotEnoughDataError extends StructDeserializeError {
|
|
@@ -17,227 +15,87 @@ export class StructEmptyError extends StructDeserializeError {
|
|
|
17
15
|
super("The underlying readable doesn't contain any more struct");
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
#extra = {};
|
|
39
|
-
#postDeserialized;
|
|
40
|
-
constructor(options) {
|
|
41
|
-
this.options = { ...StructDefaultOptions, ...options };
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Appends a `StructFieldDefinition` to the `Struct
|
|
45
|
-
*/
|
|
46
|
-
field(name, definition) {
|
|
47
|
-
for (const field of this.#fields) {
|
|
48
|
-
if (field[0] === name) {
|
|
49
|
-
// Convert Symbol to string
|
|
50
|
-
const nameString = String(name);
|
|
51
|
-
throw new Error(`This struct already have a field with name '${nameString}'`);
|
|
18
|
+
/* #__NO_SIDE_EFFECTS__ */
|
|
19
|
+
export function struct(fields, options) {
|
|
20
|
+
const fieldList = Object.entries(fields);
|
|
21
|
+
const size = fieldList.reduce((sum, [, field]) => sum + field.size, 0);
|
|
22
|
+
const littleEndian = !!options.littleEndian;
|
|
23
|
+
const extra = options.extra
|
|
24
|
+
? Object.getOwnPropertyDescriptors(options.extra)
|
|
25
|
+
: undefined;
|
|
26
|
+
return {
|
|
27
|
+
fields,
|
|
28
|
+
size,
|
|
29
|
+
extra: options.extra,
|
|
30
|
+
serialize(runtimeStruct, buffer) {
|
|
31
|
+
for (const [key, field] of fieldList) {
|
|
32
|
+
if (key in runtimeStruct) {
|
|
33
|
+
field.preSerialize?.(runtimeStruct[key], runtimeStruct);
|
|
34
|
+
}
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return this.#number(name, NumberFieldType.Uint16, typeScriptType);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Appends an `int32` field to the `Struct`
|
|
100
|
-
*/
|
|
101
|
-
int32(name, typeScriptType) {
|
|
102
|
-
return this.#number(name, NumberFieldType.Int32, typeScriptType);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Appends an `uint32` field to the `Struct`
|
|
106
|
-
*/
|
|
107
|
-
uint32(name, typeScriptType) {
|
|
108
|
-
return this.#number(name, NumberFieldType.Uint32, typeScriptType);
|
|
109
|
-
}
|
|
110
|
-
#bigint(name, type, typeScriptType) {
|
|
111
|
-
return this.field(name, new BigIntFieldDefinition(type, typeScriptType));
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Appends an `int64` field to the `Struct`
|
|
115
|
-
*
|
|
116
|
-
* Requires native `BigInt` support
|
|
117
|
-
*/
|
|
118
|
-
int64(name, typeScriptType) {
|
|
119
|
-
return this.#bigint(name, BigIntFieldType.Int64, typeScriptType);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Appends an `uint64` field to the `Struct`
|
|
123
|
-
*
|
|
124
|
-
* Requires native `BigInt` support
|
|
125
|
-
*/
|
|
126
|
-
uint64(name, typeScriptType) {
|
|
127
|
-
return this.#bigint(name, BigIntFieldType.Uint64, typeScriptType);
|
|
128
|
-
}
|
|
129
|
-
#arrayBufferLike = (name, type, options) => {
|
|
130
|
-
if ("length" in options) {
|
|
131
|
-
return this.field(name, new FixedLengthBufferLikeFieldDefinition(type, options));
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
return this.field(name, new VariableLengthBufferLikeFieldDefinition(type, options));
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
uint8Array = (name, options, typeScriptType) => {
|
|
138
|
-
return this.#arrayBufferLike(name, Uint8ArrayBufferFieldSubType.Instance, options, typeScriptType);
|
|
139
|
-
};
|
|
140
|
-
string = (name, options, typeScriptType) => {
|
|
141
|
-
return this.#arrayBufferLike(name, StringBufferFieldSubType.Instance, options, typeScriptType);
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Adds some extra properties into every `Struct` value.
|
|
145
|
-
*
|
|
146
|
-
* Extra properties will not affect serialize or deserialize process.
|
|
147
|
-
*
|
|
148
|
-
* Multiple calls to `extra` will merge all properties together.
|
|
149
|
-
*
|
|
150
|
-
* @param value
|
|
151
|
-
* An object containing properties to be added to the result value. Accessors and methods are also allowed.
|
|
152
|
-
*/
|
|
153
|
-
extra(value) {
|
|
154
|
-
Object.defineProperties(this.#extra, Object.getOwnPropertyDescriptors(value));
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
postDeserialize(callback) {
|
|
158
|
-
this.#postDeserialized = callback;
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
deserialize(stream) {
|
|
162
|
-
const structValue = new StructValue(this.#extra);
|
|
163
|
-
let promise = SyncPromise.resolve();
|
|
164
|
-
const startPosition = stream.position;
|
|
165
|
-
for (const [name, definition] of this.#fields) {
|
|
166
|
-
promise = promise
|
|
167
|
-
.then(() => definition.deserialize(this.options, stream, structValue))
|
|
168
|
-
.then((fieldValue) => {
|
|
169
|
-
structValue.set(name, fieldValue);
|
|
170
|
-
}, (e) => {
|
|
36
|
+
const sizes = fieldList.map(([key, field]) => field.dynamicSize?.(runtimeStruct[key]) ??
|
|
37
|
+
field.size);
|
|
38
|
+
const size = sizes.reduce((sum, size) => sum + size, 0);
|
|
39
|
+
let externalBuffer = false;
|
|
40
|
+
if (buffer) {
|
|
41
|
+
if (buffer.length < size) {
|
|
42
|
+
throw new Error("Buffer too small");
|
|
43
|
+
}
|
|
44
|
+
externalBuffer = true;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
buffer = new Uint8Array(size);
|
|
48
|
+
}
|
|
49
|
+
const context = {
|
|
50
|
+
buffer,
|
|
51
|
+
index: 0,
|
|
52
|
+
littleEndian,
|
|
53
|
+
};
|
|
54
|
+
for (const [index, [key, field]] of fieldList.entries()) {
|
|
55
|
+
field.serialize(runtimeStruct[key], context);
|
|
56
|
+
context.index += sizes[index];
|
|
57
|
+
}
|
|
58
|
+
if (externalBuffer) {
|
|
59
|
+
return size;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return buffer;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
deserialize: bipedal(function* (then, reader) {
|
|
66
|
+
const startPosition = reader.position;
|
|
67
|
+
const runtimeStruct = {};
|
|
68
|
+
const context = {
|
|
69
|
+
reader,
|
|
70
|
+
runtimeStruct: runtimeStruct,
|
|
71
|
+
littleEndian: littleEndian,
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
for (const [key, field] of fieldList) {
|
|
75
|
+
runtimeStruct[key] = yield* then(field.deserialize(context));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
171
79
|
if (!(e instanceof ExactReadableEndedError)) {
|
|
172
80
|
throw e;
|
|
173
81
|
}
|
|
174
|
-
if (
|
|
82
|
+
if (reader.position === startPosition) {
|
|
175
83
|
throw new StructEmptyError();
|
|
176
84
|
}
|
|
177
85
|
else {
|
|
178
86
|
throw new StructNotEnoughDataError();
|
|
179
87
|
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
return promise
|
|
183
|
-
.then(() => {
|
|
184
|
-
const value = structValue.value;
|
|
185
|
-
// Run `postDeserialized`
|
|
186
|
-
if (this.#postDeserialized) {
|
|
187
|
-
const override = this.#postDeserialized.call(value, value);
|
|
188
|
-
// If it returns a new value, use that as result
|
|
189
|
-
// Otherwise it only inspects/mutates the object in place.
|
|
190
|
-
if (override !== undefined) {
|
|
191
|
-
return override;
|
|
192
|
-
}
|
|
193
88
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
.valueOrPromise();
|
|
197
|
-
}
|
|
198
|
-
serialize(init, output) {
|
|
199
|
-
let structValue;
|
|
200
|
-
if (STRUCT_VALUE_SYMBOL in init) {
|
|
201
|
-
structValue = init[STRUCT_VALUE_SYMBOL];
|
|
202
|
-
for (const [key, value] of Object.entries(init)) {
|
|
203
|
-
const fieldValue = structValue.get(key);
|
|
204
|
-
if (fieldValue) {
|
|
205
|
-
fieldValue.set(value);
|
|
206
|
-
}
|
|
89
|
+
if (extra) {
|
|
90
|
+
Object.defineProperties(runtimeStruct, extra);
|
|
207
91
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
structValue = new StructValue({});
|
|
211
|
-
for (const [name, definition] of this.#fields) {
|
|
212
|
-
const fieldValue = definition.create(this.options, structValue, init[name]);
|
|
213
|
-
structValue.set(name, fieldValue);
|
|
92
|
+
if (options.postDeserialize) {
|
|
93
|
+
return options.postDeserialize.call(runtimeStruct, runtimeStruct);
|
|
214
94
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const size = fieldValue.getSize();
|
|
221
|
-
fieldsInfo.push({ fieldValue, size });
|
|
222
|
-
structSize += size;
|
|
223
|
-
}
|
|
224
|
-
let outputType = "number";
|
|
225
|
-
if (!output) {
|
|
226
|
-
output = new Uint8Array(structSize);
|
|
227
|
-
outputType = "Uint8Array";
|
|
228
|
-
}
|
|
229
|
-
const dataView = new DataView(output.buffer, output.byteOffset, output.byteLength);
|
|
230
|
-
let offset = 0;
|
|
231
|
-
for (const { fieldValue, size } of fieldsInfo) {
|
|
232
|
-
fieldValue.serialize(dataView, offset);
|
|
233
|
-
offset += size;
|
|
234
|
-
}
|
|
235
|
-
if (outputType === "number") {
|
|
236
|
-
return structSize;
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
return output;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
95
|
+
else {
|
|
96
|
+
return runtimeStruct;
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
242
100
|
}
|
|
243
101
|
//# sourceMappingURL=struct.js.map
|
package/esm/struct.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct.js","sourceRoot":"","sources":["../src/struct.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"struct.js","sourceRoot":"","sources":["../src/struct.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AA8BxD,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ;AAED,MAAM,OAAO,wBAAyB,SAAQ,sBAAsB;IAChE;QACI,KAAK,CACD,4EAA4E,CAC/E,CAAC;IACN,CAAC;CACJ;AAED,MAAM,OAAO,gBAAiB,SAAQ,sBAAsB;IACxD;QACI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IACrE,CAAC;CACJ;AAqBD,0BAA0B;AAC1B,MAAM,UAAU,MAAM,CAMlB,MAAS,EACT,OAOC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,E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;gBACzC,CAAC;YACL,CAAC;YAED,IAAI,KAAK,EAAE,CAAC;gBACR,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;YAClD,CAAC;YAED,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;gBAC1B,OAAO,OAAO,CAAC,eAAe,CAAC,IAAI,CAC/B,aAAsB,EACtB,aAAsB,CACzB,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO,aAAa,CAAC;YACzB,CAAC;QACL,CAAC,CAAC;KACI,CAAC;AACf,CAAC"}
|
package/esm/utils.d.ts
CHANGED
|
@@ -1,48 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* type WithIdentityResult = WithIdentity<number>;
|
|
12
|
-
* // Hover on this one shows `SomeType<number>`
|
|
13
|
-
*
|
|
14
|
-
* type WithoutIdentityResult = WithoutIdentity<number>;
|
|
15
|
-
* // Hover on this one shows `WithoutIdentity<number>`
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export type Identity<T> = T;
|
|
19
|
-
/**
|
|
20
|
-
* Collapse an intersection type (`{ foo: string } & { bar: number }`) to a simple type (`{ foo: string, bar: number }`)
|
|
21
|
-
*/
|
|
22
|
-
export type Evaluate<T> = T extends infer U ? {
|
|
23
|
-
[K in keyof U]: U[K];
|
|
24
|
-
} : never;
|
|
25
|
-
/**
|
|
26
|
-
* Overwrite fields in `TBase` with fields in `TNew`
|
|
27
|
-
*/
|
|
28
|
-
export type Overwrite<TBase extends object, TNew extends object> = Evaluate<Omit<TBase, keyof TNew> & TNew>;
|
|
29
|
-
/**
|
|
30
|
-
* Remove fields with `never` type
|
|
31
|
-
*/
|
|
32
|
-
export type OmitNever<T> = Pick<T, {
|
|
33
|
-
[K in keyof T]: [T[K]] extends [never] ? never : K;
|
|
34
|
-
}[keyof T]>;
|
|
35
|
-
/**
|
|
36
|
-
* Extract keys of fields in `T` that has type `TValue`
|
|
37
|
-
*/
|
|
38
|
-
export type KeysOfType<T, TValue> = {
|
|
39
|
-
[TKey in keyof T]: T[TKey] extends TValue ? TKey : never;
|
|
40
|
-
}[keyof T];
|
|
41
|
-
export type ValueOrPromise<T> = T | PromiseLike<T>;
|
|
42
|
-
/**
|
|
43
|
-
* Returns a (fake) value of the given type.
|
|
44
|
-
*/
|
|
45
|
-
export declare function placeholder<T>(): T;
|
|
1
|
+
interface TextEncoder {
|
|
2
|
+
encode(input: string): Uint8Array;
|
|
3
|
+
}
|
|
4
|
+
interface TextDecoder {
|
|
5
|
+
decode(buffer?: ArrayBufferView | ArrayBuffer, options?: {
|
|
6
|
+
stream?: boolean;
|
|
7
|
+
}): string;
|
|
8
|
+
}
|
|
9
|
+
export declare const TextEncoder: new () => TextEncoder, TextDecoder: new () => TextDecoder;
|
|
46
10
|
export declare function encodeUtf8(input: string): Uint8Array;
|
|
47
11
|
export declare function decodeUtf8(buffer: ArrayBufferView | ArrayBuffer): string;
|
|
12
|
+
export {};
|
|
48
13
|
//# sourceMappingURL=utils.d.ts.map
|
package/esm/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAQA,UAAU,WAAW;IACjB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;CACrC;AAED,UAAU,WAAW;IACjB,MAAM,CACF,MAAM,CAAC,EAAE,eAAe,GAAG,WAAW,EACtC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAC/B,MAAM,CAAC;CACb;AAOD,eAAO,MAAQ,WAAW,YAJC,WAAW,EAIV,WAAW,YAHZ,WAIiB,CAAC;AAM7C,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEpD;AAGD,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,GAAG,MAAM,CAIxE"}
|