A performance-optimized fork of vmihailenco/msgpack/v5, maintained by Basekick Labs. Built for Arc, a high-performance time-series database. The upstream module path is preserved for drop-in compatibility.
Decode — ~21% faster, ~50% less memory:
- Zero-allocation byte-slice reader for
Unmarshal() *interface{}fast path bypasses reflect for the most common decode pattern
Encode — ~12% faster, ~43% fewer allocations:
- Pooled byte buffer in
Marshal()eliminates per-callbytes.Buffer - Native
WriteByteon the Marshal path removes per-byte heap allocations - Type-switch fast paths for
map[string]interface{}and[]interface{}
Security:
- OOM protection: slice and map allocations from untrusted input are capped at 1M elements
See CHANGELOG.md for full details.
- 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 (the module path is unchanged from upstream for drop-in compatibility):
go get github.com/vmihailenco/msgpack/v5import "github.com/vmihailenco/msgpack/v5"
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!