ArraySerializer.js 398 B

12345678910111213141516171819202122
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. class ArraySerializer {
  6. serialize(array, { write }) {
  7. write(array.length);
  8. for (const item of array) write(item);
  9. }
  10. deserialize({ read }) {
  11. const length = read();
  12. const array = [];
  13. for (let i = 0; i < length; i++) {
  14. array.push(read());
  15. }
  16. return array;
  17. }
  18. }
  19. module.exports = ArraySerializer;