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).

  1. Simple but extremely powerful and feature-rich API
  2. Very High Performance.
    Our extensive benchmarks show us outperforming Gob, Json and Bson by 2-4X. This was achieved by taking extreme care on:
    1. managing allocation
    2. stack frame size (important due to Go’s use of split stacks),
    3. reflection use
    4. recursion implications
    5. zero-copy mode (encoding/decoding to byte slice without using temp buffers)
  3. Correct.
    Care was taken to precisely handle corner cases like: overflows, nil maps and slices, nil value in stream, etc.
  4. Efficient zero-copying into temporary byte buffers
    when encoding into or decoding from a byte slice.
  5. Standard field renaming via tags
  6. Encoding from any value
    (struct, slice, map, primitives, pointers, interface{}, etc)
  7. Decoding into pointer to any non-nil typed value
    (struct, slice, map, int, float32, bool, string, reflect.Value, etc)
  8. Supports extension functions to handle the encode/decode of custom types
  9. 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{}
  10. Provides a RPC Server and Client Codec for net/rpc communication protocol.
  11. Msgpack Specific:
    1. Provides extension functions to handle spec-defined extensions (binary, timestamp)
    2. Options to resolve ambiguities in handling raw bytes (as string or []byte) during schema-less decoding (decoding into a nil interface{})
    3. RPC Server/Client Codec for msgpack-rpc protocol defined at: http://wiki.msgpack.org/display/MSGPACK/RPC+specification .

I had previously written a specific Go Library for msgpack: https://github.com/ugorji/go-msgpack . However, that had a few issues:

  • 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.

I hope you enjoy using the library.

Tags: golang technology


Subscribe: Technology
© Ugorji Nwoke