Skip to content

Instantly share code, notes, and snippets.

@178inaba
Created September 3, 2016 19:25
Show Gist options
  • Save 178inaba/5d8231103bdeac5e905d251b26b4c71d to your computer and use it in GitHub Desktop.
Save 178inaba/5d8231103bdeac5e905d251b26b4c71d to your computer and use it in GitHub Desktop.
MessagePack in go.
package main
import (
"fmt"
"github.com/ugorji/go/codec"
)
func main() {
material := "onion potato carrot"
ladle := &codec.MsgpackHandle{}
pot := []byte{}
err := codec.NewEncoderBytes(&pot, ladle).Encode(material)
if err != nil {
fmt.Println(err)
}
fmt.Println(pot)
var curry string
err = codec.NewDecoderBytes(pot, ladle).Decode(&curry)
if err != nil {
fmt.Println(err)
}
fmt.Println(curry)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment