func transmitResponse(o io.Writer, res *gomemcached.MCResponse) (err error) {
	if len(res.Body) < 128 {
		_, err = o.Write(res.Bytes())
	} else {
		_, err = o.Write(res.HeaderBytes())
		if err == nil && len(res.Body) > 0 {
			_, err = o.Write(res.Body)
		}
	}
	return
}
Exemple #2
0
func BenchmarkReceive(b *testing.B) {
	res := gomemcached.MCResponse{
		Opcode: gomemcached.SET,
		Cas:    938424885,
		Opaque: 7242,
		Status: 824,
		Key:    []byte("somekey"),
		Body:   []byte("somevalue"),
	}

	datum := res.Bytes()
	datum[0] = gomemcached.REQ_MAGIC
	b.SetBytes(int64(len(datum)))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, err := ReadPacket(bytes.NewReader(datum))
		if err != nil {
			b.Fatalf("Failed to read: %v", err)
		}
	}
}
func transmitResponse(s io.Writer, res *gomemcached.MCResponse) error {
	_, err := s.Write(res.Bytes())
	return err
}