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


Golang Stream.Position方法代碼示例

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


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

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

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

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


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