Last change
on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
589 bytes
|
Line | |
---|
1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
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;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.