Comments (4)
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.)
from go.
I will publish a primer early next year.
from go.
This is great news ! Thank you a lot !
On Wed 24 Dec 2014 at 16:17 ugorji [email protected] wrote:
I will publish a primer early next year.
—
Reply to this email directly or view it on GitHub
#42 (comment).
from go.
Primer published: http://ugorji.net/blog/go-codec-primer
from go.
Related Issues (20)
- omitempty handling for arrays disagrees with the standard encoding/json HOT 2
- codec.MsgpackHandle.RawToString is confusingly named HOT 2
- Go 1.20 - invalid memory address or nil pointer dereference HOT 5
- Msgpack deserialization with codecgen produces wrong result HOT 3
- Unexpected encoding with interface{} key using Canonical and MapKeyAsString.
- Decoding a slice of structs encoded as arrays into a slice of structs without the same number of fields HOT 2
- Duplicate key inside of a map triggers a "cannot decode unsigned integer" msgpack decode error HOT 1
- Efficient direct conversion between supported formats? HOT 2
- Expose Handle.Name() in some form through Encoder and Decoder for use by codec.Selfer HOT 1
- `io.ErrUnexpectedEOF` should be returned instead of `io.EOF` when only partial data is present
- Add `DecodeOptions.IntType` and `DecodeOptions.FloatType` ? HOT 1
- Docs do not seem to mention case-sensitive field handling
- mem leak? HOT 1
- Tests use rand.Intn(1) for boolean rand, but always returns 0
- Decoder accepts indefinite-length CBOR strings containing chunks with mismatched major types HOT 1
- UTF-8 validation isn't applied to CBOR text strings nested inside an indefinite-length text string HOT 2
- Add support for github.com/go-json-experiment/json / UnmarshalerV2 ? HOT 1
- runtime error with golang master (furture go 1.22)
- Leading zeros is not allowed in rfc7159
- attr.go
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go.