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


Golang stream.Stream類代碼示例

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


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

示例1: encode_door

func encode_door(t *testing.T, wr *stream.Stream) {
	wr.SetSize(0)
	wr.Seek(0, 0)
	e := binutil.NewProtobufEncoder(wr)
	door := comp
	e.PutInt32(1, door.I32)
	e.PutInt64(2, door.I64)
	e.PutSint32(3, door.S32)
	e.PutSint64(4, door.S64)
	e.PutSfixed32(5, door.D32)
	e.PutSfixed64(6, door.D64)
	e.PutUint32(10, door.U32)
	e.PutUint64(11, door.U64)
	e.PutFixed32(12, door.X32)
	e.PutFixed64(13, door.X64)
	e.PutFloat32(20, door.F32)
	e.PutFloat64(21, door.F64)
	e.PutBool(30, door.B)
	e.PutString(31, door.S)
	e.PutEnum(32, door.E)
	encode_pos(dm, &door.Poslist[0])
	e.PutBytes(40, dm.Buf()[:dm.Position()])
	encode_pos(dm, &door.Poslist[1])
	e.PutBytes(40, dm.Buf()[:dm.Position()])
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:25,代碼來源:encdec_protobuf_test.go

示例2: encode_pos

func encode_pos(wr *stream.Stream, pos *pbPos) {
	wr.SetSize(0)
	wr.Seek(0, 0)
	e := binutil.NewProtobufEncoder(wr)
	e.PutInt32(1, pos.X)
	e.PutInt32(2, pos.Y)
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:7,代碼來源:encdec_protobuf_test.go

示例3: 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

示例4: testReadAt

func testReadAt(t *testing.T, s *stream.Stream, off int64, want_err error, want string) {
	var (
		err error
		msg string
		buf = []byte("......")
		str string
	)
	msg = fmt.Sprintf("ReadAt([<%d>], %d),", len(buf), off)
	_, err = s.ReadAt(buf, off)
	if err != want_err {
		t.Errorf("%s want error `%v`, but got `%v`\n", msg, want_err, err)
		return
	}
	str = string(buf)
	if str != want {
		t.Errorf("%s got `%s`, want `%s`\n", msg, str, want)
	}
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:18,代碼來源:stream_test.go

示例5: testSeekAndReadByte

func testSeekAndReadByte(t *testing.T, s *stream.Stream, off int64, whence int, want_err error, want rune) {
	var (
		err error
		msg string
		b   byte
		c   rune
	)
	msg = fmt.Sprintf("Seek(%d, %d),", off, whence)
	_, err = s.Seek(off, whence)
	if err != want_err {
		t.Errorf("%s want error `%v`, but got `%v`\n", msg, want_err, err)
		return
	}
	b, _ = s.ReadByte()
	c = rune(b)
	if c != want {
		t.Errorf("%s ReadByte() is `%c`, want `%c`\n", msg, c, want)
	}
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:19,代碼來源:stream_test.go

示例6: decode_door

func decode_door(t *testing.T, rd *stream.Stream, last int, door *pbDoor) {
	rd.Seek(0, 0)
	d := binutil.NewProtobufDecoder(rd)
	posidx := 0
	for rd.Position() < last {
		_, tag, wire, _ := d.Tag()
		switch tag {
		case 0:
			t.Fatalf("test protobuf decode: got tag 0 when parse door\n")
		case 1:
			_, door.I32, _ = d.Int32()
		case 3:
			_, door.S32, _ = d.Sint32()
		case 5:
			_, door.D32, _ = d.Sfixed32()
		case 2:
			_, door.I64, _ = d.Int64()
		case 4:
			_, door.S64, _ = d.Sint64()
		case 6:
			_, door.D64, _ = d.Sfixed64()

		case 10:
			_, door.U32, _ = d.Uint32()
		case 12:
			_, door.X32, _ = d.Fixed32()
		case 11:
			_, door.U64, _ = d.Uint64()
		case 13:
			_, door.X64, _ = d.Fixed64()

		case 20:
			_, door.F32, _ = d.Float32()
		case 21:
			_, door.F64, _ = d.Float64()

		case 30:
			_, door.B, _ = d.Bool()
		case 31:
			_, door.S, _ = d.String()
		case 32:
			_, door.E, _ = d.Enum()
		case 40:
			_, u, _ := d.Uint64()
			m, L := int64(u), int(u)
			dm.SetSize(m)
			d.GetBody(dm.Buf()[:m])
			decode_pos(t, dm, L, &door.Poslist[posidx])
			if dm.Position() != L {
				t.Fatalf("test protobuf decode: got pos fail\n")
			}
			posidx++
		default:
			d.Skip(wire)
		}
	}
	if rd.Position() != last {
		t.Fatalf("test protobuf decode: parse pos, error tail position\n")
	}
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:60,代碼來源:encdec_protobuf_test.go

示例7: 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

示例8: decode_pos

func decode_pos(t *testing.T, rd *stream.Stream, last int, pos *pbPos) {
	rd.Seek(0, 0)
	d := binutil.NewProtobufDecoder(rd)
	for rd.Position() < last {
		_, tag, wire, _ := d.Tag()
		switch tag {
		case 0:
			t.Fatalf("test protobuf decode: got tag 0 when parse pos\n")
		case 1:
			_, pos.X, _ = d.Int32()
		case 2:
			_, pos.Y, _ = d.Int32()
		default:
			d.Skip(wire)
		}
	}
	if rd.Position() != last {
		t.Fatalf("test protobuf decode: parse pos, error tail position\n")
	}
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:20,代碼來源:encdec_protobuf_test.go

示例9: testSetSize

func testSetSize(t *testing.T, s *stream.Stream, size int64, want_err error) {
	err := s.SetSize(size)
	if err != want_err {
		t.Errorf("SetSize(%v) want error `%v`, got `%v`\n", size, want_err, err)
	}
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:6,代碼來源:stream_test.go

示例10: testTruncate

func testTruncate(t *testing.T, s *stream.Stream, size int, want_err error) {
	err := s.Truncate(size)
	if err != want_err {
		t.Errorf("Truncate(%v) want error `%v`, got `%v`\n", size, want_err, err)
	}
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:6,代碼來源:stream_test.go

示例11: testPosition

func testPosition(t *testing.T, s *stream.Stream, want int) {
	pos := s.Position()
	if pos != want {
		t.Errorf("Position() want error `%v`, got `%v`\n", want, pos)
	}
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:6,代碼來源:stream_test.go

示例12: testUnreadByte

func testUnreadByte(t *testing.T, s *stream.Stream, want_err error) {
	err := s.UnreadByte()
	if err != want_err {
		t.Errorf("UnreadByte() want error `%v`, got `%v`\n", want_err, err)
	}
}
開發者ID:princeofdatamining,項目名稱:golib,代碼行數:6,代碼來源:stream_test.go


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