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


Golang xdr.NewWriter函數代碼示例

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


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

示例1: TestTypeErr

func TestTypeErr(t *testing.T) {
	m0 := newTestModel()
	m1 := newTestModel()

	ar, aw := io.Pipe()
	br, bw := io.Pipe()

	c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
	c0.Start()
	c1 := NewConnection(c1ID, br, aw, m1, "name", CompressAlways)
	c1.Start()
	c0.ClusterConfig(ClusterConfigMessage{})
	c1.ClusterConfig(ClusterConfigMessage{})

	w := xdr.NewWriter(c0.cw)
	w.WriteUint32(encodeHeader(header{
		version: 0,
		msgID:   0,
		msgType: 42,
	}))
	w.WriteUint32(0) // Avoids reader closing due to EOF

	if !m1.isClosed() {
		t.Error("Connection should close due to unknown message type")
	}
}
開發者ID:hexuallyactive,項目名稱:syncthing,代碼行數:26,代碼來源:protocol_test.go

示例2: TestTypeErr

func TestTypeErr(t *testing.T) {
	m0 := newTestModel()
	m1 := newTestModel()

	ar, aw := io.Pipe()
	br, bw := io.Pipe()

	c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).Connection.(*rawConnection)
	c0.Start()
	c1 := NewConnection(c1ID, br, aw, m1, "name", CompressAlways)
	c1.Start()
	c0.ClusterConfig(ClusterConfigMessage{})
	c1.ClusterConfig(ClusterConfigMessage{})

	w := xdr.NewWriter(c0.cw)
	timeoutWriteHeader(w, header{
		version: 0,
		msgID:   0,
		msgType: 42, // unknown type
	})

	if err := m1.closedError(); err == nil || !strings.Contains(err.Error(), "unknown message type") {
		t.Error("Connection should close due to unknown message type, not", err)
	}
}
開發者ID:escribano,項目名稱:syncthing,代碼行數:25,代碼來源:protocol_test.go

示例3: BenchmarkThisEncoder

func BenchmarkThisEncoder(b *testing.B) {
	w := xdr.NewWriter(ioutil.Discard)
	for i := 0; i < b.N; i++ {
		_, err := s.encodeXDR(w)
		if err != nil {
			b.Fatal(err)
		}
	}
}
開發者ID:ericcapricorn,項目名稱:syncthing,代碼行數:9,代碼來源:bench_test.go

示例4: TestHeaderMarshalUnmarshal

func TestHeaderMarshalUnmarshal(t *testing.T) {
	f := func(ver, id, typ int) bool {
		ver = int(uint(ver) % 16)
		id = int(uint(id) % 4096)
		typ = int(uint(typ) % 256)
		buf := new(bytes.Buffer)
		xw := xdr.NewWriter(buf)
		h0 := header{version: ver, msgID: id, msgType: typ}
		h0.encodeXDR(xw)

		xr := xdr.NewReader(buf)
		var h1 header
		h1.decodeXDR(xr)
		return h0 == h1
	}
	if err := quick.Check(f, nil); err != nil {
		t.Error(err)
	}
}
開發者ID:escribano,項目名稱:syncthing,代碼行數:19,代碼來源:protocol_test.go

示例5: TestTypeErr

func TestTypeErr(t *testing.T) {
	m0 := newTestModel()
	m1 := newTestModel()

	ar, aw := io.Pipe()
	br, bw := io.Pipe()

	c0 := NewConnection(c0ID, ar, bw, m0, "name", true).(wireFormatConnection).next.(*rawConnection)
	NewConnection(c1ID, br, aw, m1, "name", true)

	w := xdr.NewWriter(c0.cw)
	w.WriteUint32(encodeHeader(header{
		version: 0,
		msgID:   0,
		msgType: 42,
	}))
	w.WriteUint32(0)

	if !m1.isClosed() {
		t.Error("Connection should close due to unknown message type")
	}
}
開發者ID:GDXN,項目名稱:syncthing,代碼行數:22,代碼來源:protocol_test.go

示例6: TestVersionErr

func TestVersionErr(t *testing.T) {
	m0 := newTestModel()
	m1 := newTestModel()

	ar, aw := io.Pipe()
	br, bw := io.Pipe()

	c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
	NewConnection(c1ID, br, aw, m1, "name", CompressAlways)

	w := xdr.NewWriter(c0.cw)
	w.WriteUint32(encodeHeader(header{
		version: 2,
		msgID:   0,
		msgType: 0,
	}))
	w.WriteUint32(0) // Avoids reader closing due to EOF

	if !m1.isClosed() {
		t.Error("Connection should close due to unknown version")
	}
}
開發者ID:tomschlenkhoff,項目名稱:syncthing,代碼行數:22,代碼來源:protocol_test.go

示例7: EncodeXDR

func (o Ping) EncodeXDR(w io.Writer) (int, error) {
	var xw = xdr.NewWriter(w)
	return o.EncodeXDRInto(xw)
}
開發者ID:readthecodes,項目名稱:syncthing,代碼行數:4,代碼來源:packets_xdr.go

示例8: AppendXDR

func (o SessionInvitation) AppendXDR(bs []byte) ([]byte, error) {
	var aw = xdr.AppendWriter(bs)
	var xw = xdr.NewWriter(&aw)
	_, err := o.EncodeXDRInto(xw)
	return []byte(aw), err
}
開發者ID:readthecodes,項目名稱:syncthing,代碼行數:6,代碼來源:packets_xdr.go

示例9: EncodeXDR

func (o fileVersion) EncodeXDR(w io.Writer) (int, error) {
	var xw = xdr.NewWriter(w)
	return o.EncodeXDRInto(xw)
}
開發者ID:kattunga,項目名稱:syncthing,代碼行數:4,代碼來源:leveldb_xdr.go

示例10: EncodeXDR

func (o EmptyMessage) EncodeXDR(w io.Writer) (int, error) {
	var xw = xdr.NewWriter(w)
	return o.encodeXDR(xw)
}
開發者ID:baa-archieve,項目名稱:syncthing,代碼行數:4,代碼來源:message_xdr.go

示例11: AppendXDR

func (o FileInfoTruncated) AppendXDR(bs []byte) ([]byte, error) {
	var aw = xdr.AppendWriter(bs)
	var xw = xdr.NewWriter(&aw)
	_, err := o.encodeXDR(xw)
	return []byte(aw), err
}
開發者ID:ericcapricorn,項目名稱:syncthing,代碼行數:6,代碼來源:message_xdr.go

示例12: EncodeXDR

func (o Repository) EncodeXDR(w io.Writer) (int, error) {
	var xw = xdr.NewWriter(w)
	return o.encodeXDR(xw)
}
開發者ID:Blueprint-Marketing,項目名稱:syncthing,代碼行數:4,代碼來源:message_xdr.go

示例13: EncodeXDR

func (o XDRBenchStruct) EncodeXDR(w io.Writer) (int, error) {
	var xw = xdr.NewWriter(w)
	return o.EncodeXDRInto(xw)
}
開發者ID:kattunga,項目名稱:syncthing,代碼行數:4,代碼來源:bench_xdr_test.go

示例14: AppendXDR

func (o ClusterConfigMessage) AppendXDR(bs []byte) ([]byte, error) {
	var aw = xdr.AppendWriter(bs)
	var xw = xdr.NewWriter(&aw)
	_, err := o.EncodeXDRInto(xw)
	return []byte(aw), err
}
開發者ID:oliviercoma,項目名稱:syncthing,代碼行數:6,代碼來源:message_xdr.go

示例15: EncodeXDR

func (o IndexMessage) EncodeXDR(w io.Writer) (int, error) {
	var xw = xdr.NewWriter(w)
	return o.EncodeXDRInto(xw)
}
開發者ID:oliviercoma,項目名稱:syncthing,代碼行數:4,代碼來源:message_xdr.go


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