pod: plain-old-data library and serialization


A Lua library for specifying and converting types to/from "plain old data" and methods to serialize/deserialize those types to/from bytes. In Lua, the 5 supported types considered "plain old data" are: nil, boolean, integer, string and any table of only these types.
local M = mod'mymod'
local mty = require'metaty'
local pod = require'pod'

-- enums are already plain-old-data.
M.Job = mty.enum'Job' { BOSS = 1, PEON = 2 }

--- records need to have pod() called on them.
--- This implements __toPod and __fromPod for the metaty record.
M.Worker = pod(mty'Worker' {
  'name [string] #1',    -- must specify type and #id
  'job  [mymod.Job] #2', -- can lookup any type in PKG_LOOKUP
  'salary [int] #3',
  'schedule {int: mymod.Schedule} #4', -- map of weekday[1,7] -> scheduled time
})

M.Schedule = pod(mty'Schedule' {
  'start [int]: start time in seconds since midnight',
  'stop  [int]: stop time in seconds since midnight',
})

local serialized = pod.ser(M.Worker{...})   -- convert to string
local worker = pod.de(serialized, M.Worker) -- convert from string

Explanation of above:, {listType} or {map: type} repsecitively. The collection types are converted to pod.List and pod.Map respectively.