当前位置: 首页>>代码示例>>Golang>>正文


Golang Stream.Buf方法代码示例

本文整理汇总了Golang中github.com/princeofdatamining/golib/stream.Stream.Buf方法的典型用法代码示例。如果您正苦于以下问题:Golang Stream.Buf方法的具体用法?Golang Stream.Buf怎么用?Golang Stream.Buf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/princeofdatamining/golib/stream.Stream的用法示例。


在下文中一共展示了Stream.Buf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: testByteOrder

func testByteOrder(t *testing.T, s *stream.Stream, in *byteorderSample) {
	s.SetSize(256)
	s.Seek(0, 0)
	data := s.Buf()
	whint := in.order.String()
	var m, n int
	m = in.order.PutUint8(data, byte(0x09))
	n = in.order.PutUint32(data[m:], uint32(0x1310))
	n += m
	L := len(in.output)
	if n != L {
		t.Fatalf("%s: outsize must %v, but got %v\n", whint, L, n)
	}
	for i, b := range in.output {
		if b != data[i] {
			t.Fatalf("%s: output[%d] must %2X, but got %2X\n", whint, i, b, data[i])
		}
	}
	for _, read := range in.reads {
		s.Seek(0, 0)
		rhint := read.order.String()
		var b byte
		var i uint32
		b, m = read.order.Uint8(data)
		i, n = read.order.Uint32(data[m:])
		n += m
		if n != L {
			t.Errorf("%s: read by %s: final position must be %v, but got %v\n", whint, rhint, L, n)
		} else if b != read.b {
			t.Errorf("%s: read by %s: expect %.2X, but got %.2X\n", whint, rhint, read.b, b)
		} else if i != read.i {
			t.Errorf("%s: read by %s: expect %.8X, but got %.8X\n", whint, rhint, read.i, i)
		}
	}
}
开发者ID:princeofdatamining,项目名称:golib,代码行数:35,代码来源:binary_test.go

示例2: testMarshal

func testMarshal(t *testing.T, s *stream.Stream, in *marshalTestData) {
	var dummy = &datatype{}
	var n int
	var err error

	// println("*** encoding ***")
	s.SetSize(0)
	w := binutil.NewEncoder2(s, in.order, in.intNs)
	hint := w.String()
	n, err = w.Write(in.data)
	if err != nil {
		t.Errorf("encode(%s) error: %v\n", hint, err)
	}
	if n != in.outsize {
		t.Errorf("encode(%s) size must %v, but got %v\n", hint, in.outsize, n)
	}
	n = len(in.out)
	if n != in.outsize {
		t.Errorf("encode(%s) len(test) must %v, but got %v\n", hint, in.outsize, n)
	}
	b := s.Buf()
	n = len(b)
	if n != in.outsize {
		t.Errorf("encode(%s) len(dump) must %v, but got %v\n", hint, in.outsize, n)
	}
	for i, v := range in.out {
		if v != b[i] {
			t.Fatalf("marshal(%s) out[%v] must %2X, but got %2X\n", hint, i, v, b[i])
		}
	}
	//*
	// println("*** decoding ***")
	s.Seek(0, 0)
	r := binutil.NewDecoder2(s, in.order, in.intNs)
	n, err = r.Read(dummy)
	if err != nil {
		t.Errorf("decode(%s) error: %v\n", hint, err)
	}
	if n != in.outsize {
		t.Errorf("decode(%s) size must %v, but got %v\n", hint, in.outsize, n)
	}
	if !DeepEqual(in.data, dummy) {
		t.Fatalf("decode(%s) DeepEqual false\n", hint)
	}
	//*/
}
开发者ID:princeofdatamining,项目名称:golib,代码行数:46,代码来源:encdec_fixed_test.go


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