Represents a struct instance created by new()
.
const fmt = struct.new(…);
fmt.pack(…);
const values = fmt.unpack(…);
- Source
- See
Methods
pack(…values) → {string}
Pack given values.
The pack()
function creates a byte string containing the argument values packed according to the given format instance.
Returns the packed string.
Raises a runtime exception if a given argument value does not match the required type of the corresponding format string directive.
Name | Type | Description |
---|---|---|
values | * | (repeatable) Variable number of values to pack. |
const fmt = struct.new(…);
const data = fmt.pack(…);
- Source
unpack(input, offsetopt) → {array}
Unpack given byte string.
The unpack()
function interpretes a byte string according to the given format instance and returns the resulting values. If the optional offset argument is given, unpacking starts from this byte position within the input. If not specified, the start offset defaults to 0
, the start of the given input string.
Returns an array of unpacked values.
Raises a runtime exception if an invalid input string or offset value is given.
Name | Type | Description |
---|---|---|
input | string | The input string to unpack. |
offset | number | (optional, default: 0 )The offset within the input string to start unpacking from. |
const fmt = struct.new(…);
const values = fmt.unpack(…);
- Source