Module struct
Binary codec for fixed C struct layouts.
Calling the module on a layout
descriptor (as generated by autogen, e.g.
require("linux.netlink").layout.nlmsghdr) derives a string.pack format
once and returns a codec exposing pack/unpack/size, so callers never
hand-write the byte layout.
Usage:
local struct = require("struct")
local nlmsghdr = struct(require("linux.netlink").layout.nlmsghdr)
local bytes = nlmsghdr:pack(len, mtype, flags, seq, pid)
local len, mtype = nlmsghdr:unpack(bytes)
Functions
| pack (...) | Serializes the field values (in offset order) into the struct's bytes. |
| unpack (buf[, pos]) | Deserializes the struct's fields from a buffer. |
Functions
- pack (...)
-
Serializes the field values (in offset order) into the struct's bytes.
Parameters:
- ... the field values
Returns:
- unpack (buf[, pos])
-
Deserializes the struct's fields from a buffer.
Parameters:
- buf string
- pos integer starting offset (1-based) (optional)
Returns:
-
the field values in offset order, then the position past the struct