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


Golang Header.Arg方法代碼示例

本文整理匯總了Golang中github.com/mdlayher/aoe.Header.Arg方法的典型用法代碼示例。如果您正苦於以下問題:Golang Header.Arg方法的具體用法?Golang Header.Arg怎麽用?Golang Header.Arg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/mdlayher/aoe.Header的用法示例。


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

示例1: headersEqual

// headersEqual compares a response and request AoE header for equality, but
// does not factor in their Arg fields.
func headersEqual(res, req aoe.Header) bool {
	if !res.FlagResponse {
		panic("response AoE header did not have FlagResponse set, please verify parameter order")
	}

	// Set request's response flag for comparison
	req.FlagResponse = true

	// Clear arguments of both request and response so we can compare the
	// headers, and because the arguments are compared separately
	req.Arg = nil
	res.Arg = nil

	return reflect.DeepEqual(res, req)
}
開發者ID:ConfusedReality,項目名稱:server_distributed-storage_torus,代碼行數:17,代碼來源:aoe_test.go

示例2: testBPFProgram

// testBPFProgram builds a BPF program for the input server and compares the
// output of the program against the input AoE header, returning whether or
// not the header was accepted by the filter.
func testBPFProgram(t *testing.T, s *Server, h *aoe.Header) bool {
	filter, ok := bpf.Disassemble(s.mustAssembleBPF(testMTU))
	if !ok {
		t.Fatal("failed to decode all BPF instructions")
	}

	vm, err := bpf.NewVM(filter)
	if !ok {
		t.Fatalf("failed to load BPF program: %v", err)
	}

	// Fill in empty AoE header fields not relevant to this test
	h.Version = aoe.Version
	h.Command = aoe.CommandQueryConfigInformation
	h.Arg = &aoe.ConfigArg{
		Command: aoe.ConfigCommandRead,
	}

	hb, err := h.MarshalBinary()
	if err != nil {
		t.Fatalf("failed to marshal AoE header to binary: %v", err)
	}

	f := &ethernet.Frame{
		EtherType: aoe.EtherType,
		Payload:   hb,
	}
	fb, err := f.MarshalBinary()
	if err != nil {
		t.Fatalf("failed to marshal Ethernet frame to binary: %v", err)
	}

	out, err := vm.Run(fb)
	if err != nil {
		t.Fatalf("failed to run BPF program: %v", err)
	}

	return out > 0
}
開發者ID:ConfusedReality,項目名稱:server_distributed-storage_torus,代碼行數:42,代碼來源:aoe_test.go


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