PeerDB-io / gluamsgpack

msgpack.org[gopher-lua]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

msgpack encoding library for gopher-lua in PeerDB

This follows many ideas from gluajson

For now there's no unmark function, as most marker types do not have a clear & precise Lua value

We also don't have a ubiquitous MarshalJSON trait to rely on, instead custom encodings must be done with a Packer interface:

type Packer interface {
  PackMsg([]byte) []byte
}

Which is passed the entire msgpack buffer & should append accordingly, returning the result


decode is not currently implemented, only encode

Lua strings are checked, if valid utf8 they are encoded as str, otherwise as bin

encode checks UserData for a __msgpack metamethod, the result of which is encoded

If no __msgpack metamethod exists, the Value is checked. If it implements the Packer interface, then it is invoked. Otherwise the following types have predictable implementations:

  • string (not checked for valid utf8)
  • []byte
  • uint64
  • int64
  • time.Time

There exists the following marker methods:

  • raw takes a string
  • array, map takes a table (useful for encoding empty arrays)
  • bin, str takes a string
  • signed, unsigned takes a number, or parses string
  • f32, f64 takes a number
  • time, time32, time64, time96 takes number representing time since unix epoch in seconds, or string with optional format (default RFC3339), or UserData with time.Time value
  • ext takes a number for type & string for bytes

About

msgpack.org[gopher-lua]

License:BSD Zero Clause License


Languages

Language:Go 100.0%