easier, faster, but extendable MessagePack Serializer for Golang. / msgpack.org[Go]
If your application serializes only primitive types, array, map and struct, code generation is also recommended. You can get the fastest performance with msgpackgen.
msgpack:"field_name"
msgpack:"-"
Current version is msgpack/v2.
go get -u github.com/shamaton/msgpack/v2
package main
import (
"github.com/shamaton/msgpack/v2"
"net/http"
)
type Struct struct {
String string
}
// simple
func main() {
v := Struct{String: "msgpack"}
d, err := msgpack.Marshal(v)
if err != nil {
panic(err)
}
r := Struct{}
if err = msgpack.Unmarshal(d, &r); err != nil {
panic(err)
}
}
// streaming
func handle(w http.ResponseWriter, r *http.Request) {
var body Struct
if err := msgpack.UnmarshalRead(r, &body); err != nil {
panic(err)
}
if err := msgpack.MarshalWrite(w, body); err != nil {
panic(err)
}
}
This result made from shamaton/msgpack_bench
This library is under the MIT License.