Methods

(inner) 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.
Parameters:
NameTypeDescription
formatStrstringThe format string.
msgArray.<any>The message to be packed.
Throws:
- The error encountered during packing.
Type
error
Returns:
- The packed message in a byte array.
Type: 
Uint8Array
Example
let s = require('nuclei/structs'); 
let packedMsg = s.Pack("H", [0]);

(inner) StructsCalcSize(format) → {number}

StructsCalcSize returns the number of bytes needed to pack the values according to the given format.
Parameters:
NameTypeDescription
formatstringThe format string.
Throws:
- The error encountered during calculation.
Type
error
Returns:
- The number of bytes needed to pack the values.
Type: 
number
Example
let s = require('nuclei/structs'); 
let size = s.StructsCalcSize("H");

(inner) 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)).
Parameters:
NameTypeDescription
formatstringThe format string.
msgUint8ArrayThe packed message to be unpacked.
Throws:
- The error encountered during unpacking.
Type
error
Example
let s = require('nuclei/structs'); 
let unpackedMsg = s.Unpack(">I", buff[:nb]);