@yume-chan/struct 0.0.18 → 0.0.20
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 +27 -0
- package/CHANGELOG.md +16 -1
- package/README.md +126 -143
- 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/definition.js.map +1 -1
- 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 +24 -19
- package/esm/basic/stream.d.ts.map +1 -1
- package/esm/basic/stream.js +7 -1
- package/esm/basic/stream.js.map +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 +14 -13
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +6 -5
- package/esm/index.js.map +1 -1
- package/esm/struct.d.ts +140 -129
- package/esm/struct.d.ts.map +1 -1
- package/esm/struct.js +242 -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/sync-promise.js.map +1 -1
- 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 +111 -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 +9 -8
- package/src/basic/definition.ts +6 -9
- package/src/basic/field-value.ts +3 -3
- package/src/basic/index.ts +5 -5
- package/src/basic/stream.ts +18 -7
- package/src/basic/struct-value.ts +1 -1
- package/src/index.ts +6 -5
- package/src/struct.ts +91 -59
- package/src/sync-promise.ts +12 -12
- package/src/types/bigint.ts +11 -12
- package/src/types/buffer/base.ts +12 -12
- package/src/types/buffer/fixed-length.ts +2 -1
- package/src/types/buffer/variable-length.ts +8 -11
- package/src/types/number.ts +28 -33
- package/tsconfig.build.tsbuildinfo +1 -1
package/esm/sync-promise.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
export const SyncPromise = {
|
|
2
|
-
reject(reason) {
|
|
3
|
-
return new RejectedSyncPromise(reason);
|
|
4
|
-
},
|
|
5
|
-
resolve(value) {
|
|
6
|
-
if (typeof value === "object" &&
|
|
7
|
-
value !== null &&
|
|
8
|
-
typeof value.then === "function") {
|
|
9
|
-
if (value instanceof PendingSyncPromise ||
|
|
10
|
-
value instanceof ResolvedSyncPromise ||
|
|
11
|
-
value instanceof RejectedSyncPromise) {
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
return new PendingSyncPromise(value);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
return new ResolvedSyncPromise(value);
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
try(executor) {
|
|
21
|
-
try {
|
|
22
|
-
return SyncPromise.resolve(executor());
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
return SyncPromise.reject(e);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
class PendingSyncPromise {
|
|
30
|
-
promise;
|
|
31
|
-
constructor(promise) {
|
|
32
|
-
this
|
|
33
|
-
}
|
|
34
|
-
then(onfulfilled, onrejected) {
|
|
35
|
-
return new PendingSyncPromise(this
|
|
36
|
-
}
|
|
37
|
-
valueOrPromise() {
|
|
38
|
-
return this
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
class ResolvedSyncPromise {
|
|
42
|
-
value;
|
|
43
|
-
constructor(value) {
|
|
44
|
-
this
|
|
45
|
-
}
|
|
46
|
-
then(onfulfilled) {
|
|
47
|
-
if (!onfulfilled) {
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
return SyncPromise.try(() => onfulfilled(this
|
|
51
|
-
}
|
|
52
|
-
valueOrPromise() {
|
|
53
|
-
return this
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
class RejectedSyncPromise {
|
|
57
|
-
reason;
|
|
58
|
-
constructor(reason) {
|
|
59
|
-
this
|
|
60
|
-
}
|
|
61
|
-
then(onfulfilled, onrejected) {
|
|
62
|
-
if (!onrejected) {
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
return SyncPromise.try(() => onrejected(this
|
|
66
|
-
}
|
|
67
|
-
valueOrPromise() {
|
|
68
|
-
throw this
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
export const SyncPromise = {
|
|
2
|
+
reject(reason) {
|
|
3
|
+
return new RejectedSyncPromise(reason);
|
|
4
|
+
},
|
|
5
|
+
resolve(value) {
|
|
6
|
+
if (typeof value === "object" &&
|
|
7
|
+
value !== null &&
|
|
8
|
+
typeof value.then === "function") {
|
|
9
|
+
if (value instanceof PendingSyncPromise ||
|
|
10
|
+
value instanceof ResolvedSyncPromise ||
|
|
11
|
+
value instanceof RejectedSyncPromise) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
return new PendingSyncPromise(value);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return new ResolvedSyncPromise(value);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
try(executor) {
|
|
21
|
+
try {
|
|
22
|
+
return SyncPromise.resolve(executor());
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
return SyncPromise.reject(e);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
class PendingSyncPromise {
|
|
30
|
+
#promise;
|
|
31
|
+
constructor(promise) {
|
|
32
|
+
this.#promise = promise;
|
|
33
|
+
}
|
|
34
|
+
then(onfulfilled, onrejected) {
|
|
35
|
+
return new PendingSyncPromise(this.#promise.then(onfulfilled, onrejected));
|
|
36
|
+
}
|
|
37
|
+
valueOrPromise() {
|
|
38
|
+
return this.#promise;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class ResolvedSyncPromise {
|
|
42
|
+
#value;
|
|
43
|
+
constructor(value) {
|
|
44
|
+
this.#value = value;
|
|
45
|
+
}
|
|
46
|
+
then(onfulfilled) {
|
|
47
|
+
if (!onfulfilled) {
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
return SyncPromise.try(() => onfulfilled(this.#value));
|
|
51
|
+
}
|
|
52
|
+
valueOrPromise() {
|
|
53
|
+
return this.#value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class RejectedSyncPromise {
|
|
57
|
+
#reason;
|
|
58
|
+
constructor(reason) {
|
|
59
|
+
this.#reason = reason;
|
|
60
|
+
}
|
|
61
|
+
then(onfulfilled, onrejected) {
|
|
62
|
+
if (!onrejected) {
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
return SyncPromise.try(() => onrejected(this.#reason));
|
|
66
|
+
}
|
|
67
|
+
valueOrPromise() {
|
|
68
|
+
throw this.#reason;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
71
|
//# sourceMappingURL=sync-promise.js.map
|
package/esm/sync-promise.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-promise.js","sourceRoot":"","sources":["../src/sync-promise.ts"],"names":[],"mappings":"AAwBA,MAAM,CAAC,MAAM,WAAW,GAAsB;IAC1C,MAAM,CAAY,MAAY;QAC1B,OAAO,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,CAAI,KAA0B;QACjC,IACI,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YACd,OAAQ,KAAwB,CAAC,IAAI,KAAK,UAAU,EACtD;YACE,IACI,KAAK,YAAY,kBAAkB;gBACnC,KAAK,YAAY,mBAAmB;gBACpC,KAAK,YAAY,mBAAmB,EACtC;gBACE,OAAO,KAAK,CAAC;aAChB;YAED,OAAO,IAAI,kBAAkB,CAAC,KAAuB,CAAC,CAAC;SAC1D;aAAM;YACH,OAAO,IAAI,mBAAmB,CAAC,KAAU,CAAC,CAAC;SAC9C;IACL,CAAC;IACD,GAAG,CAAI,QAAkC;QACrC,IAAI;YACA,OAAO,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;SAC1C;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SAChC;IACL,CAAC;CACJ,CAAC;AAEF,MAAM,kBAAkB;
|
|
1
|
+
{"version":3,"file":"sync-promise.js","sourceRoot":"","sources":["../src/sync-promise.ts"],"names":[],"mappings":"AAwBA,MAAM,CAAC,MAAM,WAAW,GAAsB;IAC1C,MAAM,CAAY,MAAY;QAC1B,OAAO,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,CAAI,KAA0B;QACjC,IACI,OAAO,KAAK,KAAK,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AAC;IACvB,CAAC;CACJ;AAED,MAAM,mBAAmB;IACrB,OAAO,CAAM;IAEb,YAAmB,MAAW;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAEM,IAAI,CACP,WAGe,EACf,UAGe;QAEf,IAAI,CAAC,UAAU,EAAE;YACb,OAAO,IAAW,CAAC;SACtB;QACD,OAAO,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IAEM,cAAc;QACjB,MAAM,IAAI,CAAC,OAAO,CAAC;IACvB,CAAC;CACJ"}
|
package/esm/types/bigint.d.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly
|
|
7
|
-
readonly
|
|
8
|
-
readonly
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
static readonly
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
deserialize(options: Readonly<StructOptions>, stream:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import type { AsyncExactReadable, ExactReadable, StructOptions, StructValue } from "../basic/index.js";
|
|
2
|
+
import { StructFieldDefinition, StructFieldValue } from "../basic/index.js";
|
|
3
|
+
type DataViewBigInt64Getter = (dataView: DataView, byteOffset: number, littleEndian: boolean | undefined) => bigint;
|
|
4
|
+
type DataViewBigInt64Setter = (dataView: DataView, byteOffset: number, value: bigint, littleEndian: boolean | undefined) => void;
|
|
5
|
+
export declare class BigIntFieldType {
|
|
6
|
+
readonly TTypeScriptType: bigint;
|
|
7
|
+
readonly size: number;
|
|
8
|
+
readonly getter: DataViewBigInt64Getter;
|
|
9
|
+
readonly setter: DataViewBigInt64Setter;
|
|
10
|
+
constructor(size: number, getter: DataViewBigInt64Getter, setter: DataViewBigInt64Setter);
|
|
11
|
+
static readonly Int64: BigIntFieldType;
|
|
12
|
+
static readonly Uint64: BigIntFieldType;
|
|
13
|
+
}
|
|
14
|
+
export declare class BigIntFieldDefinition<TType extends BigIntFieldType = BigIntFieldType, TTypeScriptType = TType["TTypeScriptType"]> extends StructFieldDefinition<void, TTypeScriptType> {
|
|
15
|
+
readonly type: TType;
|
|
16
|
+
constructor(type: TType, typescriptType?: TTypeScriptType);
|
|
17
|
+
getSize(): number;
|
|
18
|
+
create(options: Readonly<StructOptions>, struct: StructValue, value: TTypeScriptType): BigIntFieldValue<this>;
|
|
19
|
+
deserialize(options: Readonly<StructOptions>, stream: ExactReadable, struct: StructValue): BigIntFieldValue<this>;
|
|
20
|
+
deserialize(options: Readonly<StructOptions>, stream: AsyncExactReadable, struct: StructValue): Promise<BigIntFieldValue<this>>;
|
|
21
|
+
}
|
|
22
|
+
export declare class BigIntFieldValue<TDefinition extends BigIntFieldDefinition<BigIntFieldType, any>> extends StructFieldValue<TDefinition> {
|
|
23
|
+
serialize(dataView: DataView, offset: number): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
25
26
|
//# sourceMappingURL=bigint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bigint.d.ts","sourceRoot":"","sources":["../../src/types/bigint.ts"],"names":[],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"bigint.d.ts","sourceRoot":"","sources":["../../src/types/bigint.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,WAAW,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAI5E,KAAK,sBAAsB,GAAG,CAC1B,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,OA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,gBAAgB,CACzB,WAAW,SAAS,qBAAqB,CAAC,eAAe,EAAE,GAAG,CAAC,CACjE,SAAQ,gBAAgB,CAAC,WAAW,CAAC;IAC5B,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAQ7D"}
|
package/esm/types/bigint.js
CHANGED
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import { getBigInt64, getBigUint64, setBigInt64, setBigUint64, } from "@yume-chan/dataview-bigint-polyfill/esm/fallback.js";
|
|
2
|
-
import { StructFieldDefinition, StructFieldValue
|
|
3
|
-
import { SyncPromise } from "../sync-promise.js";
|
|
4
|
-
|
|
5
|
-
TTypeScriptType;
|
|
6
|
-
size;
|
|
7
|
-
getter;
|
|
8
|
-
setter;
|
|
9
|
-
constructor(size, getter, setter) {
|
|
10
|
-
this.size = size;
|
|
11
|
-
this.getter = getter;
|
|
12
|
-
this.setter = setter;
|
|
13
|
-
}
|
|
14
|
-
static Int64 = new BigIntFieldType(8, getBigInt64, setBigInt64);
|
|
15
|
-
static Uint64 = new BigIntFieldType(8, getBigUint64, setBigUint64);
|
|
16
|
-
}
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
1
|
+
import { getBigInt64, getBigUint64, setBigInt64, setBigUint64, } from "@yume-chan/dataview-bigint-polyfill/esm/fallback.js";
|
|
2
|
+
import { StructFieldDefinition, StructFieldValue } from "../basic/index.js";
|
|
3
|
+
import { SyncPromise } from "../sync-promise.js";
|
|
4
|
+
class BigIntFieldType {
|
|
5
|
+
TTypeScriptType;
|
|
6
|
+
size;
|
|
7
|
+
getter;
|
|
8
|
+
setter;
|
|
9
|
+
constructor(size, getter, setter) {
|
|
10
|
+
this.size = size;
|
|
11
|
+
this.getter = getter;
|
|
12
|
+
this.setter = setter;
|
|
13
|
+
}
|
|
14
|
+
static Int64 = new BigIntFieldType(8, getBigInt64, setBigInt64);
|
|
15
|
+
static Uint64 = new BigIntFieldType(8, getBigUint64, setBigUint64);
|
|
16
|
+
}
|
|
17
|
+
export { BigIntFieldType };
|
|
18
|
+
export class BigIntFieldDefinition extends StructFieldDefinition {
|
|
19
|
+
type;
|
|
20
|
+
constructor(type, typescriptType) {
|
|
21
|
+
void typescriptType;
|
|
22
|
+
super();
|
|
23
|
+
this.type = type;
|
|
24
|
+
}
|
|
25
|
+
getSize() {
|
|
26
|
+
return this.type.size;
|
|
27
|
+
}
|
|
28
|
+
create(options, struct, value) {
|
|
29
|
+
return new BigIntFieldValue(this, options, struct, value);
|
|
30
|
+
}
|
|
31
|
+
deserialize(options, stream, struct) {
|
|
32
|
+
return SyncPromise.try(() => {
|
|
33
|
+
return stream.readExactly(this.getSize());
|
|
34
|
+
})
|
|
35
|
+
.then((array) => {
|
|
36
|
+
const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
37
|
+
const value = this.type.getter(view, 0, options.littleEndian);
|
|
38
|
+
return this.create(options, struct, value);
|
|
39
|
+
})
|
|
40
|
+
.valueOrPromise();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class BigIntFieldValue extends StructFieldValue {
|
|
44
|
+
serialize(dataView, offset) {
|
|
45
|
+
this.definition.type.setter(dataView, offset, this.value, this.options.littleEndian);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
47
48
|
//# sourceMappingURL=bigint.js.map
|
package/esm/types/bigint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bigint.js","sourceRoot":"","sources":["../../src/types/bigint.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,GACf,MAAM,qDAAqD,CAAC;
|
|
1
|
+
{"version":3,"file":"bigint.js","sourceRoot":"","sources":["../../src/types/bigint.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,GACf,MAAM,qDAAqD,CAAC;AAQ7D,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAgBjD,MAAa,eAAe;IACR,eAAe,CAAU;IAEzB,IAAI,CAAS;IAEb,MAAM,CAAyB;IAE/B,MAAM,CAAyB;IAE/C,YACI,IAAY,EACZ,MAA8B,EAC9B,MAA8B;QAE9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAEM,MAAM,CAAU,KAAK,GAAG,IAAI,eAAe,CAC9C,CAAC,EACD,WAAW,EACX,WAAW,CACd,CAAC;IAEK,MAAM,CAAU,MAAM,GAAG,IAAI,eAAe,CAC/C,CAAC,EACD,YAAY,EACZ,YAAY,CACf,CAAC;;SA7BO,eAAe;AAgC5B,MAAM,OAAO,qBAGX,SAAQ,qBAA4C;IAClC,IAAI,CAAQ;IAE5B,YAAmB,IAAW,EAAE,cAAgC;QAC5D,KAAK,cAAc,CAAC;QACpB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAEM,OAAO;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC1B,CAAC;IAEM,MAAM,CACT,OAAgC,EAChC,MAAmB,EACnB,KAAsB;QAEtB,OAAO,I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|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export declare
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
deserialize(options: Readonly<StructOptions>, stream:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
import type { AsyncExactReadable, ExactReadable, StructOptions, StructValue } from "../../basic/index.js";
|
|
2
|
+
import { StructFieldDefinition, StructFieldValue } from "../../basic/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base class for all types that
|
|
5
|
+
* can be converted from an `Uint8Array` when deserialized,
|
|
6
|
+
* and need to be converted to an `Uint8Array` when serializing
|
|
7
|
+
*
|
|
8
|
+
* @template TValue The actual TypeScript type of this type
|
|
9
|
+
* @template TTypeScriptType Optional another type (should be compatible with `TType`)
|
|
10
|
+
* specified by user when creating field definitions.
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class BufferFieldSubType<TValue = unknown, TTypeScriptType = TValue> {
|
|
13
|
+
readonly TTypeScriptType: TTypeScriptType;
|
|
14
|
+
/**
|
|
15
|
+
* When implemented in derived classes, converts the type-specific `value` to an `Uint8Array`
|
|
16
|
+
*
|
|
17
|
+
* This function should be "pure", i.e.,
|
|
18
|
+
* same `value` should always be converted to `Uint8Array`s that have same content.
|
|
19
|
+
*/
|
|
20
|
+
abstract toBuffer(value: TValue): Uint8Array;
|
|
21
|
+
/** When implemented in derived classes, converts the `Uint8Array` to a type-specific value */
|
|
22
|
+
abstract toValue(array: Uint8Array): TValue;
|
|
23
|
+
/**
|
|
24
|
+
* When implemented in derived classes, gets the size in byte of the type-specific `value`.
|
|
25
|
+
*
|
|
26
|
+
* If the size can't be calculated without first converting the `value` back to an `Uint8Array`,
|
|
27
|
+
* implementer can returns `-1`, so the caller will get its size by first converting it to
|
|
28
|
+
* an `Uint8Array` (and cache the result).
|
|
29
|
+
*/
|
|
30
|
+
abstract getSize(value: TValue): number;
|
|
31
|
+
}
|
|
32
|
+
/** An `BufferFieldSubType` that's actually an `Uint8Array` */
|
|
33
|
+
export declare class Uint8ArrayBufferFieldSubType<TTypeScriptType = Uint8Array> extends BufferFieldSubType<Uint8Array, TTypeScriptType> {
|
|
34
|
+
static readonly Instance: Uint8ArrayBufferFieldSubType<Uint8Array>;
|
|
35
|
+
protected constructor();
|
|
36
|
+
toBuffer(value: Uint8Array): Uint8Array;
|
|
37
|
+
toValue(buffer: Uint8Array): Uint8Array;
|
|
38
|
+
getSize(value: Uint8Array): number;
|
|
39
|
+
}
|
|
40
|
+
/** An `BufferFieldSubType` that converts between `Uint8Array` and `string` */
|
|
41
|
+
export declare class StringBufferFieldSubType<TTypeScriptType = string> extends BufferFieldSubType<string, TTypeScriptType> {
|
|
42
|
+
static readonly Instance: StringBufferFieldSubType<string>;
|
|
43
|
+
toBuffer(value: string): Uint8Array;
|
|
44
|
+
toValue(array: Uint8Array): string;
|
|
45
|
+
getSize(): number;
|
|
46
|
+
}
|
|
47
|
+
export declare const EMPTY_UINT8_ARRAY: Uint8Array;
|
|
48
|
+
export declare abstract class BufferLikeFieldDefinition<TType extends BufferFieldSubType<any, any> = BufferFieldSubType<unknown, unknown>, TOptions = void, TOmitInitKey extends PropertyKey = never, TTypeScriptType = TType["TTypeScriptType"]> extends StructFieldDefinition<TOptions, TTypeScriptType, TOmitInitKey> {
|
|
49
|
+
readonly type: TType;
|
|
50
|
+
constructor(type: TType, options: TOptions);
|
|
51
|
+
protected getDeserializeSize(struct: StructValue): number;
|
|
52
|
+
/**
|
|
53
|
+
* When implemented in derived classes, creates a `StructFieldValue` for the current field definition.
|
|
54
|
+
*/
|
|
55
|
+
create(options: Readonly<StructOptions>, struct: StructValue, value: TType["TTypeScriptType"], array?: Uint8Array): BufferLikeFieldValue<this>;
|
|
56
|
+
deserialize(options: Readonly<StructOptions>, stream: ExactReadable, struct: StructValue): BufferLikeFieldValue<this>;
|
|
57
|
+
deserialize(options: Readonly<StructOptions>, stream: AsyncExactReadable, struct: StructValue): Promise<BufferLikeFieldValue<this>>;
|
|
58
|
+
}
|
|
59
|
+
export declare class BufferLikeFieldValue<TDefinition extends BufferLikeFieldDefinition<BufferFieldSubType<unknown, unknown>, any, any>> extends StructFieldValue<TDefinition> {
|
|
60
|
+
protected array: Uint8Array | undefined;
|
|
61
|
+
constructor(definition: TDefinition, options: Readonly<StructOptions>, struct: StructValue, value: TDefinition["TValue"], array?: Uint8Array);
|
|
62
|
+
set(value: TDefinition["TValue"]): void;
|
|
63
|
+
serialize(dataView: DataView, offset: number): void;
|
|
64
|
+
}
|
|
64
65
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/types/buffer/base.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/types/buffer/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,WAAW,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAK/E;;;;;;;;GAQG;AACH,8BAAsB,kBAAkB,CACpC,MAAM,GAAG,OAAO,EAChB,eAAe,GAAG,MAAM;IAExB,SAAgB,eAAe,EAAG,eAAe,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