- Source
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:
Name | Type | Description |
---|---|---|
formatStr | string | The format string. |
msg | Array.<any> | The message to be packed. |
- Source
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:
Name | Type | Description |
---|---|---|
format | string | The format string. |
- Source
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:
Name | Type | Description |
---|---|---|
format | string | The format string. |
msg | Uint8Array | The packed message to be unpacked. |
- Source
Throws:
- - The error encountered during unpacking.
- Type
- error
Example
let s = require('nuclei/structs');
let unpackedMsg = s.Unpack(">I", buff[:nb]);