• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang xdr.NewWriter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/calmh/xdr.NewWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewWriter函数的具体用法?Golang NewWriter怎么用?Golang NewWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewWriter函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: AppendXDR

func (o FileInfoTruncated) AppendXDR(bs []byte) []byte {
	var aw = xdr.AppendWriter(bs)
	var xw = xdr.NewWriter(&aw)
	o.encodeXDR(xw)
	return []byte(aw)
}
开发者ID:baa-archieve,项目名称:syncthing,代码行数:6,代码来源:message_xdr.go


示例17: AppendXDR

func (o fileVersion) AppendXDR(bs []byte) ([]byte, error) {
	var aw = xdr.AppendWriter(bs)
	var xw = xdr.NewWriter(&aw)
	_, err := o.encodeXDR(xw)
	return []byte(aw), err
}
开发者ID:qbit,项目名称:syncthing,代码行数:6,代码来源:leveldb_xdr.go



注:本文中的github.com/calmh/xdr.NewWriter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang xdr.Padding函数代码示例发布时间:2022-05-23
下一篇:
Golang xdr.NewReader函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap