1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | class MapObjectSerializer {
|
8 | serialize(obj, { write }) {
|
9 | write(obj.size);
|
10 | for (const key of obj.keys()) {
|
11 | write(key);
|
12 | }
|
13 | for (const value of obj.values()) {
|
14 | write(value);
|
15 | }
|
16 | }
|
17 | deserialize({ read }) {
|
18 | let size = read();
|
19 | const map = new Map();
|
20 | const keys = [];
|
21 | for (let i = 0; i < size; i++) {
|
22 | keys.push(read());
|
23 | }
|
24 | for (let i = 0; i < size; i++) {
|
25 | map.set(keys[i], read());
|
26 | }
|
27 | return map;
|
28 | }
|
29 | }
|
30 |
|
31 | module.exports = MapObjectSerializer;
|