# All files / lib/serialize getTlv.ts

78.57% Statements 11/14
100% Branches 0/0
50% Functions 1/2
78.57% Lines 11/14

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
    221x

    1x
    928x
    928x
    928x

    928x
    928x
    928x
    928x

    928x

    1x

     import { BufferReader, BufferWriter } from '@node-dlc/bufio';

    // TODO: add unit tests
    export function getTlv(reader: BufferReader): Buffer {
      const type = reader.readBigSize();
      const length = reader.readBigSize();
      const body = reader.readBytes(Number(length));

      const writer = new BufferWriter();
      writer.writeBigSize(type);
      writer.writeBigSize(length);
      writer.writeBytes(body);

      return writer.toBuffer();
    }

    export function skipTlv(reader: BufferReader): void {
      reader.readBigSize();
      const length = reader.readBigSize();
      reader.readBytes(Number(length));
    }