當前位置: 首頁>>代碼示例>>Golang>>正文


Golang transport.MCResponse類代碼示例

本文整理匯總了Golang中github.com/couchbase/indexing/secondary/dcp/transport.MCResponse的典型用法代碼示例。如果您正苦於以下問題:Golang MCResponse類的具體用法?Golang MCResponse怎麽用?Golang MCResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MCResponse類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: sendAck

func (mc *Client) sendAck(pkt *transport.MCRequest) (int, error) {
	res := transport.MCResponse{
		Opcode: pkt.Opcode,
		Opaque: pkt.Opaque,
		Status: transport.SUCCESS,
	}
	return res.Transmit(mc.conn)
}
開發者ID:jchris,項目名稱:indexing,代碼行數:8,代碼來源:tap_feed.go

示例2: 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)
		}
	}
}
開發者ID:jchris,項目名稱:indexing,代碼行數:19,代碼來源:server_test.go

示例3: 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())
	}
}
開發者ID:jchris,項目名稱:indexing,代碼行數:42,代碼來源:server_test.go

示例4: BenchmarkReceive

func BenchmarkReceive(b *testing.B) {
	res := transport.MCResponse{
		Opcode: transport.SET,
		Cas:    938424885,
		Opaque: 7242,
		Status: 824,
		Key:    []byte("somekey"),
		Body:   []byte("somevalue"),
	}

	datum := res.Bytes()
	datum[0] = transport.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)
		}
	}
}
開發者ID:jchris,項目名稱:indexing,代碼行數:22,代碼來源:server_test.go

示例5: 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)
		}
	}
}
開發者ID:jchris,項目名稱:indexing,代碼行數:23,代碼來源:server_test.go

示例6: transmitResponse

func transmitResponse(o io.Writer, res *transport.MCResponse) (int, error) {
	return res.Transmit(o)
}
開發者ID:jchris,項目名稱:indexing,代碼行數:3,代碼來源:mc_conn_handler.go

示例7: notFound

func notFound(req *transport.MCRequest, s *storage) *transport.MCResponse {
	var response transport.MCResponse
	response.Status = transport.UNKNOWN_COMMAND
	return &response
}
開發者ID:jchris,項目名稱:indexing,代碼行數:5,代碼來源:mc_storage.go


注:本文中的github.com/couchbase/indexing/secondary/dcp/transport.MCResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。