json-as 1.0.0-alpha.2 → 1.0.0-alpha.3

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.
Files changed (37) hide show
  1. package/.prettierignore +6 -0
  2. package/.prettierrc.json +0 -1
  3. package/CHANGELOG +9 -1
  4. package/README.md +3 -3
  5. package/as-test.config.json +1 -1
  6. package/asconfig.json +1 -29
  7. package/assembly/__tests__/array.spec.ts +67 -0
  8. package/assembly/__tests__/bool.spec.ts +4 -12
  9. package/assembly/__tests__/float.spec.ts +11 -21
  10. package/assembly/__tests__/integer.spec.ts +7 -9
  11. package/assembly/__tests__/null.spec.ts +12 -0
  12. package/assembly/__tests__/obj.spec.ts +137 -3
  13. package/assembly/__tests__/simd/string.spec.ts +21 -21
  14. package/assembly/__tests__/string.spec.ts +6 -4
  15. package/assembly/__tests__/test.spec.ts +120 -191
  16. package/assembly/deserialize/simple/bool.ts +1 -1
  17. package/assembly/deserialize/simple/map.ts +1 -1
  18. package/assembly/deserialize/simple/string.ts +4 -3
  19. package/assembly/globals/tables.ts +74 -416
  20. package/assembly/index.ts +18 -18
  21. package/assembly/serialize/simd/string.ts +10 -10
  22. package/assembly/serialize/simple/array.ts +4 -4
  23. package/assembly/serialize/simple/bool.ts +2 -2
  24. package/assembly/serialize/simple/date.ts +1 -1
  25. package/assembly/serialize/simple/float.ts +1 -1
  26. package/assembly/serialize/simple/integer.ts +1 -1
  27. package/assembly/serialize/simple/map.ts +6 -6
  28. package/assembly/serialize/simple/string.ts +3 -3
  29. package/assembly/test.ts +4 -43
  30. package/assembly/util/bytes.ts +1 -1
  31. package/modules/as-bs/assembly/index.ts +33 -83
  32. package/modules/test/assembly/index.ts +22 -0
  33. package/package.json +3 -7
  34. package/run-tests.sh +15 -0
  35. package/transform/lib/index.js +1 -1
  36. package/transform/lib/index.js.map +1 -1
  37. package/transform/src/index.ts +1 -1
@@ -1,417 +1,75 @@
1
1
  export const SERIALIZE_ESCAPE_TABLE = memory.data<u16>([
2
- 48,
3
- 48,
4
- 48,
5
- 49,
6
- 48,
7
- 50,
8
- 48,
9
- 51, // Pair 0-3
10
- 48,
11
- 52,
12
- 48,
13
- 53,
14
- 48,
15
- 54,
16
- 48,
17
- 55, // Pair 4-7
18
-
19
- 92,
20
- 98,
21
- 92,
22
- 116,
23
- 92,
24
- 110,
25
- 48,
26
- 98, // Pair 8-11
27
- 92,
28
- 102,
29
- 92,
30
- 114,
31
- 48,
32
- 101,
33
- 48,
34
- 102, // Pair 12-15
35
-
36
- 49,
37
- 48,
38
- 49,
39
- 49,
40
- 49,
41
- 50,
42
- 49,
43
- 51, // Pair 16-19
44
- 49,
45
- 52,
46
- 49,
47
- 53,
48
- 49,
49
- 54,
50
- 49,
51
- 55, // Pair 20-23
52
-
53
- 49,
54
- 56,
55
- 49,
56
- 57,
57
- 49,
58
- 97,
59
- 49,
60
- 98, // Pair 24-27
61
- 49,
62
- 99,
63
- 49,
64
- 100,
65
- 49,
66
- 101,
67
- 49,
68
- 102, // Pair 28-31
69
-
70
- 0,
71
- 0,
72
- 0,
73
- 0,
74
- 92,
75
- 34,
76
- 0,
77
- 0, // Pair 32-35
78
- 0,
79
- 0,
80
- 0,
81
- 0,
82
- 0,
83
- 0,
84
- 0,
85
- 0, // Pair 36-39
86
-
87
- 0,
88
- 0,
89
- 0,
90
- 0,
91
- 0,
92
- 0,
93
- 0,
94
- 0, // Pair 40-43
95
- 0,
96
- 0,
97
- 0,
98
- 0,
99
- 0,
100
- 0,
101
- 0,
102
- 0, // Pair 44-47
103
-
104
- 0,
105
- 0,
106
- 0,
107
- 0,
108
- 0,
109
- 0,
110
- 0,
111
- 0, // Pair 48-51
112
- 0,
113
- 0,
114
- 0,
115
- 0,
116
- 0,
117
- 0,
118
- 0,
119
- 0, // Pair 52-55
120
-
121
- 0,
122
- 0,
123
- 0,
124
- 0,
125
- 0,
126
- 0,
127
- 0,
128
- 0, // Pair 56-59
129
- 0,
130
- 0,
131
- 0,
132
- 0,
133
- 0,
134
- 0,
135
- 0,
136
- 0, // Pair 60-63
137
-
138
- 0,
139
- 0,
140
- 0,
141
- 0,
142
- 0,
143
- 0,
144
- 0,
145
- 0, // Pair 64-67
146
- 0,
147
- 0,
148
- 0,
149
- 0,
150
- 0,
151
- 0,
152
- 0,
153
- 0, // Pair 68-71
154
-
155
- 0,
156
- 0,
157
- 0,
158
- 0,
159
- 0,
160
- 0,
161
- 0,
162
- 0, // Pair 72-75
163
- 0,
164
- 0,
165
- 0,
166
- 0,
167
- 0,
168
- 0,
169
- 0,
170
- 0, // Pair 76-79
171
-
172
- 0,
173
- 0,
174
- 0,
175
- 0,
176
- 0,
177
- 0,
178
- 0,
179
- 0, // Pair 80-83
180
- 0,
181
- 0,
182
- 0,
183
- 0,
184
- 0,
185
- 0,
186
- 0,
187
- 0, // Pair 84-87
188
-
189
- 0,
190
- 0,
191
- 0,
192
- 0,
193
- 0,
194
- 0,
195
- 0,
196
- 0, // Pair 88-91
197
- 92,
198
- 92, // Pair 92-93
199
- ]);
200
-
201
- export const DESERIALIZE_ESCAPE_TABLE = memory.data<u8>([
202
- 0,
203
- 0,
204
- 0,
205
- 0,
206
- 0,
207
- 0,
208
- 0,
209
- 0, // 0-7
210
- 0,
211
- 0,
212
- 0,
213
- 0,
214
- 0,
215
- 0,
216
- 0,
217
- 0, // 8-15
218
- 0,
219
- 0,
220
- 0,
221
- 0,
222
- 0,
223
- 0,
224
- 0,
225
- 0, // 16-23
226
- 0,
227
- 0,
228
- 0,
229
- 0,
230
- 0,
231
- 0,
232
- 0,
233
- 0, // 24-31
234
- 0,
235
- 0,
236
- 34,
237
- 0,
238
- 0,
239
- 0,
240
- 0,
241
- 0, // 32-39
242
- 0,
243
- 0,
244
- 0,
245
- 0,
246
- 0,
247
- 0,
248
- 0,
249
- 0, // 40-47
250
- 0,
251
- 0,
252
- 0,
253
- 0,
254
- 0,
255
- 0,
256
- 0,
257
- 0, // 48-55
258
- 0,
259
- 0,
260
- 0,
261
- 0,
262
- 0,
263
- 0,
264
- 0,
265
- 0, // 56-63
266
- 0,
267
- 0,
268
- 0,
269
- 0,
270
- 0,
271
- 0,
272
- 0,
273
- 0, // 64-71
274
- 0,
275
- 0,
276
- 0,
277
- 0,
278
- 0,
279
- 0,
280
- 0,
281
- 0, // 72-79
282
- 0,
283
- 0,
284
- 0,
285
- 0,
286
- 0,
287
- 0,
288
- 0,
289
- 0, // 80-87
290
- 0,
291
- 0,
292
- 0,
293
- 0,
294
- 92,
295
- 0,
296
- 0,
297
- 0, // 88-95
298
- 0,
299
- 0,
300
- 8,
301
- 0,
302
- 0,
303
- 0,
304
- 12,
305
- 0, // 96-103
306
- 0,
307
- 0,
308
- 0,
309
- 0,
310
- 0,
311
- 0,
312
- 10,
313
- 0, // 104-111
314
- 0,
315
- 0,
316
- 13,
317
- 0,
318
- 9,
319
- 117,
320
- 0,
321
- 0, // 112-119
322
- 0,
323
- 0,
324
- 0,
325
- 0,
326
- 0,
327
- 0,
328
- 0,
329
- 0, // 120-127
330
- 0,
331
- 0,
332
- 0,
333
- 0,
334
- 0,
335
- 0,
336
- 0,
337
- 0, // 128-135
338
- 0,
339
- 0,
340
- 0,
341
- 0,
342
- 0,
343
- 0,
344
- 0,
345
- 0, // 136-143
346
- 0,
347
- 0,
348
- 0,
349
- 0,
350
- 0,
351
- 0,
352
- 0,
353
- 0, // 144-151
354
- ]);
355
-
356
- export const ESCAPE_HEX_TABLE =
357
- memory.data<u8>([
358
- 0,
359
- 1,
360
- 2,
361
- 3,
362
- 4,
363
- 5,
364
- 6,
365
- 7, // 0-7
366
- 8,
367
- 9,
368
- 0,
369
- 0,
370
- 0,
371
- 0,
372
- 0,
373
- 0, // 8-15
374
- 0,
375
- 0,
376
- 0,
377
- 0,
378
- 0,
379
- 0,
380
- 0,
381
- 0, // 16-23
382
- 0,
383
- 0,
384
- 0,
385
- 0,
386
- 0,
387
- 0,
388
- 0,
389
- 0, // 24-31
390
- 0,
391
- 0,
392
- 0,
393
- 0,
394
- 0,
395
- 0,
396
- 0,
397
- 0, // 32-39
398
- 0,
399
- 0,
400
- 0,
401
- 0,
402
- 0,
403
- 0,
404
- 0,
405
- 0, // 40-47
406
- 0,
407
- 10,
408
- 11,
409
- 12,
410
- 13,
411
- 14,
412
- 15, // 48-54
413
- ]) - 48;
414
-
415
- export const POW_TEN_TABLE_32 = memory.data<u32>([1, 10, 1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000, 1_000_000_000]);
416
-
417
- export const POW_TEN_TABLE_64 = memory.data<u64>([1, 10, 1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000, 1_000_000_000, 10_000_000_000, 100_000_000_000, 1_000_000_000_000, 10_000_000_000_000, 100_000_000_000_000, 1_000_000_000_000_000, 10_000_000_000_000_000, 100_000_000_000_000_000, 1_000_000_000_000_000_000, 10_000_000_000_000_000_000]);
2
+ 48, 48, 48, 49, 48, 50, 48, 51, // Pair 0-3
3
+ 48, 52, 48, 53, 48, 54, 48, 55, // Pair 4-7
4
+
5
+ 92, 98, 92, 116, 92, 110, 48, 98, // Pair 8-11
6
+ 92, 102, 92, 114, 48, 101, 48, 102, // Pair 12-15
7
+
8
+ 49, 48, 49, 49, 49, 50, 49, 51, // Pair 16-19
9
+ 49, 52, 49, 53, 49, 54, 49, 55, // Pair 20-23
10
+
11
+ 49, 56, 49, 57, 49, 97, 49, 98, // Pair 24-27
12
+ 49, 99, 49, 100, 49, 101, 49, 102, // Pair 28-31
13
+
14
+ 0, 0, 0, 0, 92, 34, 0, 0, // Pair 32-35
15
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 36-39
16
+
17
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 40-43
18
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 44-47
19
+
20
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 48-51
21
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 52-55
22
+
23
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 56-59
24
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 60-63
25
+
26
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 64-67
27
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 68-71
28
+
29
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 72-75
30
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 76-79
31
+
32
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 80-83
33
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 84-87
34
+
35
+ 0, 0, 0, 0, 0, 0, 0, 0, // Pair 88-91
36
+ 92, 92, // Pair 92-93
37
+ ]);
38
+
39
+ export const DESERIALIZE_ESCAPE_TABLE = memory.data<u8>([
40
+ 0, 0, 0, 0, 0, 0, 0, 0, // 0-7
41
+ 0, 0, 0, 0, 0, 0, 0, 0, // 8-15
42
+ 0, 0, 0, 0, 0, 0, 0, 0, // 16-23
43
+ 0, 0, 0, 0, 0, 0, 0, 0, // 24-31
44
+ 0, 0, 34, 0, 0, 0, 0, 0, // 32-39
45
+ 0, 0, 0, 0, 0, 0, 0, 0, // 40-47
46
+ 0, 0, 0, 0, 0, 0, 0, 0, // 48-55
47
+ 0, 0, 0, 0, 0, 0, 0, 0, // 56-63
48
+ 0, 0, 0, 0, 0, 0, 0, 0, // 64-71
49
+ 0, 0, 0, 0, 0, 0, 0, 0, // 72-79
50
+ 0, 0, 0, 0, 0, 0, 0, 0, // 80-87
51
+ 0, 0, 0, 0, 92, 0, 0, 0, // 88-95
52
+ 0, 0, 8, 0, 0, 0, 12, 0, // 96-103
53
+ 0, 0, 0, 0, 0, 0, 10, 0, // 104-111
54
+ 0, 0, 13, 0, 9, 117, 0, 0, // 112-119
55
+ 0, 0, 0, 0, 0, 0, 0, 0, // 120-127
56
+ 0, 0, 0, 0, 0, 0, 0, 0, // 128-135
57
+ 0, 0, 0, 0, 0, 0, 0, 0, // 136-143
58
+ 0, 0, 0, 0, 0, 0, 0, 0, // 144-151
59
+ ]);
60
+
61
+ export const ESCAPE_HEX_TABLE =
62
+ memory.data<u8>([
63
+ 0, 1, 2, 3, 4, 5, 6, 7, // 0-7
64
+ 8, 9, 0, 0, 0, 0, 0, 0, // 8-15
65
+ 0, 0, 0, 0, 0, 0, 0, 0, // 16-23
66
+ 0, 0, 0, 0, 0, 0, 0, 0, // 24-31
67
+ 0, 0, 0, 0, 0, 0, 0, 0, // 32-39
68
+ 0, 0, 0, 0, 0, 0, 0, 0, // 40-47
69
+ 0, 10, 11, 12, 13, 14, 15, // 48-54
70
+ ]) - 48;
71
+
72
+ export const POW_TEN_TABLE_32 = memory.data<u32>([1, 10, 1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000, 1_000_000_000]);
73
+
74
+ export const POW_TEN_TABLE_64 = memory.data<u64>([1, 10, 1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000, 1_000_000_000, 10_000_000_000, 100_000_000_000, 1_000_000_000_000, 10_000_000_000_000, 100_000_000_000_000, 1_000_000_000_000_000, 10_000_000_000_000_000, 100_000_000_000_000_000, 1_000_000_000_000_000_000, 10_000_000_000_000_000_000]);
75
+
package/assembly/index.ts CHANGED
@@ -93,23 +93,23 @@ export namespace JSON {
93
93
  return NULL_WORD;
94
94
  // @ts-ignore
95
95
  } else if (isString<nonnull<T>>()) {
96
- if (out) {
97
- out = changetype<string>(__renew(changetype<usize>(out), bytes(data) + 4));
98
- // const oldSize = bs.byteLength;
99
- const oldBuf = bs.buffer;
100
- const newSize = bytes(data) + 4;
101
- const newBuf = __new(newSize, idof<string>());
102
- bs.setBuffer(newBuf);
103
- serializeString(changetype<string>(data));
104
- bs.setBuffer(oldBuf);
105
- return changetype<string>(newBuf);
106
- }
96
+ // if (out) {
97
+ // out = changetype<string>(__renew(changetype<usize>(out), bytes(data) + 4));
98
+ // // const oldSize = bs.byteLength;
99
+ // const oldBuf = bs.buffer;
100
+ // const newSize = bytes(data) + 4;
101
+ // const newBuf = __new(newSize, idof<string>());
102
+ // bs.setBuffer(newBuf);
103
+ // serializeString(changetype<string>(data));
104
+ // bs.setBuffer(oldBuf);
105
+ // return changetype<string>(newBuf);
106
+ // }
107
107
  serializeString(changetype<string>(data));
108
108
  return bs.out<string>();
109
109
  // @ts-ignore: Supplied by transform
110
110
  } else if (isDefined(data.__SERIALIZE) && isDefined(data.__ALLOCATE)) {
111
111
  // @ts-ignore
112
- data.__ALLOCATE();
112
+ // data.__ALLOCATE();
113
113
  // @ts-ignore
114
114
  data.__SERIALIZE(changetype<usize>(data));
115
115
  return bs.out<string>();
@@ -135,7 +135,7 @@ export namespace JSON {
135
135
  } else if (data instanceof JSON.Box) {
136
136
  return JSON.stringify(data.value);
137
137
  } else {
138
- ERROR(`Could not serialize data of type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
138
+ throw new Error(`Could not serialize data of type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
139
139
  }
140
140
  }
141
141
 
@@ -161,7 +161,7 @@ export namespace JSON {
161
161
  return null;
162
162
  } else if (isString<T>()) {
163
163
  // @ts-ignore
164
- return deserializeString(dataPtr, dataPtr + dataSize);
164
+ return deserializeString(dataPtr, dataPtr + dataSize, __new(dataSize - 4, idof<string>()));
165
165
  } else if (isArray<T>()) {
166
166
  // @ts-ignore
167
167
  return deserializeArray<nonnull<T>>(dataPtr, dataPtr + dataSize, changetype<usize>(instantiate<T>()));
@@ -184,7 +184,7 @@ export namespace JSON {
184
184
  // @ts-ignore
185
185
  return new JSON.Box(JSON.parse<indexof<T>>(data));
186
186
  } else {
187
- ERROR(`Could not deserialize data ${data} to type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
187
+ throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
188
188
  }
189
189
  }
190
190
 
@@ -359,7 +359,7 @@ export namespace JSON {
359
359
  if (isBoolean<T>()) {
360
360
  serializeBool(src as bool);
361
361
  } else if (isInteger<T>() && nameof<T>() == "usize" && src == 0) {
362
- bs.ensureSize(8);
362
+ bs.proposeSize(8);
363
363
  store<u64>(bs.offset, 30399761348886638);
364
364
  bs.offset += 8;
365
365
  } else if (isInteger<T>()) {
@@ -370,7 +370,7 @@ export namespace JSON {
370
370
  serializeFloat<T>(src);
371
371
  // @ts-ignore: Function is generated by transform
372
372
  } else if (isNullable<T>() && changetype<usize>(src) == <usize>0) {
373
- bs.ensureSize(8);
373
+ bs.proposeSize(8);
374
374
  store<u64>(bs.offset, 30399761348886638);
375
375
  bs.offset += 8;
376
376
  } else if (isString<nonnull<T>>()) {
@@ -393,7 +393,7 @@ export namespace JSON {
393
393
  } else if (src instanceof JSON.Box) {
394
394
  __serialize(src.value);
395
395
  } else {
396
- ERROR(`Could not serialize provided data. Make sure to add the correct decorators to classes.`);
396
+ throw new Error(`Could not serialize provided data. Make sure to add the correct decorators to classes.`);
397
397
  }
398
398
  }
399
399
  export function __deserialize<T>(srcStart: usize, srcEnd: usize, dst: usize = 0): T {
@@ -45,13 +45,13 @@ export function serializeString_SIMD(src: string): void {
45
45
  mask &= mask - 1;
46
46
 
47
47
  if ((escaped & 0xffff) != BACK_SLASH) {
48
- bs.ensureSize(10);
48
+ bs.addSize(10);
49
49
  store<u64>(dst_offset, 13511005048209500);
50
50
  store<u32>(dst_offset, escaped, 8);
51
51
  v128.store(dst_offset, v128.load(src_offset, 2), 12);
52
52
  bs.offset += 10;
53
53
  } else {
54
- bs.ensureSize(2);
54
+ bs.addSize(2);
55
55
  store<u32>(dst_offset, escaped);
56
56
  v128.store(dst_offset, v128.load(src_offset, 2), 4);
57
57
  bs.offset += 2;
@@ -84,7 +84,7 @@ export function serializeString_SIMD(src: string): void {
84
84
  mask &= mask - 1;
85
85
 
86
86
  if ((escaped & 0xffff) != BACK_SLASH) {
87
- bs.ensureSize(10);
87
+ bs.addSize(10);
88
88
  store<u64>(dst_offset, 13511005048209500);
89
89
  store<u32>(dst_offset, escaped, 8);
90
90
  while (lane_index < 6) {
@@ -93,7 +93,7 @@ export function serializeString_SIMD(src: string): void {
93
93
  }
94
94
  bs.offset += 10;
95
95
  } else {
96
- bs.ensureSize(2);
96
+ bs.addSize(2);
97
97
  store<u32>(dst_offset, escaped);
98
98
 
99
99
  while (lane_index < 6) {
@@ -116,12 +116,12 @@ export function serializeString_SIMD(src: string): void {
116
116
  const escaped = load<u32>(SERIALIZE_ESCAPE_TABLE + (codeA << 2));
117
117
 
118
118
  if ((escaped & 0xffff) != BACK_SLASH) {
119
- bs.ensureSize(10);
119
+ bs.addSize(10);
120
120
  store<u64>(bs.offset, 13511005048209500);
121
121
  store<u32>(bs.offset, escaped, 8);
122
122
  bs.offset += 12;
123
123
  } else {
124
- bs.ensureSize(2);
124
+ bs.addSize(2);
125
125
  store<u32>(bs.offset, escaped);
126
126
  bs.offset += 4;
127
127
  }
@@ -134,12 +134,12 @@ export function serializeString_SIMD(src: string): void {
134
134
  const escaped = load<u32>(SERIALIZE_ESCAPE_TABLE + (codeB << 2));
135
135
 
136
136
  if ((escaped & 0xffff) != BACK_SLASH) {
137
- bs.ensureSize(10);
137
+ bs.addSize(10);
138
138
  store<u64>(bs.offset, 13511005048209500);
139
139
  store<u32>(bs.offset, escaped, 8);
140
140
  bs.offset += 12;
141
141
  } else {
142
- bs.ensureSize(2);
142
+ bs.addSize(2);
143
143
  store<u32>(bs.offset, escaped);
144
144
  bs.offset += 4;
145
145
  }
@@ -156,12 +156,12 @@ export function serializeString_SIMD(src: string): void {
156
156
  const escaped = load<u32>(SERIALIZE_ESCAPE_TABLE + (code << 2));
157
157
 
158
158
  if ((escaped & 0xffff) != BACK_SLASH) {
159
- bs.ensureSize(10);
159
+ bs.addSize(10);
160
160
  store<u64>(bs.offset, 13511005048209500);
161
161
  store<u32>(bs.offset, escaped, 8);
162
162
  bs.offset += 12;
163
163
  } else {
164
- bs.ensureSize(2);
164
+ bs.addSize(2);
165
165
  store<u32>(bs.offset, escaped);
166
166
  bs.offset += 4;
167
167
  }
@@ -6,12 +6,12 @@ export function serializeArray<T extends any[]>(src: T): void {
6
6
  const end = src.length - 1;
7
7
  let i = 0;
8
8
  if (end == -1) {
9
- bs.ensureSize(4);
9
+ bs.proposeSize(4);
10
10
  store<u32>(bs.offset, 6094939);
11
11
  bs.offset += 4;
12
12
  return;
13
13
  }
14
- bs.ensureSize(end << 3);
14
+ bs.proposeSize(end << 3);
15
15
 
16
16
  store<u16>(bs.offset, BRACKET_LEFT);
17
17
  bs.offset += 2;
@@ -19,14 +19,14 @@ export function serializeArray<T extends any[]>(src: T): void {
19
19
  while (i < end) {
20
20
  const block = unchecked(src[i++]);
21
21
  JSON.__serialize<valueof<T>>(block);
22
- bs.ensureSize(2);
22
+ bs.growSize(2);
23
23
  store<u16>(bs.offset, COMMA);
24
24
  bs.offset += 2;
25
25
  }
26
26
 
27
27
  const lastBlock = unchecked(src[end]);
28
28
  JSON.__serialize<valueof<T>>(lastBlock);
29
- bs.ensureSize(2);
29
+ bs.proposeSize(2);
30
30
  store<u16>(bs.offset, BRACKET_RIGHT);
31
31
  bs.offset += 2;
32
32
  }
@@ -7,11 +7,11 @@ import { bs } from "../../../modules/as-bs";
7
7
  */
8
8
  export function serializeBool(data: bool): void {
9
9
  if (data == true) {
10
- bs.ensureSize(8);
10
+ bs.proposeSize(8);
11
11
  store<u64>(bs.offset, 28429475166421108);
12
12
  bs.offset += 8;
13
13
  } else {
14
- bs.ensureSize(10);
14
+ bs.proposeSize(10);
15
15
  store<u64>(bs.offset, 32370086184550502);
16
16
  store<u64>(bs.offset, 101, 8);
17
17
  bs.offset += 10;