Exemple #1
0
// Unmarshal msgpack data from request body.
func (d *MsgpackRequestDecoder) Unmarshal(cx *goweb.Context, v interface{}) error {
	// read body
	data, err := ioutil.ReadAll(cx.Request.Body)
	if err != nil {
		return err
	}

	return msgpack.Unmarshal(data, v, nil)
}
Exemple #2
0
func (t *MsgpackTest) BenchmarkStructMsgpack2(c *C) {
	in := t.structForBenchmark()
	out := &benchmarkStruct{}
	for i := 0; i < c.N; i++ {
		b, err := msgpack2.Marshal(in)
		if err != nil {
			panic(err)
		}
		err = msgpack2.Unmarshal(b, out, nil)
		if err != nil {
			panic(err)
		}
	}
}
Exemple #3
0
func BenchmarkStructUgorjiGoMsgpack(b *testing.B) {
	in := structForBenchmark()
	out := &benchmarkStruct{}
	for i := 0; i < b.N; i++ {
		buf, err := gomsgpack.Marshal(in)
		if err != nil {
			b.Fatal(err)
		}

		err = gomsgpack.Unmarshal(buf, out, nil)
		if err != nil {
			b.Fatal(err)
		}
	}
}
Exemple #4
0
// unmarshal from messagepack.
// This function is used for websocket.Codec.
func msgpackUnmarshal(msg []byte, payloadType byte, v interface{}) (err error) {
	return msgpack.Unmarshal(msg, v, nil)
}