gluamsgpack

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: 0BSD Imports: 7 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Loader

func Loader(ls *lua.LState) int

func MsgEncode

func MsgEncode(ls *lua.LState) int

Types

type Array

type Array *lua.LTable

type Bin

type Bin string

func (Bin) PackMsg

func (s Bin) PackMsg(buf []byte) []byte

type Ext

type Ext struct {
	// contains filtered or unexported fields
}

func (Ext) PackMsg

func (x Ext) PackMsg(buf []byte) []byte

type F32

type F32 float32

func (F32) PackMsg

func (f F32) PackMsg(buf []byte) []byte

type F64

type F64 float64

func (F64) PackMsg

func (f F64) PackMsg(buf []byte) []byte

type Map

type Map *lua.LTable

type Packer

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

type Raw

type Raw string

func (Raw) PackMsg

func (s Raw) PackMsg(buf []byte) []byte

type Signed

type Signed int64

func (Signed) PackMsg

func (i Signed) PackMsg(buf []byte) []byte

type Str

type Str string

func (Str) PackMsg

func (s Str) PackMsg(buf []byte) []byte

type Time

type Time time.Time

func (Time) PackMsg

func (t Time) PackMsg(buf []byte) []byte

type Time32

type Time32 time.Time

func (Time32) PackMsg

func (t Time32) PackMsg(buf []byte) []byte

type Time64

type Time64 time.Time

func (Time64) PackMsg

func (t Time64) PackMsg(buf []byte) []byte

type Time96

type Time96 time.Time

func (Time96) PackMsg

func (t Time96) PackMsg(buf []byte) []byte

type Unsigned

type Unsigned uint64

func (Unsigned) PackMsg

func (u Unsigned) PackMsg(buf []byte) []byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL