structs

(structs).Pack(formatStr, msg) ⇒ Uint8Array

Pack returns a byte slice containing the values of msg slice packed according to the given format. The items of msg slice must match the values required by the format exactly.

Kind: inner method of structs
Returns: Uint8Array - - The packed message in a byte array.
Throws:

  • error - The error encountered during packing.
ParamTypeDescription
formatStrstringThe format string.
msgArray.<any>The message to be packed.

Example

let s = require('nuclei/structs'); 
let packedMsg = s.Pack("H", [0]);

(structs).StructsCalcSize(format) ⇒ number

StructsCalcSize returns the number of bytes needed to pack the values according to the given format.

Kind: inner method of structs
Returns: number - - The number of bytes needed to pack the values.
Throws:

  • error - The error encountered during calculation.
ParamTypeDescription
formatstringThe format string.

Example

let s = require('nuclei/structs'); 
let size = s.StructsCalcSize("H");

(structs).Unpack(format, msg)

Unpack the byte slice (presumably packed by Pack(format, msg)) according to the given format. The result is a []interface slice even if it contains exactly one item. The byte slice must contain not less the amount of data required by the format (len(msg) must more or equal CalcSize(format)).

Kind: inner method of structs
Throws:

  • error - The error encountered during unpacking.
ParamTypeDescription
formatstringThe format string.
msgUint8ArrayThe packed message to be unpacked.

Example

let s = require('nuclei/structs'); 
let unpackedMsg = s.Unpack(">I", buff[:nb]);