main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
882 bytes
|
Line | |
---|
1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | */
|
---|
4 |
|
---|
5 | "use strict";
|
---|
6 |
|
---|
7 | /** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
8 | /** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
9 |
|
---|
10 | class ArraySerializer {
|
---|
11 | /**
|
---|
12 | * @template T
|
---|
13 | * @param {T[]} array array
|
---|
14 | * @param {ObjectSerializerContext} context context
|
---|
15 | */
|
---|
16 | serialize(array, context) {
|
---|
17 | context.write(array.length);
|
---|
18 | for (const item of array) context.write(item);
|
---|
19 | }
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * @template T
|
---|
23 | * @param {ObjectDeserializerContext} context context
|
---|
24 | * @returns {T[]} array
|
---|
25 | */
|
---|
26 | deserialize(context) {
|
---|
27 | /** @type {number} */
|
---|
28 | const length = context.read();
|
---|
29 | /** @type {T[]} */
|
---|
30 | const array = [];
|
---|
31 | for (let i = 0; i < length; i++) {
|
---|
32 | array.push(context.read());
|
---|
33 | }
|
---|
34 | return array;
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | module.exports = ArraySerializer;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.