A performance-optimized fork of vmihailenco/msgpack/v5, maintained by Basekick Labs. Built for Arc, a high-performance time-series database.
15 performance optimizations — +8.6% throughput in Arc production benchmarks:
- Zero-allocation byte-slice reader for
Unmarshal()(~21% faster, ~50% less memory) *interface{}fast path bypasses reflect for the most common decode pattern- Pooled byte buffer and
MarshalAppendAPI for zero-alloc encode - Type-switch fast paths for
map[string]interface{},map[string]string,[]interface{} - Two-pass
OmitEmpty,isZeroercaching,reflect.Convertskip, sorted key pooling sync.Poolreplacement for goroutine-per-type value cache
15 bug fixes — including OOM protection, float-to-int decoding, non-addressable pointer encode, and more.
See CHANGELOG.md for full details and the v6.0.0 release.
- 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.
- Renaming fields via
msgpack:"my_field_name"and alias viamsgpack:"alias:another_name". - Omitting individual empty fields via
msgpack:",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 msgpack into drop-in replacement for any tag.
- Simple but very fast and efficient queries.
msgpack 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/repoAnd then install msgpack:
go get github.com/Basekick-Labs/msgpack/v6import "github.com/Basekick-Labs/msgpack/v6"
func ExampleMarshal() {
type Item struct {
Foo string
}
b, err := msgpack.Marshal(&Item{Foo: "bar"})
if err != nil {
panic(err)
}
var item Item
err = msgpack.Unmarshal(b, &item)
if err != nil {
panic(err)
}
fmt.Println(item.Foo)
// Output: bar
}Thanks to all the people who already contributed!