By Ugorji Nwoke   15 Dec 2014   /blog   technology go-codec

go-codec supports cbor? What is a CBOR?

View articles in the go-codec series, source at http://github.com/ugorji/go

Glad you asked. cbor stands for: Concise Binary Object Representation.

cbor is a relatively new binary format which builds upon the simplicity of messagepack and json. It is currently being targeted agressively in the internet-of-things space. It is a kick-ass format.

Cool. Now I know what cbor is. What does that have to do with go-codec?

cbor has pretty good implementations in Java, Python and some other languages.

We needed an efficient, complete and feature-rich go implementation.

It took less than 500 LOC to add cbor support to the go-codec library.

Why are you supporting it if it is not in widespread use?

A little history.

The primary author of the cbor spec is Carsten Bormann.

I got to know Carsten when we were working through updates to the messagepack spec within the messagepack community. We wanted explicit support for timestamps, extensions and distinct string (unicode) vs binary in the format. A few months in, and there was a stalemate and the messagepack community was not making much progress getting a v2 of the spec agreed upon.

Carsten and I separately (and without knowing of one-another’s work) built alternate formats that were more feature-rich than messagepack while maintaining it’s simplicity. I announced binc and Carsten engaged the IETF standards community on cbor around the same time in May 2013.

cbor has the advantage that it has gone through some rigors in the IETF, got a lot of feedback, and is a proposed standard.

What about the other go implementations?

The other implementation which is respectable is code.google.com/p/cbor/go package.

I tested it out, and it had issues encoding or decoding the TestStruc used in the benchmarks. It is not ready for prime time.

2014/12/18 14:17:36 cannot set field _struct
2014/12/18 14:17:36 error decoding map val:
    T *reflect.Value v &reflect.Value{typ:(*reflect.rtype)(0xa6a440),
    ptr:(unsafe.Pointer)(0xc208032150), flag:0xd6} v.T *codec.AnonInTestStrucIntf
--- FAIL: Benchmark__Gcbor_______Decode
	testing.go:18: Error decoding into new TestStruc: gcbor:
        can't read map into *codec.AnonInTestStrucIntf
Tags: technology go-codec


Subscribe: Technology
© Ugorji Nwoke