ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.87k stars 295 forks source link

Question about docs. #42

Closed giulioungaretti closed 9 years ago

giulioungaretti commented 10 years ago

Not strictly an issue, but is there anywhere a working example of how to encode/ deconde from start to end? Really does not matter into the details, but I can't figure out how one it's even supposed to start. It's most probably me being idiot but I can't figure out from the example in the readme, which to my newbie eyes has some obscure things.

:D

zancarius commented 10 years ago

I'd imagine you've probably already figured this out at this point some 5 days later. In case you haven't, I'll give it a shot since this remains unanswered, and I'm in the area.

What I was able to divine from the documentation is most simplistically put as thus (for encoding), as an example:

type SomeData struct {
    /* Fill in the blanks. */
}
data := SomeData{}
buf := &bytes.Buffer{}
encoder := codec.NewEncoder(buf, &codec.MsgpackHandle{})
err := encoder.Encode(&data)

This will write the serialized version of data into buf, or at least should (off the top of my head). There's probably a mistake here or there, but that should get you started in the right direction. Decoding should be fairly similar.

I actually really like ugorji's API, because it works somewhat analogous to the standard library's JSON serializers, only better. You can use it with io.Reader/Writer much more cleanly and it's fairly easy to shoehorn into a REST API or similar if you want to cut down on network traffic overhead a bit more than using, say, JSON. And it's pretty dang fast.

I think the only problem with the documentation is that it demonstrates how to use all the codecs at once. There's nothing wrong with doing that, but if you're new to Golang, it'll probably make your eyes bug out. :) The only advice I can give is to focus on one codec at a time and follow those through the example--it just looks intimidating at first blush.

(The example above doesn't configure the codec, though, so you'll need to appeal to the docs for that.)

ugorji commented 9 years ago

I will publish a primer early next year.

giulioungaretti commented 9 years ago

This is great news ! Thank you a lot ! On Wed 24 Dec 2014 at 16:17 ugorji notifications@github.com wrote:

I will publish a primer early next year.

— Reply to this email directly or view it on GitHub https://github.com/ugorji/go/issues/42#issuecomment-68057890.

ugorji commented 9 years ago

Primer published: http://ugorji.net/blog/go-codec-primer