All files / src/common_serdes optional.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 3/3
100% Lines 8/8

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 1619x     19x 2x   336x 192x   144x 144x     204x    
import { define } from "../define";
import { OptionalFactory } from "../types";
 
export const optional: OptionalFactory = (sd) =>
  define(
    (ctx, data) => {
      if (data == undefined) {
        ctx.view.setUint8(ctx.i++, 0);
      } else {
        ctx.view.setUint8(ctx.i++, 1);
        sd.ser(ctx, data);
      }
    },
    (ctx) => (ctx.view.getUint8(ctx.i++) ? sd.des(ctx) : undefined)
  );