All files / src/common_serdes array.ts

100% Statements 15/15
100% Branches 0/0
100% Functions 3/3
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2219x     19x 4x   346x 346x 346x 33647x       210x 210x 210x 20406x   210x      
import { define } from "../define";
import { ArrayFactory } from "../types";
 
export const array: ArrayFactory = (sd, headSd) =>
  define(
    (ctx, data) => {
      const { length } = data;
      headSd.ser(ctx, length);
      for (let i = 0; i < length; i++) {
        sd.ser(ctx, data[i]);
      }
    },
    (ctx) => {
      const length = headSd.des(ctx);
      const data = new Array(length);
      for (let i = 0; i < length; i++) {
        data[i] = sd.des(ctx);
      }
      return data;
    }
  );