utilium 1.7.6 → 1.7.7
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 +7 -7
- package/package.json +1 -1
- package/src/struct.ts +7 -7
package/dist/struct.js
CHANGED
@@ -44,7 +44,7 @@ export function align(value, alignment) {
|
|
44
44
|
*/
|
45
45
|
function _memberLength(struct, length, name) {
|
46
46
|
if (length === undefined)
|
47
|
-
return
|
47
|
+
return -1;
|
48
48
|
if (typeof length != 'string')
|
49
49
|
return Number.isSafeInteger(length) && length >= 0
|
50
50
|
? length
|
@@ -128,9 +128,9 @@ export function serialize(instance) {
|
|
128
128
|
// for unions we should write members in ascending last modified order, but we don't have that info.
|
129
129
|
for (const [name, { type, length: rawLength, offset }] of members) {
|
130
130
|
const length = _memberLength(instance, rawLength, name);
|
131
|
-
for (let i = 0; i < (length
|
131
|
+
for (let i = 0; i < Math.abs(length); i++) {
|
132
132
|
const iOff = offset + sizeof(type) * i;
|
133
|
-
let value = length
|
133
|
+
let value = length != -1 ? instance[name][i] : instance[name];
|
134
134
|
if (typeof value == 'string') {
|
135
135
|
value = value.charCodeAt(0);
|
136
136
|
}
|
@@ -179,9 +179,9 @@ export function deserialize(instance, _buffer) {
|
|
179
179
|
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
180
180
|
for (const [name, { type, offset, length: rawLength }] of members) {
|
181
181
|
const length = _memberLength(instance, rawLength, name);
|
182
|
-
for (let i = 0; i < (length
|
183
|
-
let object = length
|
184
|
-
const key = length
|
182
|
+
for (let i = 0; i < Math.abs(length); i++) {
|
183
|
+
let object = length != -1 ? instance[name][i] : instance[name];
|
184
|
+
const key = length != -1 ? i : name, iOff = offset + sizeof(type) * i;
|
185
185
|
if (typeof instance[name] == 'string') {
|
186
186
|
instance[name] =
|
187
187
|
instance[name].slice(0, i) + String.fromCharCode(view.getUint8(iOff)) + instance[name].slice(i + 1);
|
@@ -194,7 +194,7 @@ export function deserialize(instance, _buffer) {
|
|
194
194
|
deserialize(object[key], new Uint8Array(buffer.subarray(iOff, iOff + sizeof(type))));
|
195
195
|
continue;
|
196
196
|
}
|
197
|
-
if (length)
|
197
|
+
if (length && length != -1)
|
198
198
|
object ||= [];
|
199
199
|
const fn = `get${capitalize(type)}`;
|
200
200
|
if (fn == 'getInt64') {
|
package/package.json
CHANGED
package/src/struct.ts
CHANGED
@@ -71,7 +71,7 @@ function _memberLength<T extends Metadata>(
|
|
71
71
|
length: string | number | undefined,
|
72
72
|
name: string
|
73
73
|
): number {
|
74
|
-
if (length === undefined) return
|
74
|
+
if (length === undefined) return -1;
|
75
75
|
if (typeof length != 'string')
|
76
76
|
return Number.isSafeInteger(length) && length >= 0
|
77
77
|
? length
|
@@ -173,10 +173,10 @@ export function serialize(instance: unknown): Uint8Array {
|
|
173
173
|
// for unions we should write members in ascending last modified order, but we don't have that info.
|
174
174
|
for (const [name, { type, length: rawLength, offset }] of members) {
|
175
175
|
const length = _memberLength(instance, rawLength, name);
|
176
|
-
for (let i = 0; i < (length
|
176
|
+
for (let i = 0; i < Math.abs(length); i++) {
|
177
177
|
const iOff = offset + sizeof(type) * i;
|
178
178
|
|
179
|
-
let value = length
|
179
|
+
let value = length != -1 ? instance[name][i] : instance[name];
|
180
180
|
if (typeof value == 'string') {
|
181
181
|
value = value.charCodeAt(0);
|
182
182
|
}
|
@@ -238,9 +238,9 @@ export function deserialize(instance: unknown, _buffer: ArrayBufferLike | ArrayB
|
|
238
238
|
|
239
239
|
for (const [name, { type, offset, length: rawLength }] of members) {
|
240
240
|
const length = _memberLength(instance, rawLength, name);
|
241
|
-
for (let i = 0; i < (length
|
242
|
-
let object = length
|
243
|
-
const key = length
|
241
|
+
for (let i = 0; i < Math.abs(length); i++) {
|
242
|
+
let object = length != -1 ? instance[name][i] : instance[name];
|
243
|
+
const key = length != -1 ? i : name,
|
244
244
|
iOff = offset + sizeof(type) * i;
|
245
245
|
|
246
246
|
if (typeof instance[name] == 'string') {
|
@@ -257,7 +257,7 @@ export function deserialize(instance: unknown, _buffer: ArrayBufferLike | ArrayB
|
|
257
257
|
continue;
|
258
258
|
}
|
259
259
|
|
260
|
-
if (length) object ||= [];
|
260
|
+
if (length && length != -1) object ||= [];
|
261
261
|
|
262
262
|
const fn = `get${capitalize(type)}` as const;
|
263
263
|
if (fn == 'getInt64') {
|