SetObjectSerializer.js 403 B

123456789101112131415161718192021222324
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. class SetObjectSerializer {
  6. serialize(obj, { write }) {
  7. write(obj.size);
  8. for (const value of obj) {
  9. write(value);
  10. }
  11. }
  12. deserialize({ read }) {
  13. let size = read();
  14. const set = new Set();
  15. for (let i = 0; i < size; i++) {
  16. set.add(read());
  17. }
  18. return set;
  19. }
  20. }
  21. module.exports = SetObjectSerializer;