bin library

The bin library provides function for packing and unpacking binary data. It can be imported into a script as follows:

local bin = require("pktizr.bin")

The provided functions can then be used by prepending bin. to the name (e.g. bin.pack(...)).

Functions

pack(fmt, v1, v2, ...)

Returns a binary string containing the values v1, v2, etc. packed (that is, serialized in binary form) according to the format string fmt.

unpack(fmt, s[, pos])

Returns the values packed in the string s according to the format string fmt. An optional pos marks where to start reading in s (default is 1). After the read values, this function also returns the index of the first unread byte in s.

Format

The format used by these functions is compatible with the one for the string.pack() and string.unpack() functions in Lua 5.3. See the Lua reference for more information.

Table Of Contents

Previous topic

pktizr

Next topic

bit library

This Page