LuaJIT string.buffer encoding for Golang
Resources
Notes
The encoding format for LuaJIT string.buffer is not a formalized structure, the format could change at any time. Thus use this project with your own risk.
Supported:
- nil, false, true, userdata NULL
- int (int32), double (float64)
- Empty table, hash, 0-based array, 1-based array
- FFI int64, uint64, complex
- string, interned string
Work in Progress:
- lightud32, lightud64
- Mixed table, Metatable dict entry
Not supported
- Non-string value as hash keys
Features
- Primitives, arrays, maps, structs, time.Time and interface{}.
- Appengine *datastore.Key and datastore.Cursor.
- CustomEncoder/CustomDecoder interfaces for custom encoding.
- Renaming fields via
ljpack:"my_field_name"
and alias vialjpack:"alias:another_name"
. - Omitting individual empty fields via
ljpack:",omitempty"
tag or all empty fields in a struct. - Map keys sorting.
- Encoding/decoding all structs as arrays or individual structs.
- Encoder.SetCustomStructTag with Decoder.SetCustomStructTag can turn ljpack into drop-in replacement for any tag.
- Simple but very fast and efficient queries.
Installation
ljpack supports 2 last Go versions and requires support for Go modules. So make sure to initialize a Go module:
go mod init github.com/my/repo
And then install ljpack:
go get github.com/fffonion/ljpack
Quickstart
import "github.com/fffonion/ljpack"
func ExampleMarshal() {
type Item struct {
Foo string
}
b, err := ljpack.Marshal(&Item{Foo: "bar"})
if err != nil {
panic(err)
}
var item Item
err = ljpack.Unmarshal(b, &item)
if err != nil {
panic(err)
}
fmt.Println(item.Foo)
// Output: bar
}
Credits
- Forked from https://github.com/vmihailenco/msgpack