23 lines
620 B
Lua
23 lines
620 B
Lua
local constants = require("core.constants")
|
|
local M = {}
|
|
function M.message(kind, source, target, payload)
|
|
return {
|
|
protocol = constants.PROTOCOL,
|
|
version = constants.PROTOCOL_VERSION,
|
|
type = kind,
|
|
source = source,
|
|
target = target,
|
|
requestId = ("%s-%d-%d"):format(source, os.getComputerID(), os.epoch("utc")),
|
|
timestamp = os.epoch("utc"),
|
|
payload = payload or {},
|
|
}
|
|
end
|
|
function M.valid(message)
|
|
return type(message) == "table"
|
|
and message.protocol == constants.PROTOCOL
|
|
and message.version == constants.PROTOCOL_VERSION
|
|
and type(message.type) == "string"
|
|
end
|
|
return M
|
|
|