本文整理汇总了Golang中github.com/couchbase/indexing/secondary/dcp/transport.MCResponse.Size方法的典型用法代码示例。如果您正苦于以下问题:Golang MCResponse.Size方法的具体用法?Golang MCResponse.Size怎么用?Golang MCResponse.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/indexing/secondary/dcp/transport.MCResponse
的用法示例。
在下文中一共展示了MCResponse.Size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkTransmitResNull
func BenchmarkTransmitResNull(b *testing.B) {
res := transport.MCResponse{
Opcode: transport.SET,
Cas: 938424885,
Opaque: 7242,
Status: 824,
Key: []byte("somekey"),
Body: []byte("somevalue"),
}
b.SetBytes(int64(res.Size()))
for i := 0; i < b.N; i++ {
_, err := transmitResponse(ioutil.Discard, &res)
if err != nil {
b.Fatalf("Error transmitting request: %v", err)
}
}
}
示例2: TestTransmitRes
func TestTransmitRes(t *testing.T) {
b := &bytes.Buffer{}
buf := bufio.NewWriter(b)
res := transport.MCResponse{
Opcode: transport.SET,
Cas: 938424885,
Opaque: 7242,
Status: 0x338,
Key: []byte("somekey"),
Body: []byte("somevalue"),
}
_, err := transmitResponse(buf, &res)
if err != nil {
t.Fatalf("Error transmitting request: %v", err)
}
buf.Flush()
expected := []byte{
transport.RES_MAGIC, byte(transport.SET),
0x0, 0x7, // length of key
0x0, // extra length
0x0, // reserved
0x3, 0x38, // Status
0x0, 0x0, 0x0, 0x10, // Length of value
0x0, 0x0, 0x1c, 0x4a, // opaque
0x0, 0x0, 0x0, 0x0, 0x37, 0xef, 0x3a, 0x35, // CAS
's', 'o', 'm', 'e', 'k', 'e', 'y',
's', 'o', 'm', 'e', 'v', 'a', 'l', 'u', 'e'}
if len(b.Bytes()) != res.Size() {
t.Fatalf("Expected %v bytes, got %v", res.Size(),
len(b.Bytes()))
}
if !reflect.DeepEqual(b.Bytes(), expected) {
t.Fatalf("Expected:\n%#v\n -- got -- \n%#v",
expected, b.Bytes())
}
}
示例3: BenchmarkTransmitRes
func BenchmarkTransmitRes(b *testing.B) {
bout := &bytes.Buffer{}
res := transport.MCResponse{
Opcode: transport.SET,
Cas: 938424885,
Opaque: 7242,
Status: 824,
Key: []byte("somekey"),
Body: []byte("somevalue"),
}
b.SetBytes(int64(res.Size()))
for i := 0; i < b.N; i++ {
bout.Reset()
buf := bufio.NewWriterSize(bout, res.Size()*2)
_, err := transmitResponse(buf, &res)
if err != nil {
b.Fatalf("Error transmitting request: %v", err)
}
}
}