utilium 1.7.8 → 1.7.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/dist/struct.js +6 -3
- package/package.json +1 -1
- package/src/struct.ts +7 -3
package/dist/struct.js
CHANGED
@@ -91,7 +91,10 @@ export function struct(options = {}) {
|
|
91
91
|
}
|
92
92
|
context.metadata.struct = { options, members, staticSize };
|
93
93
|
context.addInitializer(function () {
|
94
|
-
this
|
94
|
+
Object.defineProperty(this.prototype, Symbol.size, {
|
95
|
+
get: _structSize.bind(this),
|
96
|
+
enumerable: false,
|
97
|
+
});
|
95
98
|
});
|
96
99
|
return target;
|
97
100
|
};
|
@@ -119,7 +122,7 @@ export function member(type, length) {
|
|
119
122
|
* Serializes a struct into a Uint8Array
|
120
123
|
*/
|
121
124
|
export function serialize(instance) {
|
122
|
-
if (isCustom(instance))
|
125
|
+
if (isCustom(instance) && typeof instance[Symbol.serialize] == 'function')
|
123
126
|
return instance[Symbol.serialize]();
|
124
127
|
checkInstance(instance);
|
125
128
|
const { options, members } = instance.constructor[symbol_metadata(instance.constructor)].struct;
|
@@ -172,7 +175,7 @@ export function serialize(instance) {
|
|
172
175
|
*/
|
173
176
|
export function deserialize(instance, _buffer) {
|
174
177
|
const buffer = toUint8Array(_buffer);
|
175
|
-
if (isCustom(instance))
|
178
|
+
if (isCustom(instance) && typeof instance[Symbol.deserialize] == 'function')
|
176
179
|
return instance[Symbol.deserialize](buffer);
|
177
180
|
checkInstance(instance);
|
178
181
|
const { options, members } = instance.constructor[symbol_metadata(instance.constructor)].struct;
|
package/package.json
CHANGED
package/src/struct.ts
CHANGED
@@ -130,7 +130,10 @@ export function struct(options: Partial<Options> = {}) {
|
|
130
130
|
context.metadata.struct = { options, members, staticSize } satisfies Metadata;
|
131
131
|
|
132
132
|
context.addInitializer(function (this: any) {
|
133
|
-
this
|
133
|
+
Object.defineProperty(this.prototype, Symbol.size, {
|
134
|
+
get: _structSize.bind(this),
|
135
|
+
enumerable: false,
|
136
|
+
});
|
134
137
|
});
|
135
138
|
|
136
139
|
return target;
|
@@ -162,7 +165,7 @@ export function member(type: primitive.Valid | ClassLike, length?: number | stri
|
|
162
165
|
* Serializes a struct into a Uint8Array
|
163
166
|
*/
|
164
167
|
export function serialize(instance: unknown): Uint8Array {
|
165
|
-
if (isCustom(instance)) return instance[Symbol.serialize]!();
|
168
|
+
if (isCustom(instance) && typeof instance[Symbol.serialize] == 'function') return instance[Symbol.serialize]!();
|
166
169
|
|
167
170
|
checkInstance(instance);
|
168
171
|
const { options, members } = instance.constructor[symbol_metadata(instance.constructor)].struct;
|
@@ -229,7 +232,8 @@ export function serialize(instance: unknown): Uint8Array {
|
|
229
232
|
export function deserialize(instance: unknown, _buffer: ArrayBufferLike | ArrayBufferView) {
|
230
233
|
const buffer = toUint8Array(_buffer);
|
231
234
|
|
232
|
-
if (isCustom(instance)
|
235
|
+
if (isCustom(instance) && typeof instance[Symbol.deserialize] == 'function')
|
236
|
+
return instance[Symbol.deserialize]!(buffer);
|
233
237
|
|
234
238
|
checkInstance(instance);
|
235
239
|
const { options, members } = instance.constructor[symbol_metadata(instance.constructor)].struct;
|