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


Golang Buffer.EncodeVarint方法代碼示例

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


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

示例1: _HttpRule_OneofMarshaler

func _HttpRule_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
	m := msg.(*HttpRule)
	// pattern
	switch x := m.Pattern.(type) {
	case *HttpRule_Get:
		_ = b.EncodeVarint(101<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Get)
	case *HttpRule_Post:
		_ = b.EncodeVarint(102<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Post)
	case *HttpRule_Patch:
		_ = b.EncodeVarint(103<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Patch)
	case *HttpRule_Put:
		_ = b.EncodeVarint(104<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Put)
	case *HttpRule_Delete:
		_ = b.EncodeVarint(105<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Delete)
	case nil:
	default:
		return fmt.Errorf("HttpRule.Pattern has unexpected type %T", x)
	}
	return nil
}
開發者ID:limbo-services,項目名稱:core,代碼行數:25,代碼來源:http.pb.go

示例2: _Person_OneofMarshaler

func _Person_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
	m := msg.(*Person)
	// foo_bar
	switch x := m.FooBar.(type) {
	case *Person_Foo:
		_ = b.EncodeVarint(6<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Foo)
	case *Person_Bar:
		_ = b.EncodeVarint(7<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Bar)
	case nil:
	default:
		return fmt.Errorf("Person.FooBar has unexpected type %T", x)
	}
	return nil
}
開發者ID:limbo-services,項目名稱:core,代碼行數:16,代碼來源:example.pb.go

示例3: _MsgWithOneof_OneofMarshaler

func _MsgWithOneof_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
	m := msg.(*MsgWithOneof)
	// union
	switch x := m.Union.(type) {
	case *MsgWithOneof_Title:
		_ = b.EncodeVarint(1<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Title)
	case *MsgWithOneof_Salary:
		_ = b.EncodeVarint(2<<3 | proto.WireVarint)
		_ = b.EncodeVarint(uint64(x.Salary))
	case nil:
	default:
		return fmt.Errorf("MsgWithOneof.Union has unexpected type %T", x)
	}
	return nil
}
開發者ID:limbo-services,項目名稱:protobuf,代碼行數:16,代碼來源:test_objects.pb.go

示例4: _Bar_OneofMarshaler

func _Bar_OneofMarshaler(msg proto1.Message, b *proto1.Buffer) error {
	m := msg.(*Bar)
	// pick
	switch x := m.Pick.(type) {
	case *Bar_A:
		t := uint64(0)
		if x.A {
			t = 1
		}
		_ = b.EncodeVarint(11<<3 | proto1.WireVarint)
		_ = b.EncodeVarint(t)
	case *Bar_B:
		t := uint64(0)
		if x.B {
			t = 1
		}
		_ = b.EncodeVarint(12<<3 | proto1.WireVarint)
		_ = b.EncodeVarint(t)
	case nil:
	default:
		return fmt.Errorf("Bar.Pick has unexpected type %T", x)
	}
	return nil
}
開發者ID:limbo-services,項目名稱:protobuf,代碼行數:24,代碼來源:oneofembed.pb.go

示例5: _Communique_OneofMarshaler

func _Communique_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
	m := msg.(*Communique)
	// union
	switch x := m.Union.(type) {
	case *Communique_Number:
		_ = b.EncodeVarint(5<<3 | proto.WireVarint)
		_ = b.EncodeVarint(uint64(x.Number))
	case *Communique_Name:
		_ = b.EncodeVarint(6<<3 | proto.WireBytes)
		_ = b.EncodeStringBytes(x.Name)
	case *Communique_Data:
		_ = b.EncodeVarint(7<<3 | proto.WireBytes)
		_ = b.EncodeRawBytes(x.Data)
	case *Communique_TempC:
		_ = b.EncodeVarint(8<<3 | proto.WireFixed64)
		_ = b.EncodeFixed64(math.Float64bits(x.TempC))
	case *Communique_Height:
		_ = b.EncodeVarint(9<<3 | proto.WireFixed32)
		_ = b.EncodeFixed32(uint64(math.Float32bits(x.Height)))
	case *Communique_Today:
		_ = b.EncodeVarint(10<<3 | proto.WireVarint)
		_ = b.EncodeVarint(uint64(x.Today))
	case *Communique_Maybe:
		t := uint64(0)
		if x.Maybe {
			t = 1
		}
		_ = b.EncodeVarint(11<<3 | proto.WireVarint)
		_ = b.EncodeVarint(t)
	case *Communique_Delta_:
		_ = b.EncodeVarint(12<<3 | proto.WireVarint)
		_ = b.EncodeZigzag32(uint64(x.Delta))
	case *Communique_Msg:
		_ = b.EncodeVarint(13<<3 | proto.WireBytes)
		if err := b.EncodeMessage(x.Msg); err != nil {
			return err
		}
	case *Communique_Somegroup:
		_ = b.EncodeVarint(14<<3 | proto.WireStartGroup)
		if err := b.Marshal(x.Somegroup); err != nil {
			return err
		}
		_ = b.EncodeVarint(14<<3 | proto.WireEndGroup)
	case nil:
	default:
		return fmt.Errorf("Communique.Union has unexpected type %T", x)
	}
	return nil
}
開發者ID:limbo-services,項目名稱:protobuf,代碼行數:49,代碼來源:test.pb.go


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