1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | class NullPrototypeObjectSerializer {
|
8 | serialize(obj, { write }) {
|
9 | const keys = Object.keys(obj);
|
10 | for (const key of keys) {
|
11 | write(key);
|
12 | }
|
13 | write(null);
|
14 | for (const key of keys) {
|
15 | write(obj[key]);
|
16 | }
|
17 | }
|
18 | deserialize({ read }) {
|
19 | const obj = Object.create(null);
|
20 | const keys = [];
|
21 | let key = read();
|
22 | while (key !== null) {
|
23 | keys.push(key);
|
24 | key = read();
|
25 | }
|
26 | for (const key of keys) {
|
27 | obj[key] = read();
|
28 | }
|
29 | return obj;
|
30 | }
|
31 | }
|
32 |
|
33 | module.exports = NullPrototypeObjectSerializer;
|