All files / src/msgpack array.ts

100% Statements 15/15
100% Branches 0/0
100% Functions 2/2
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 19 20 21 22 23 24 25 26 27 28 29 30 31  19x 19x 19x   19x             11x 11x 11x 223874x       19x         7x 7x 101010x   7x    
import { Context, Encoding, Ser } from "../types";
import { pack } from "./pack";
import { packSize } from "./size";
import { unpack } from "./unpack";
 
export function packArray(
  ctx: Context,
  data: unknown[],
  floatHead: number,
  float: Ser<number>,
  str: Ser<string>
) {
  const { length } = data;
  packSize(ctx, length, 0x90, 0xdc);
  for (let i = 0; i < length; i++) {
    pack(ctx, data[i], floatHead, float, str);
  }
}
 
export function unpackArrayBody(
  ctx: Context,
  size: number,
  encoding: Encoding<string>
) {
  const data = Array<unknown>(size);
  for (let i = 0; i < size; i++) {
    data[i] = unpack(ctx, encoding);
  }
  return data;
}