Supports:
- Primitives, arrays, maps, structs, time.Time and interface{}.
- Appengine *datastore.Key and datastore.Cursor.
- CustomEncoder/CustomDecoder interfaces for custom encoding.
- Extensions to encode type information.
- Fields renaming, e.g.
msgpack:"my_field_name"
. - Structs inlining, e.g.
msgpack:",inline"
. - Omitempty flag, e.g.
msgpack:",omitempty"
.
API docs: http://godoc.org/gopkg.in/vmihailenco/msgpack.v2. Examples: http://godoc.org/gopkg.in/vmihailenco/msgpack.v2#pkg-examples.
Install:
go get gopkg.in/vmihailenco/msgpack.v2
func ExampleMarshal() {
b, err := msgpack.Marshal(true)
if err != nil {
panic(err)
}
fmt.Printf("%#v\n", b)
// Output:
var out bool
err = msgpack.Unmarshal([]byte{0xc3}, &out)
if err != nil {
panic(err)
}
fmt.Println(out)
// Output: []byte{0xc3}
// true
}
BenchmarkStruct-4 200000 11515 ns/op 3296 B/op 27 allocs/op
BenchmarkStructUgorjiGoMsgpack-4 100000 12234 ns/op 3840 B/op 70 allocs/op
BenchmarkStructUgorjiGoCodec-4 100000 15251 ns/op 7474 B/op 29 allocs/op
BenchmarkStructJSON-4 30000 50851 ns/op 8088 B/op 29 allocs/op
BenchmarkStructGOB-4 20000 64993 ns/op 15609 B/op 299 allocs/op
Please go through examples to get an idea how to use this package.