@yume-chan/struct 0.0.5 → 0.0.10
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 +23 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -21
- package/README.md +720 -643
- package/dts/basic/context.d.ts +10 -17
- package/dts/basic/context.d.ts.map +1 -1
- package/dts/basic/definition.d.ts +23 -23
- package/dts/basic/definition.d.ts.map +1 -1
- package/dts/basic/field-value.d.ts +38 -0
- package/dts/basic/field-value.d.ts.map +1 -0
- package/dts/basic/index.d.ts +2 -2
- package/dts/basic/index.d.ts.map +1 -1
- package/dts/basic/struct-value.d.ts +24 -0
- package/dts/basic/struct-value.d.ts.map +1 -0
- package/dts/index.d.ts +1 -0
- package/dts/index.d.ts.map +1 -1
- package/dts/struct.d.ts +44 -47
- package/dts/struct.d.ts.map +1 -1
- package/dts/syncbird.d.ts +20 -0
- package/dts/syncbird.d.ts.map +1 -0
- package/dts/types/array-buffer.d.ts +22 -20
- package/dts/types/array-buffer.d.ts.map +1 -1
- package/dts/types/fixed-length-array-buffer.d.ts +1 -3
- package/dts/types/fixed-length-array-buffer.d.ts.map +1 -1
- package/dts/types/index.d.ts +0 -1
- package/dts/types/index.d.ts.map +1 -1
- package/dts/types/number.d.ts +11 -10
- package/dts/types/number.d.ts.map +1 -1
- package/dts/types/variable-length-array-buffer.d.ts +21 -19
- package/dts/types/variable-length-array-buffer.d.ts.map +1 -1
- package/dts/{types/utils.d.ts → utils.d.ts} +3 -0
- package/dts/utils.d.ts.map +1 -0
- package/esm/basic/context.js +1 -1
- package/esm/basic/context.js.map +1 -1
- package/esm/basic/definition.js +9 -11
- package/esm/basic/definition.js.map +1 -1
- package/esm/basic/field-value.js +35 -0
- package/esm/basic/field-value.js.map +1 -0
- package/esm/basic/index.js +2 -2
- package/esm/basic/index.js.map +1 -1
- package/esm/basic/struct-value.js +36 -0
- package/esm/basic/struct-value.js.map +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/struct.js +103 -176
- package/esm/struct.js.map +1 -1
- package/esm/syncbird.js +25 -0
- package/esm/syncbird.js.map +1 -0
- package/esm/types/array-buffer.js +83 -107
- package/esm/types/array-buffer.js.map +1 -1
- package/esm/types/fixed-length-array-buffer.js +5 -15
- package/esm/types/fixed-length-array-buffer.js.map +1 -1
- package/esm/types/index.js +0 -1
- package/esm/types/index.js.map +1 -1
- package/esm/types/number.js +35 -53
- package/esm/types/number.js.map +1 -1
- package/esm/types/variable-length-array-buffer.js +57 -68
- package/esm/types/variable-length-array-buffer.js.map +1 -1
- package/esm/utils.js +17 -0
- package/esm/utils.js.map +1 -0
- package/package.json +47 -50
- package/src/basic/context.ts +32 -40
- package/src/basic/definition.ts +72 -69
- package/src/basic/{runtime-value.ts → field-value.ts} +67 -72
- package/src/basic/index.ts +4 -4
- package/src/basic/struct-value.ts +39 -0
- package/src/index.ts +5 -4
- package/src/struct.ts +595 -579
- package/src/syncbird.ts +53 -0
- package/src/types/array-buffer.ts +194 -171
- package/src/types/fixed-length-array-buffer.ts +17 -27
- package/src/types/index.ts +4 -5
- package/src/types/number.ts +114 -101
- package/src/types/variable-length-array-buffer.ts +142 -121
- package/src/{types/utils.ts → utils.ts} +62 -47
- package/cjs/basic/context.js +0 -7
- package/cjs/basic/context.js.map +0 -1
- package/cjs/basic/definition.js +0 -26
- package/cjs/basic/definition.js.map +0 -1
- package/cjs/basic/index.js +0 -8
- package/cjs/basic/index.js.map +0 -1
- package/cjs/basic/runtime-object.js +0 -34
- package/cjs/basic/runtime-object.js.map +0 -1
- package/cjs/basic/runtime-value.js +0 -41
- package/cjs/basic/runtime-value.js.map +0 -1
- package/cjs/index.js +0 -10
- package/cjs/index.js.map +0 -1
- package/cjs/struct.js +0 -259
- package/cjs/struct.js.map +0 -1
- package/cjs/types/array-buffer.js +0 -137
- package/cjs/types/array-buffer.js.map +0 -1
- package/cjs/types/fixed-length-array-buffer.js +0 -21
- package/cjs/types/fixed-length-array-buffer.js.map +0 -1
- package/cjs/types/index.js +0 -9
- package/cjs/types/index.js.map +0 -1
- package/cjs/types/number.js +0 -68
- package/cjs/types/number.js.map +0 -1
- package/cjs/types/utils.js +0 -11
- package/cjs/types/utils.js.map +0 -1
- package/cjs/types/variable-length-array-buffer.js +0 -85
- package/cjs/types/variable-length-array-buffer.js.map +0 -1
- package/dts/basic/runtime-object.d.ts +0 -17
- package/dts/basic/runtime-object.d.ts.map +0 -1
- package/dts/basic/runtime-value.d.ts +0 -39
- package/dts/basic/runtime-value.d.ts.map +0 -1
- package/dts/types/utils.d.ts.map +0 -1
- package/esm/basic/runtime-object.js +0 -28
- package/esm/basic/runtime-object.js.map +0 -1
- package/esm/basic/runtime-value.js +0 -38
- package/esm/basic/runtime-value.js.map +0 -1
- package/esm/types/utils.js +0 -7
- package/esm/types/utils.js.map +0 -1
- package/src/basic/context.spec.ts +0 -9
- package/src/basic/definition.spec.ts +0 -26
- package/src/basic/runtime-object.spec.ts +0 -38
- package/src/basic/runtime-object.ts +0 -36
- package/src/basic/runtime-value.spec.ts +0 -71
- package/src/types/array-buffer.spec.ts +0 -88
- package/src/types/number.spec.ts +0 -262
- package/tsconfig.cjs.json +0 -11
- package/tsconfig.esm.json +0 -15
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setRuntimeValue = exports.getRuntimeValue = exports.createRuntimeObject = void 0;
|
|
4
|
-
var RuntimeValues = Symbol('RuntimeValues');
|
|
5
|
-
/** Creates a new runtime object that can be used with `getRuntimeValue` and `setRuntimeValue` */
|
|
6
|
-
function createRuntimeObject() {
|
|
7
|
-
var _a;
|
|
8
|
-
return _a = {},
|
|
9
|
-
_a[RuntimeValues] = {},
|
|
10
|
-
_a;
|
|
11
|
-
}
|
|
12
|
-
exports.createRuntimeObject = createRuntimeObject;
|
|
13
|
-
/** Gets the previously set `RuntimeValue` for specified `key` on `object` */
|
|
14
|
-
function getRuntimeValue(object, key) {
|
|
15
|
-
return object[RuntimeValues][key];
|
|
16
|
-
}
|
|
17
|
-
exports.getRuntimeValue = getRuntimeValue;
|
|
18
|
-
/**
|
|
19
|
-
* Sets the `RuntimeValue` for specified `key` on `object`,
|
|
20
|
-
* also sets up property accessors so reads/writes to `object`'s `key` will be forwarded to
|
|
21
|
-
* the underlying `RuntimeValue`
|
|
22
|
-
*/
|
|
23
|
-
function setRuntimeValue(object, key, runtimeValue) {
|
|
24
|
-
delete object[key];
|
|
25
|
-
object[RuntimeValues][key] = runtimeValue;
|
|
26
|
-
Object.defineProperty(object, key, {
|
|
27
|
-
configurable: true,
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () { return runtimeValue.get(); },
|
|
30
|
-
set: function (value) { runtimeValue.set(value); },
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
exports.setRuntimeValue = setRuntimeValue;
|
|
34
|
-
//# sourceMappingURL=runtime-object.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-object.js","sourceRoot":"","sources":["../../src/basic/runtime-object.ts"],"names":[],"mappings":";;;AAEA,IAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAM9C,iGAAiG;AACjG,SAAgB,mBAAmB;;IAC/B;QACI,GAAC,aAAa,IAAG,EAAE;WACrB;AACN,CAAC;AAJD,kDAIC;AAED,6EAA6E;AAC7E,SAAgB,eAAe,CAAC,MAAqB,EAAE,GAAgB;IACnE,OAAO,MAAM,CAAC,aAAa,CAAC,CAAC,GAAU,CAAsB,CAAC;AAClE,CAAC;AAFD,0CAEC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,MAAqB,EAAE,GAAgB,EAAE,YAA+B;IACpG,OAAQ,MAAc,CAAC,GAAG,CAAC,CAAC;IAE5B,MAAM,CAAC,aAAa,CAAC,CAAC,GAAU,CAAC,GAAG,YAAY,CAAC;IACjD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;QAC/B,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,IAAI;QAChB,GAAG,gBAAK,OAAO,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACpC,GAAG,YAAC,KAAK,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC1C,CAAC,CAAC;AACP,CAAC;AAVD,0CAUC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FieldRuntimeValue = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Field runtime value manages one field of one `Struct` instance.
|
|
6
|
-
*
|
|
7
|
-
* If one `FieldDefinition` needs to change other field's semantics
|
|
8
|
-
* It can override other fields' `FieldRuntimeValue` in its own `FieldRuntimeValue`'s constructor
|
|
9
|
-
*/
|
|
10
|
-
var FieldRuntimeValue = /** @class */ (function () {
|
|
11
|
-
function FieldRuntimeValue(definition, options, context, object, value) {
|
|
12
|
-
this.definition = definition;
|
|
13
|
-
this.options = options;
|
|
14
|
-
this.context = context;
|
|
15
|
-
this.object = object;
|
|
16
|
-
this.value = value;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Gets the actual size of this field. By default, the return value of its `definition.getSize()`
|
|
20
|
-
*
|
|
21
|
-
* When overridden in derived classes, can have custom logic to calculate the actual size.
|
|
22
|
-
*/
|
|
23
|
-
FieldRuntimeValue.prototype.getSize = function () {
|
|
24
|
-
return this.definition.getSize();
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* When implemented in derived classes, returns the current value of this field
|
|
28
|
-
*/
|
|
29
|
-
FieldRuntimeValue.prototype.get = function () {
|
|
30
|
-
return this.value;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* When implemented in derived classes, update the current value of this field
|
|
34
|
-
*/
|
|
35
|
-
FieldRuntimeValue.prototype.set = function (value) {
|
|
36
|
-
this.value = value;
|
|
37
|
-
};
|
|
38
|
-
return FieldRuntimeValue;
|
|
39
|
-
}());
|
|
40
|
-
exports.FieldRuntimeValue = FieldRuntimeValue;
|
|
41
|
-
//# sourceMappingURL=runtime-value.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-value.js","sourceRoot":"","sources":["../../src/basic/runtime-value.ts"],"names":[],"mappings":";;;AAGA;;;;;GAKG;AACH;IAiBI,2BACI,UAAuB,EACvB,OAAgC,EAChC,OAAmC,EACnC,MAAW,EACX,KAA+B;QAE/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,mCAAO,GAAd;QACI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,+BAAG,GAAV;QACI,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,+BAAG,GAAV,UAAW,KAA+B;QACtC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAUL,wBAAC;AAAD,CAAC,AA9DD,IA8DC;AA9DqB,8CAAiB"}
|
package/cjs/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./basic"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./struct"), exports);
|
|
7
|
-
var struct_1 = require("./struct");
|
|
8
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return struct_1.Struct; } });
|
|
9
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,kDAAwB;AACxB,mDAAyB;AACzB,mCAA6C;AAApC,iGAAA,MAAM,OAAW;AAC1B,kDAAwB"}
|
package/cjs/struct.js
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Struct = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var basic_1 = require("./basic");
|
|
6
|
-
var types_1 = require("./types");
|
|
7
|
-
var Struct = /** @class */ (function () {
|
|
8
|
-
function Struct(options) {
|
|
9
|
-
var _this = this;
|
|
10
|
-
this._size = 0;
|
|
11
|
-
this._fields = [];
|
|
12
|
-
this._extra = {};
|
|
13
|
-
this.arrayBufferLike = function (name, type, options) {
|
|
14
|
-
if ('length' in options) {
|
|
15
|
-
return _this.field(name, new types_1.FixedLengthArrayBufferLikeFieldDefinition(type, options));
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return _this.field(name, new types_1.VariableLengthArrayBufferLikeFieldDefinition(type, options));
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
this.arrayBuffer = function (name, options) {
|
|
22
|
-
return _this.arrayBufferLike(name, types_1.ArrayBufferFieldType.instance, options);
|
|
23
|
-
};
|
|
24
|
-
this.uint8ClampedArray = function (name, options) {
|
|
25
|
-
return _this.arrayBufferLike(name, types_1.Uint8ClampedArrayFieldType.instance, options);
|
|
26
|
-
};
|
|
27
|
-
this.string = function (name, options) {
|
|
28
|
-
return _this.arrayBufferLike(name, types_1.StringFieldType.instance, options);
|
|
29
|
-
};
|
|
30
|
-
this.options = tslib_1.__assign(tslib_1.__assign({}, basic_1.StructDefaultOptions), options);
|
|
31
|
-
}
|
|
32
|
-
Object.defineProperty(Struct.prototype, "size", {
|
|
33
|
-
/**
|
|
34
|
-
* Gets the static size (exclude fields that can change size at runtime)
|
|
35
|
-
*/
|
|
36
|
-
get: function () { return this._size; },
|
|
37
|
-
enumerable: false,
|
|
38
|
-
configurable: true
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* Appends a `FieldDefinition` to the `Struct
|
|
42
|
-
*/
|
|
43
|
-
Struct.prototype.field = function (name, definition) {
|
|
44
|
-
this._fields.push([name, definition]);
|
|
45
|
-
var size = definition.getSize();
|
|
46
|
-
this._size += size;
|
|
47
|
-
// Force cast `this` to another type
|
|
48
|
-
return this;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Merges (flats) another `Struct`'s fields and extra fields into this one.
|
|
52
|
-
*/
|
|
53
|
-
Struct.prototype.fields = function (other) {
|
|
54
|
-
var e_1, _a;
|
|
55
|
-
try {
|
|
56
|
-
for (var _b = tslib_1.__values(other._fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
57
|
-
var field = _c.value;
|
|
58
|
-
this._fields.push(field);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
62
|
-
finally {
|
|
63
|
-
try {
|
|
64
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
65
|
-
}
|
|
66
|
-
finally { if (e_1) throw e_1.error; }
|
|
67
|
-
}
|
|
68
|
-
this._size += other._size;
|
|
69
|
-
Object.assign(this._extra, other._extra);
|
|
70
|
-
return this;
|
|
71
|
-
};
|
|
72
|
-
Struct.prototype.number = function (name, type, _typescriptType) {
|
|
73
|
-
return this.field(name, new types_1.NumberFieldDefinition(type, _typescriptType));
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Appends an `int8` field to the `Struct`
|
|
77
|
-
*/
|
|
78
|
-
Struct.prototype.int8 = function (name, _typescriptType) {
|
|
79
|
-
return this.number(name, types_1.NumberFieldType.Int8, _typescriptType);
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Appends an `uint8` field to the `Struct`
|
|
83
|
-
*/
|
|
84
|
-
Struct.prototype.uint8 = function (name, _typescriptType) {
|
|
85
|
-
return this.number(name, types_1.NumberFieldType.Uint8, _typescriptType);
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Appends an `int16` field to the `Struct`
|
|
89
|
-
*/
|
|
90
|
-
Struct.prototype.int16 = function (name, _typescriptType) {
|
|
91
|
-
return this.number(name, types_1.NumberFieldType.Int16, _typescriptType);
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Appends an `uint16` field to the `Struct`
|
|
95
|
-
*/
|
|
96
|
-
Struct.prototype.uint16 = function (name, _typescriptType) {
|
|
97
|
-
return this.number(name, types_1.NumberFieldType.Uint16, _typescriptType);
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Appends an `int32` field to the `Struct`
|
|
101
|
-
*/
|
|
102
|
-
Struct.prototype.int32 = function (name, _typescriptType) {
|
|
103
|
-
return this.number(name, types_1.NumberFieldType.Int32, _typescriptType);
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Appends an `uint32` field to the `Struct`
|
|
107
|
-
*/
|
|
108
|
-
Struct.prototype.uint32 = function (name, typescriptType) {
|
|
109
|
-
return this.number(name, types_1.NumberFieldType.Uint32, typescriptType);
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Appends an `int64` field to the `Struct`
|
|
113
|
-
*
|
|
114
|
-
* Requires native `BigInt` support
|
|
115
|
-
*/
|
|
116
|
-
Struct.prototype.int64 = function (name, _typescriptType) {
|
|
117
|
-
return this.number(name, types_1.NumberFieldType.Int64, _typescriptType);
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Appends an `uint64` field to the `Struct`
|
|
121
|
-
*
|
|
122
|
-
* Requires native `BigInt` support
|
|
123
|
-
*/
|
|
124
|
-
Struct.prototype.uint64 = function (name, _typescriptType) {
|
|
125
|
-
return this.number(name, types_1.NumberFieldType.Uint64, _typescriptType);
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* Adds some extra fields into every Struct value.
|
|
129
|
-
*
|
|
130
|
-
* Extra fields will not affect serialize or deserialize process.
|
|
131
|
-
*
|
|
132
|
-
* Multiple calls to `extra` will merge all values together.
|
|
133
|
-
*
|
|
134
|
-
* @param value
|
|
135
|
-
* An object containing anything you want to add to the result object. Accessors and methods are also allowed.
|
|
136
|
-
*/
|
|
137
|
-
Struct.prototype.extra = function (value) {
|
|
138
|
-
Object.assign(this._extra, Object.getOwnPropertyDescriptors(value));
|
|
139
|
-
return this;
|
|
140
|
-
};
|
|
141
|
-
Struct.prototype.postDeserialize = function (callback) {
|
|
142
|
-
this._postDeserialized = callback;
|
|
143
|
-
return this;
|
|
144
|
-
};
|
|
145
|
-
Struct.prototype.initializeObject = function () {
|
|
146
|
-
var object = basic_1.createRuntimeObject();
|
|
147
|
-
Object.defineProperties(object, this._extra);
|
|
148
|
-
return object;
|
|
149
|
-
};
|
|
150
|
-
Struct.prototype.create = function (init, context) {
|
|
151
|
-
var e_2, _a;
|
|
152
|
-
var object = this.initializeObject();
|
|
153
|
-
try {
|
|
154
|
-
for (var _b = tslib_1.__values(this._fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
155
|
-
var _d = tslib_1.__read(_c.value, 2), name = _d[0], definition = _d[1];
|
|
156
|
-
var runtimeValue = definition.createValue(this.options, context, object, init[name]);
|
|
157
|
-
basic_1.setRuntimeValue(object, name, runtimeValue);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
161
|
-
finally {
|
|
162
|
-
try {
|
|
163
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
164
|
-
}
|
|
165
|
-
finally { if (e_2) throw e_2.error; }
|
|
166
|
-
}
|
|
167
|
-
return object;
|
|
168
|
-
};
|
|
169
|
-
Struct.prototype.deserialize = function (context) {
|
|
170
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
171
|
-
var object, _a, _b, _c, name, definition, runtimeValue, e_3_1, result;
|
|
172
|
-
var e_3, _d;
|
|
173
|
-
return tslib_1.__generator(this, function (_e) {
|
|
174
|
-
switch (_e.label) {
|
|
175
|
-
case 0:
|
|
176
|
-
object = this.initializeObject();
|
|
177
|
-
_e.label = 1;
|
|
178
|
-
case 1:
|
|
179
|
-
_e.trys.push([1, 6, 7, 8]);
|
|
180
|
-
_a = tslib_1.__values(this._fields), _b = _a.next();
|
|
181
|
-
_e.label = 2;
|
|
182
|
-
case 2:
|
|
183
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
184
|
-
_c = tslib_1.__read(_b.value, 2), name = _c[0], definition = _c[1];
|
|
185
|
-
return [4 /*yield*/, definition.deserialize(this.options, context, object)];
|
|
186
|
-
case 3:
|
|
187
|
-
runtimeValue = _e.sent();
|
|
188
|
-
basic_1.setRuntimeValue(object, name, runtimeValue);
|
|
189
|
-
_e.label = 4;
|
|
190
|
-
case 4:
|
|
191
|
-
_b = _a.next();
|
|
192
|
-
return [3 /*break*/, 2];
|
|
193
|
-
case 5: return [3 /*break*/, 8];
|
|
194
|
-
case 6:
|
|
195
|
-
e_3_1 = _e.sent();
|
|
196
|
-
e_3 = { error: e_3_1 };
|
|
197
|
-
return [3 /*break*/, 8];
|
|
198
|
-
case 7:
|
|
199
|
-
try {
|
|
200
|
-
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
201
|
-
}
|
|
202
|
-
finally { if (e_3) throw e_3.error; }
|
|
203
|
-
return [7 /*endfinally*/];
|
|
204
|
-
case 8:
|
|
205
|
-
if (this._postDeserialized) {
|
|
206
|
-
result = this._postDeserialized.call(object, object);
|
|
207
|
-
if (result) {
|
|
208
|
-
return [2 /*return*/, result];
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return [2 /*return*/, object];
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
Struct.prototype.serialize = function (init, context) {
|
|
217
|
-
var e_4, _a, e_5, _b;
|
|
218
|
-
var object = this.create(init, context);
|
|
219
|
-
var structSize = 0;
|
|
220
|
-
var fieldsInfo = [];
|
|
221
|
-
try {
|
|
222
|
-
for (var _c = tslib_1.__values(this._fields), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
223
|
-
var _e = tslib_1.__read(_d.value, 1), name = _e[0];
|
|
224
|
-
var runtimeValue = basic_1.getRuntimeValue(object, name);
|
|
225
|
-
var size = runtimeValue.getSize();
|
|
226
|
-
fieldsInfo.push({ runtimeValue: runtimeValue, size: size });
|
|
227
|
-
structSize += size;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
231
|
-
finally {
|
|
232
|
-
try {
|
|
233
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
234
|
-
}
|
|
235
|
-
finally { if (e_4) throw e_4.error; }
|
|
236
|
-
}
|
|
237
|
-
var buffer = new ArrayBuffer(structSize);
|
|
238
|
-
var dataView = new DataView(buffer);
|
|
239
|
-
var offset = 0;
|
|
240
|
-
try {
|
|
241
|
-
for (var fieldsInfo_1 = tslib_1.__values(fieldsInfo), fieldsInfo_1_1 = fieldsInfo_1.next(); !fieldsInfo_1_1.done; fieldsInfo_1_1 = fieldsInfo_1.next()) {
|
|
242
|
-
var _f = fieldsInfo_1_1.value, runtimeValue = _f.runtimeValue, size = _f.size;
|
|
243
|
-
runtimeValue.serialize(dataView, offset, context);
|
|
244
|
-
offset += size;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
248
|
-
finally {
|
|
249
|
-
try {
|
|
250
|
-
if (fieldsInfo_1_1 && !fieldsInfo_1_1.done && (_b = fieldsInfo_1.return)) _b.call(fieldsInfo_1);
|
|
251
|
-
}
|
|
252
|
-
finally { if (e_5) throw e_5.error; }
|
|
253
|
-
}
|
|
254
|
-
return buffer;
|
|
255
|
-
};
|
|
256
|
-
return Struct;
|
|
257
|
-
}());
|
|
258
|
-
exports.Struct = Struct;
|
|
259
|
-
//# sourceMappingURL=struct.js.map
|
package/cjs/struct.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"struct.js","sourceRoot":"","sources":["../src/struct.ts"],"names":[],"mappings":";;;;AAAA,iCAAmN;AACnN,iCAAqX;AA8JrX;IA8BI,gBAAmB,OAAgC;QAAnD,iBAEC;QAdO,UAAK,GAAG,CAAC,CAAC;QAMV,YAAO,GAAsE,EAAE,CAAC;QAEhF,WAAM,GAA0B,EAAE,CAAC;QAgNnC,oBAAe,GAKnB,UACA,IAAiB,EACjB,IAA8B,EAC9B,OAA2F;YAEvF,IAAI,QAAQ,IAAI,OAAO,EAAE;gBACrB,OAAO,KAAI,CAAC,KAAK,CACb,IAAI,EACJ,IAAI,iDAAyC,CAAC,IAAI,EAAE,OAAO,CAAC,CAC/D,CAAC;aACL;iBAAM;gBACH,OAAO,KAAI,CAAC,KAAK,CACb,IAAI,EACJ,IAAI,oDAA4C,CAAC,IAAI,EAAE,OAAO,CAAC,CAClE,CAAC;aACL;QACL,CAAC,CAAC;QAEC,gBAAW,GAMd,UACA,IAAiB,EACjB,OAAY;YAER,OAAO,KAAI,CAAC,eAAe,CAAC,IAAI,EAAE,4BAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9E,CAAC,CAAC;QAEC,sBAAiB,GAMpB,UACA,IAAiB,EACjB,OAAY;YAER,OAAO,KAAI,CAAC,eAAe,CAAC,IAAI,EAAE,kCAA0B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACpF,CA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,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBAClD,MAAM,IAAI,IAAI,CAAC;aAClB;;;;;;;;;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IACL,aAAC;AAAD,CAAC,AAnaD,IAmaC;AAnaY,wBAAM"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArrayBufferLikeFieldRuntimeValue = exports.ArrayBufferLikeFieldDefinition = exports.StringFieldType = exports.Uint8ClampedArrayFieldType = exports.ArrayBufferFieldType = exports.ArrayBufferLikeFieldType = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var basic_1 = require("../basic");
|
|
6
|
-
/**
|
|
7
|
-
* Base class for all types that
|
|
8
|
-
* can be converted from an ArrayBuffer when deserialized,
|
|
9
|
-
* and need to be converted to an ArrayBuffer when serializing
|
|
10
|
-
*
|
|
11
|
-
* @template TType The actual TypeScript type of this type
|
|
12
|
-
* @template TTypeScriptType Optional another type (should be compatible with `TType`)
|
|
13
|
-
* specified by user when creating field definitions.
|
|
14
|
-
*/
|
|
15
|
-
var ArrayBufferLikeFieldType = /** @class */ (function () {
|
|
16
|
-
function ArrayBufferLikeFieldType() {
|
|
17
|
-
}
|
|
18
|
-
return ArrayBufferLikeFieldType;
|
|
19
|
-
}());
|
|
20
|
-
exports.ArrayBufferLikeFieldType = ArrayBufferLikeFieldType;
|
|
21
|
-
/** An ArrayBufferLike type that's actually an `ArrayBuffer` */
|
|
22
|
-
var ArrayBufferFieldType = /** @class */ (function (_super) {
|
|
23
|
-
tslib_1.__extends(ArrayBufferFieldType, _super);
|
|
24
|
-
function ArrayBufferFieldType() {
|
|
25
|
-
return _super.call(this) || this;
|
|
26
|
-
}
|
|
27
|
-
ArrayBufferFieldType.prototype.toArrayBuffer = function (value) {
|
|
28
|
-
return value;
|
|
29
|
-
};
|
|
30
|
-
ArrayBufferFieldType.prototype.fromArrayBuffer = function (arrayBuffer) {
|
|
31
|
-
return arrayBuffer;
|
|
32
|
-
};
|
|
33
|
-
ArrayBufferFieldType.prototype.getSize = function (value) {
|
|
34
|
-
return value.byteLength;
|
|
35
|
-
};
|
|
36
|
-
ArrayBufferFieldType.instance = new ArrayBufferFieldType();
|
|
37
|
-
return ArrayBufferFieldType;
|
|
38
|
-
}(ArrayBufferLikeFieldType));
|
|
39
|
-
exports.ArrayBufferFieldType = ArrayBufferFieldType;
|
|
40
|
-
/** Am ArrayBufferLike type that converts to/from the `ArrayBuffer` from/to a `Uint8ClampedArray` */
|
|
41
|
-
var Uint8ClampedArrayFieldType = /** @class */ (function (_super) {
|
|
42
|
-
tslib_1.__extends(Uint8ClampedArrayFieldType, _super);
|
|
43
|
-
function Uint8ClampedArrayFieldType() {
|
|
44
|
-
return _super.call(this) || this;
|
|
45
|
-
}
|
|
46
|
-
Uint8ClampedArrayFieldType.prototype.toArrayBuffer = function (value) {
|
|
47
|
-
return value.buffer;
|
|
48
|
-
};
|
|
49
|
-
Uint8ClampedArrayFieldType.prototype.fromArrayBuffer = function (arrayBuffer) {
|
|
50
|
-
return new Uint8ClampedArray(arrayBuffer);
|
|
51
|
-
};
|
|
52
|
-
Uint8ClampedArrayFieldType.prototype.getSize = function (value) {
|
|
53
|
-
return value.byteLength;
|
|
54
|
-
};
|
|
55
|
-
Uint8ClampedArrayFieldType.instance = new Uint8ClampedArrayFieldType();
|
|
56
|
-
return Uint8ClampedArrayFieldType;
|
|
57
|
-
}(ArrayBufferLikeFieldType));
|
|
58
|
-
exports.Uint8ClampedArrayFieldType = Uint8ClampedArrayFieldType;
|
|
59
|
-
/** Am ArrayBufferLike type that converts to/from the `ArrayBuffer` from/to a `string` */
|
|
60
|
-
var StringFieldType = /** @class */ (function (_super) {
|
|
61
|
-
tslib_1.__extends(StringFieldType, _super);
|
|
62
|
-
function StringFieldType() {
|
|
63
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
64
|
-
}
|
|
65
|
-
StringFieldType.prototype.toArrayBuffer = function (value, context) {
|
|
66
|
-
return context.encodeUtf8(value);
|
|
67
|
-
};
|
|
68
|
-
StringFieldType.prototype.fromArrayBuffer = function (arrayBuffer, context) {
|
|
69
|
-
return context.decodeUtf8(arrayBuffer);
|
|
70
|
-
};
|
|
71
|
-
StringFieldType.prototype.getSize = function () {
|
|
72
|
-
// Return `-1`, so `ArrayBufferLikeFieldDefinition` will
|
|
73
|
-
// convert this `value` into an `ArrayBuffer` (and cache the result),
|
|
74
|
-
// Then get the size from that `ArrayBuffer`
|
|
75
|
-
return -1;
|
|
76
|
-
};
|
|
77
|
-
StringFieldType.instance = new StringFieldType();
|
|
78
|
-
return StringFieldType;
|
|
79
|
-
}(ArrayBufferLikeFieldType));
|
|
80
|
-
exports.StringFieldType = StringFieldType;
|
|
81
|
-
var EmptyArrayBuffer = new ArrayBuffer(0);
|
|
82
|
-
var ArrayBufferLikeFieldDefinition = /** @class */ (function (_super) {
|
|
83
|
-
tslib_1.__extends(ArrayBufferLikeFieldDefinition, _super);
|
|
84
|
-
function ArrayBufferLikeFieldDefinition(type, options) {
|
|
85
|
-
var _this = _super.call(this, options) || this;
|
|
86
|
-
_this.type = type;
|
|
87
|
-
return _this;
|
|
88
|
-
}
|
|
89
|
-
ArrayBufferLikeFieldDefinition.prototype.getDeserializeSize = function (object) {
|
|
90
|
-
return this.getSize();
|
|
91
|
-
};
|
|
92
|
-
ArrayBufferLikeFieldDefinition.prototype.deserialize = function (options, context, object) {
|
|
93
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
94
|
-
var size, arrayBuffer, value, runtimeValue;
|
|
95
|
-
return tslib_1.__generator(this, function (_a) {
|
|
96
|
-
switch (_a.label) {
|
|
97
|
-
case 0:
|
|
98
|
-
size = this.getDeserializeSize(object);
|
|
99
|
-
if (!(size === 0)) return [3 /*break*/, 1];
|
|
100
|
-
arrayBuffer = EmptyArrayBuffer;
|
|
101
|
-
return [3 /*break*/, 3];
|
|
102
|
-
case 1: return [4 /*yield*/, context.read(size)];
|
|
103
|
-
case 2:
|
|
104
|
-
arrayBuffer = _a.sent();
|
|
105
|
-
_a.label = 3;
|
|
106
|
-
case 3:
|
|
107
|
-
value = this.type.fromArrayBuffer(arrayBuffer, context);
|
|
108
|
-
runtimeValue = this.createValue(options, context, object, value);
|
|
109
|
-
runtimeValue.arrayBuffer = arrayBuffer;
|
|
110
|
-
return [2 /*return*/, runtimeValue];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
return ArrayBufferLikeFieldDefinition;
|
|
116
|
-
}(basic_1.FieldDefinition));
|
|
117
|
-
exports.ArrayBufferLikeFieldDefinition = ArrayBufferLikeFieldDefinition;
|
|
118
|
-
var ArrayBufferLikeFieldRuntimeValue = /** @class */ (function (_super) {
|
|
119
|
-
tslib_1.__extends(ArrayBufferLikeFieldRuntimeValue, _super);
|
|
120
|
-
function ArrayBufferLikeFieldRuntimeValue() {
|
|
121
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
122
|
-
}
|
|
123
|
-
ArrayBufferLikeFieldRuntimeValue.prototype.set = function (value) {
|
|
124
|
-
_super.prototype.set.call(this, value);
|
|
125
|
-
this.arrayBuffer = undefined;
|
|
126
|
-
};
|
|
127
|
-
ArrayBufferLikeFieldRuntimeValue.prototype.serialize = function (dataView, offset, context) {
|
|
128
|
-
if (!this.arrayBuffer) {
|
|
129
|
-
this.arrayBuffer = this.definition.type.toArrayBuffer(this.value, context);
|
|
130
|
-
}
|
|
131
|
-
new Uint8Array(dataView.buffer)
|
|
132
|
-
.set(new Uint8Array(this.arrayBuffer), offset);
|
|
133
|
-
};
|
|
134
|
-
return ArrayBufferLikeFieldRuntimeValue;
|
|
135
|
-
}(basic_1.FieldRuntimeValue));
|
|
136
|
-
exports.ArrayBufferLikeFieldRuntimeValue = ArrayBufferLikeFieldRuntimeValue;
|
|
137
|
-
//# sourceMappingURL=array-buffer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array-buffer.js","sourceRoot":"","sources":["../../src/types/array-buffer.ts"],"names":[],"mappings":";;;;AAAA,kCAAuI;AAEvI;;;;;;;;GAQG;AACH;IAAA;IAsBA,CAAC;IAAD,+BAAC;AAAD,CAAC,AAtBD,IAsBC;AAtBqB,4DAAwB;AAwB9C,+DAA+D;AAC/D;IAA0C,gDAAqC;IAG3E;eACI,iBAAO;IACX,CAAC;IAEM,4CAAa,GAApB,UAAqB,KAAkB;QACnC,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,8CAAe,GAAtB,UAAuB,WAAwB;QAC3C,OAAO,WAAW,CAAC;IACvB,CAAC;IAEM,sCAAO,GAAd,UAAe,KAAkB;QAC7B,OAAO,KAAK,CAAC,UAAU,CAAC;IAC5B,CAAC;IAhBsB,6BAAQ,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAiBjE,2BAAC;CAAA,AAlBD,CAA0C,wBAAwB,GAkBjE;AAlBY,oDAAoB;AAoBjC,oGAAoG;AACpG;IACY,sDAA8D;IAGtE;eACI,iBAAO;IACX,CAAC;IAEM,kDAAa,GAApB,UAAqB,KAAwB;QACzC,OAAO,KAAK,CAAC,MAAM,CAAC;IACxB,CAAC;IAEM,oDAAe,GAAtB,UAAuB,WAAwB;QAC3C,OAAO,IAAI,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAEM,4CAAO,GAAd,UAAe,KAAwB;QACnC,OAAO,KAAK,CAAC,UAAU,CAAC;IAC5B,CAAC;IAhBsB,mCAAQ,GAAG,IAAI,0BAA0B,EAAE,CAAC;IAiBvE,iCAAC;CAAA,AAnBD,CACY,wBAAwB,GAkBnC;AAnBY,gEAA0B;AAqBvC,yFAAyF;AACzF;IACY,2CAAiD;IAD7D;;IAkBA,CAAC;IAdU,uCAAa,GAApB,UAAqB,KAAa,EAAE,OAAmC;QACnE,OAAO,OAAO,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Y,EAAC;;;;KACvB;IAWL,qCAAC;AAAD,CAAC,AAjDD,CAIc,uBAAe,GA6C5B;AAjDqB,wEAA8B;AAmDpD;IAEc,4DAA8B;IAF5C;;IAkBA,CAAC;IAbU,8CAAG,GAAV,UAAW,KAA+B;QACtC,iBAAM,GAAG,YAAC,KAAK,CAAC,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IACjC,CAAC;IAEM,oDAAS,GAAhB,UAAiB,QAAkB,EAAE,MAAc,EAAE,OAAmC;QACpF,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SAC9E;QAED,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC;aAC1B,GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,WAAY,CAAC,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IACL,uCAAC;AAAD,CAAC,AAlBD,CAEc,yBAAiB,GAgB9B;AAlBY,4EAAgC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FixedLengthArrayBufferLikeFieldDefinition = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var array_buffer_1 = require("./array-buffer");
|
|
6
|
-
var FixedLengthArrayBufferLikeFieldDefinition = /** @class */ (function (_super) {
|
|
7
|
-
tslib_1.__extends(FixedLengthArrayBufferLikeFieldDefinition, _super);
|
|
8
|
-
function FixedLengthArrayBufferLikeFieldDefinition() {
|
|
9
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
10
|
-
}
|
|
11
|
-
FixedLengthArrayBufferLikeFieldDefinition.prototype.getSize = function () {
|
|
12
|
-
return this.options.length;
|
|
13
|
-
};
|
|
14
|
-
FixedLengthArrayBufferLikeFieldDefinition.prototype.createValue = function (options, context, object, value) {
|
|
15
|
-
return new array_buffer_1.ArrayBufferLikeFieldRuntimeValue(this, options, context, object, value);
|
|
16
|
-
};
|
|
17
|
-
return FixedLengthArrayBufferLikeFieldDefinition;
|
|
18
|
-
}(array_buffer_1.ArrayBufferLikeFieldDefinition));
|
|
19
|
-
exports.FixedLengthArrayBufferLikeFieldDefinition = FixedLengthArrayBufferLikeFieldDefinition;
|
|
20
|
-
;
|
|
21
|
-
//# sourceMappingURL=fixed-length-array-buffer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fixed-length-array-buffer.js","sourceRoot":"","sources":["../../src/types/fixed-length-array-buffer.ts"],"names":[],"mappings":";;;;AACA,+CAA4H;AAM5H;IAGc,qEAGT;IANL;;IAmBA,CAAC;IAZU,2DAAO,GAAd;QACI,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAEM,+DAAW,GAAlB,UACI,OAAgC,EAChC,OAAmC,EACnC,MAAW,EACX,KAAyB;QAEzB,OAAO,IAAI,+CAAgC,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACvF,CAAC;IACL,gDAAC;AAAD,CAAC,AAnBD,CAGc,6CAA8B,GAgB3C;AAnBY,8FAAyC;AAmBrD,CAAC"}
|
package/cjs/types/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./array-buffer"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./fixed-length-array-buffer"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./number"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./utils"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./variable-length-array-buffer"), exports);
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/cjs/types/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,sEAA4C;AAC5C,mDAAyB;AACzB,kDAAwB;AACxB,yEAA+C"}
|
package/cjs/types/number.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NumberFieldRuntimeValue = exports.NumberFieldDefinition = exports.NumberFieldType = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var basic_1 = require("../basic");
|
|
6
|
-
var NumberFieldType = /** @class */ (function () {
|
|
7
|
-
function NumberFieldType(size, dataViewGetter, dataViewSetter) {
|
|
8
|
-
this.size = size;
|
|
9
|
-
this.dataViewGetter = dataViewGetter;
|
|
10
|
-
this.dataViewSetter = dataViewSetter;
|
|
11
|
-
}
|
|
12
|
-
NumberFieldType.Int8 = new NumberFieldType(1, 'getInt8', 'setInt8');
|
|
13
|
-
NumberFieldType.Uint8 = new NumberFieldType(1, 'getUint8', 'setUint8');
|
|
14
|
-
NumberFieldType.Int16 = new NumberFieldType(2, 'getInt16', 'setInt16');
|
|
15
|
-
NumberFieldType.Uint16 = new NumberFieldType(2, 'getUint16', 'setUint16');
|
|
16
|
-
NumberFieldType.Int32 = new NumberFieldType(4, 'getInt32', 'setInt32');
|
|
17
|
-
NumberFieldType.Uint32 = new NumberFieldType(4, 'getUint32', 'setUint32');
|
|
18
|
-
NumberFieldType.Int64 = new NumberFieldType(8, 'getBigInt64', 'setBigInt64');
|
|
19
|
-
NumberFieldType.Uint64 = new NumberFieldType(8, 'getBigUint64', 'setBigUint64');
|
|
20
|
-
return NumberFieldType;
|
|
21
|
-
}());
|
|
22
|
-
exports.NumberFieldType = NumberFieldType;
|
|
23
|
-
var NumberFieldDefinition = /** @class */ (function (_super) {
|
|
24
|
-
tslib_1.__extends(NumberFieldDefinition, _super);
|
|
25
|
-
function NumberFieldDefinition(type, _typescriptType) {
|
|
26
|
-
var _this = _super.call(this) || this;
|
|
27
|
-
_this.type = type;
|
|
28
|
-
return _this;
|
|
29
|
-
}
|
|
30
|
-
NumberFieldDefinition.prototype.getSize = function () {
|
|
31
|
-
return this.type.size;
|
|
32
|
-
};
|
|
33
|
-
NumberFieldDefinition.prototype.deserialize = function (options, context, object) {
|
|
34
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
35
|
-
var buffer, view, value;
|
|
36
|
-
return tslib_1.__generator(this, function (_a) {
|
|
37
|
-
switch (_a.label) {
|
|
38
|
-
case 0: return [4 /*yield*/, context.read(this.getSize())];
|
|
39
|
-
case 1:
|
|
40
|
-
buffer = _a.sent();
|
|
41
|
-
view = new DataView(buffer);
|
|
42
|
-
value = view[this.type.dataViewGetter](0, options.littleEndian);
|
|
43
|
-
return [2 /*return*/, this.createValue(options, context, object, value)];
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
NumberFieldDefinition.prototype.createValue = function (options, context, object, value) {
|
|
49
|
-
return new NumberFieldRuntimeValue(this, options, context, object, value);
|
|
50
|
-
};
|
|
51
|
-
return NumberFieldDefinition;
|
|
52
|
-
}(basic_1.FieldDefinition));
|
|
53
|
-
exports.NumberFieldDefinition = NumberFieldDefinition;
|
|
54
|
-
var NumberFieldRuntimeValue = /** @class */ (function (_super) {
|
|
55
|
-
tslib_1.__extends(NumberFieldRuntimeValue, _super);
|
|
56
|
-
function NumberFieldRuntimeValue() {
|
|
57
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
58
|
-
}
|
|
59
|
-
NumberFieldRuntimeValue.prototype.serialize = function (dataView, offset) {
|
|
60
|
-
// `setBigInt64` requires a `bigint` while others require `number`
|
|
61
|
-
// So `dataView[DataViewSetters]` requires `bigint & number`
|
|
62
|
-
// and that is, `never`
|
|
63
|
-
dataView[this.definition.type.dataViewSetter](offset, this.value, this.options.littleEndian);
|
|
64
|
-
};
|
|
65
|
-
return NumberFieldRuntimeValue;
|
|
66
|
-
}(basic_1.FieldRuntimeValue));
|
|
67
|
-
exports.NumberFieldRuntimeValue = NumberFieldRuntimeValue;
|
|
68
|
-
//# sourceMappingURL=number.js.map
|
package/cjs/types/number.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/types/number.ts"],"names":[],"mappings":";;;;AAAA,kCAAuI;AAQvI;IAyBI,yBACI,IAAY,EACZ,cAA+B,EAC/B,cAA+B;QAE/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAhCsB,oBAAI,GAAG,IAAI,eAAe,CAAS,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAE5D,qBAAK,GAAG,IAAI,eAAe,CAAS,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE/D,qBAAK,GAAG,IAAI,eAAe,CAAS,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE/D,sBAAM,GAAG,IAAI,eAAe,CAAS,CAAC,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IAElE,qBAAK,GAAG,IAAI,eAAe,CAAS,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE/D,sBAAM,GAAG,IAAI,eAAe,CAAS,CAAC,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IAElE,qBAAK,GAAG,IAAI,eAAe,CAAS,CAAC,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IAErE,sBAAM,GAAG,IAAI,eAAe,CAAS,CAAC,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;IAmBnG,sBAAC;CAAA,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;IACL,8BAAC;AAAD,CAAC,AAdD,CAGc,yBAAiB,GAW9B;AAdY,0DAAuB"}
|
package/cjs/types/utils.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.placeholder = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Returns a (fake) value of the given type.
|
|
6
|
-
*/
|
|
7
|
-
function placeholder() {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
exports.placeholder = placeholder;
|
|
11
|
-
//# sourceMappingURL=utils.js.map
|
package/cjs/types/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/types/utils.ts"],"names":[],"mappings":";;;AAyCA;;GAEG;AACH,SAAgB,WAAW;IACvB,OAAO,SAAyB,CAAC;AACrC,CAAC;AAFD,kCAEC"}
|