All files / src/serdes string.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 3/3
100% Lines 13/13

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 1919x     19x 19x   64848x 64848x 64844x 64844x 64836x 64836x 64836x 64836x 64836x   41112x    
import { define } from "../define";
import { StringFactory } from "../types";
 
export const string: StringFactory = (encoding, headSd) =>
  define(
    (ctx, data) => {
      const head = ctx.i;
      headSd.ser(ctx, 0);
      const begin = ctx.i;
      encoding.encode(ctx, data);
      const end = ctx.i;
      const size = end - begin;
      ctx.i = head;
      headSd.ser(ctx, size);
      ctx.i = end;
    },
    (ctx) => encoding.decode(ctx, headSd.des(ctx) + ctx.i)
  );