Unified opaque byte payloads. Every API that produces bytes returns a Bytes; every API that consumes bytes accepts one. The call form lifts a string; the json / kdl / msgpack constructors encode a value, and zlib / base64 encode bytes. All decoding lives on the returned handle.
JSON-encode value and return the resulting bytes. A table value holds twice is written twice. Raises for a table inside itself, tables nested more than 127 deep, a table with a string key written as one of its number keys, such as "1" and 1, which JSON would write as one name, or JSON text longer than the memory the app has left.
Example
local body = datumhue.bytes.json({ scores = { 3, 5 } })
print(body:text()) --> {"scores":[3,5]}-- An empty table encodes as an array.print(datumhue.bytes.json({}):text()) --> []-- A table held twice is written twice; one inside itself raises.local pair = { 1, 2 }
print(datumhue.bytes.json({ pair, pair }):text()) --> [[1,2],[1,2]]
pair[3] = pair
local ok = pcall(datumhue.bytes.json, pair)
print(ok) --> false
KDL-encode value, a table, as the inverse of Bytes:kdl and return the resulting bytes. Each string key becomes a child node, never a property; an array of tables becomes repeated sibling nodes; an empty table becomes a bare node, which reads back as true, and an array of one element reads back as that element. A table value holds twice is written twice. Raises for a table inside itself, tables nested more than 127 deep, or a document larger than the memory the app has left.
Example
local config = datumhue.bytes.kdl({ window = { width = 800 } })
print(config:text()) --> window { width 800 }-- An array of tables becomes repeated nodes.local list = { plugin = { { id = 1 }, { id = 2 } } }
local plugins = datumhue.bytes.kdl(list)
print(plugins:text()) --> plugin { id 1 } plugin { id 2 }-- An empty table becomes a bare node.print(datumhue.bytes.kdl({ fullscreen = {} }):text()) --> fullscreen
MessagePack-encode value and return the resulting bytes. A table value holds twice is written twice. Raises for a table inside itself, tables nested more than 127 deep, or a value larger than the memory the app has left.