By Ugorji Nwoke
30 May 2013
/blog
golang technology
Announcing Go codec library for msgpack and binc
Go codec is a High Performance and Feature-Rich Idiomatic Go Library
providing encode/decode support for different serialization formats,
including msgpack and binc . Get it while it’s hot at
https://github.com/ugorji/go/tree/master/codec#readme
This follows on the public release of Binc,
a lightweight, compact,
limitless, schema-free, precise, binary, high-performance,
feature-rich, language-independent, multi-domain, extensible, data
interchange format for structured data.
Let me reproduce the highlights of the new library here (for those who
don’t click over to the github page).
Simple but extremely powerful and feature-rich API
Very High Performance.
Our extensive benchmarks show us outperforming Gob, Json and Bson
by 2-4X. This was achieved by taking extreme care on:
managing allocation
stack frame size (important due to Go’s use of split stacks),
reflection use
recursion implications
zero-copy mode (encoding/decoding to byte slice without using temp buffers)
Correct.
Care was taken to precisely handle corner cases like: overflows,
nil maps and slices, nil value in stream, etc.
Efficient zero-copying into temporary byte buffers
when encoding into or decoding from a byte slice.
Standard field renaming via tags
Encoding from any value
(struct, slice, map, primitives, pointers, interface{}, etc)
Decoding into pointer to any non-nil typed value
(struct, slice, map, int, float32, bool, string, reflect.Value, etc)
Supports extension functions to handle the encode/decode of custom types
Schema-less decoding
(decode into a pointer to a nil interface{} as opposed to a typed non-nil value).
Includes Options to configure what specific map or slice type to
use when decoding an encoded list or map into a nil interface{}
Provides a RPC Server and Client Codec for net/rpc communication protocol.
Msgpack Specific:
Provides extension functions to handle spec-defined extensions (binary, timestamp)
Options to resolve ambiguities in handling raw bytes (as string or []byte)
during schema-less decoding (decoding into a nil interface{})
It was specific to msgpack.
As discussions on msgpack enhancement stalled, I had to retrofit the
codebase to support multiple encodings, including the newly designed
Binc. The go tools are currently limited in supporting breaking
changes in a given repository, so a new github repository had to be
created.
The old API was convoluted.
It needed some serious rethinking so that its performance could be
dramatically improved and user-defined extensions could be
supported.
This new library kicks the tail out of the old one. The performance of
the old library was already pretty good compared to other encodings, but
this new library takes the performance up a notch.
The old library at https://github.com/ugorji/go-msgpack has now been
deprecated. At runtime, a single log message will be printed out for
users of the package “encouraging” them to migrate to the new library.