| 1 | **MessagePack and [Binc](http://github.com/ugorji/binc) Codec for [Go](http://golang.org) Language.** |
| 2 | |
| 3 | *A High Performance, Feature-Rich, Idiomatic encode/decode and rpc library*. |
| 4 | |
| 5 | To install: |
| 6 | |
| 7 | go get github.com/ugorji/go/codec |
| 8 | |
| 9 | Source: [http://github.com/ugorji/go] |
| 10 | Online documentation: [http://godoc.org/github.com/ugorji/go/codec] |
| 11 | |
| 12 | Typical usage: |
| 13 | |
| 14 | ```go |
| 15 | // create and use decoder/encoder |
| 16 | var ( |
| 17 | v interface{} // value to decode/encode into |
| 18 | r io.Reader |
| 19 | w io.Writer |
| 20 | b []byte |
| 21 | mh codec.MsgpackHandle |
| 22 | ) |
| 23 | |
| 24 | dec = codec.NewDecoder(r, &mh) |
| 25 | dec = codec.NewDecoderBytes(b, &mh) |
| 26 | err = dec.Decode(&v) |
| 27 | |
| 28 | enc = codec.NewEncoder(w, &mh) |
| 29 | enc = codec.NewEncoderBytes(&b, &mh) |
| 30 | err = enc.Encode(v) |
| 31 | |
| 32 | //RPC Server |
| 33 | go func() { |
| 34 | for { |
| 35 | conn, err := listener.Accept() |
| 36 | rpcCodec := codec.GoRpc.ServerCodec(conn, h) |
| 37 | //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h) |
| 38 | rpc.ServeCodec(rpcCodec) |
| 39 | } |
| 40 | }() |
| 41 | |
| 42 | //RPC Communication (client side) |
| 43 | conn, err = net.Dial("tcp", "localhost:5555") |
| 44 | rpcCodec := codec.GoRpc.ClientCodec(conn, h) |
| 45 | //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h) |
| 46 | client := rpc.NewClientWithCodec(rpcCodec) |
| 47 | ``` |