本文整理汇总了Golang中github.com/maditya/protobuf/proto.Buffer.EncodeVarint方法的典型用法代码示例。如果您正苦于以下问题:Golang Buffer.EncodeVarint方法的具体用法?Golang Buffer.EncodeVarint怎么用?Golang Buffer.EncodeVarint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/maditya/protobuf/proto.Buffer
的用法示例。
在下文中一共展示了Buffer.EncodeVarint方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: _OneofStdTypes_OneofMarshaler
func _OneofStdTypes_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*OneofStdTypes)
// OneOfStdTimes
switch x := m.OneOfStdTimes.(type) {
case *OneofStdTypes_Timestamp:
_ = b.EncodeVarint(1<<3 | proto.WireBytes)
data, err := github_com_maditya_protobuf_types.StdTimeMarshal(*x.Timestamp)
if err != nil {
return err
}
if err := b.EncodeRawBytes(data); err != nil {
return err
}
case *OneofStdTypes_Duration:
_ = b.EncodeVarint(2<<3 | proto.WireBytes)
data, err := github_com_maditya_protobuf_types.StdDurationMarshal(*x.Duration)
if err != nil {
return err
}
if err := b.EncodeRawBytes(data); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("OneofStdTypes.OneOfStdTimes has unexpected type %T", x)
}
return nil
}
示例2: _KeyserverStep_OneofMarshaler
func _KeyserverStep_OneofMarshaler(msg proto1.Message, b *proto1.Buffer) error {
m := msg.(*KeyserverStep)
// type
switch x := m.Type.(type) {
case *KeyserverStep_Update:
_ = b.EncodeVarint(2<<3 | proto1.WireBytes)
if err := b.EncodeMessage(x.Update); err != nil {
return err
}
case *KeyserverStep_EpochDelimiter:
_ = b.EncodeVarint(3<<3 | proto1.WireBytes)
if err := b.EncodeMessage(x.EpochDelimiter); err != nil {
return err
}
case *KeyserverStep_ReplicaSigned:
_ = b.EncodeVarint(4<<3 | proto1.WireBytes)
if err := b.EncodeMessage(x.ReplicaSigned); err != nil {
return err
}
case *KeyserverStep_VerifierSigned:
_ = b.EncodeVarint(5<<3 | proto1.WireBytes)
if err := b.EncodeMessage(x.VerifierSigned); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("KeyserverStep.Type has unexpected type %T", x)
}
return nil
}
示例3: _VerifierStep_OneofMarshaler
func _VerifierStep_OneofMarshaler(msg proto1.Message, b *proto1.Buffer) error {
m := msg.(*VerifierStep)
// type
switch x := m.Type.(type) {
case *VerifierStep_Update:
_ = b.EncodeVarint(1<<3 | proto1.WireBytes)
if err := b.EncodeMessage(x.Update); err != nil {
return err
}
case *VerifierStep_Epoch:
_ = b.EncodeVarint(2<<3 | proto1.WireBytes)
if err := b.EncodeMessage(x.Epoch); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("VerifierStep.Type has unexpected type %T", x)
}
return nil
}
示例4: _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 *MsgWithOneof_Country:
_ = b.EncodeVarint(3<<3 | proto.WireBytes)
_ = b.EncodeStringBytes(x.Country)
case *MsgWithOneof_HomeAddress:
_ = b.EncodeVarint(4<<3 | proto.WireBytes)
_ = b.EncodeStringBytes(x.HomeAddress)
case nil:
default:
return fmt.Errorf("MsgWithOneof.Union has unexpected type %T", x)
}
return nil
}
示例5: _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
}
示例6: _Value_OneofMarshaler
func _Value_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*Value)
// kind
switch x := m.Kind.(type) {
case *Value_NullValue:
_ = b.EncodeVarint(1<<3 | proto.WireVarint)
_ = b.EncodeVarint(uint64(x.NullValue))
case *Value_NumberValue:
_ = b.EncodeVarint(2<<3 | proto.WireFixed64)
_ = b.EncodeFixed64(math.Float64bits(x.NumberValue))
case *Value_StringValue:
_ = b.EncodeVarint(3<<3 | proto.WireBytes)
_ = b.EncodeStringBytes(x.StringValue)
case *Value_BoolValue:
t := uint64(0)
if x.BoolValue {
t = 1
}
_ = b.EncodeVarint(4<<3 | proto.WireVarint)
_ = b.EncodeVarint(t)
case *Value_StructValue:
_ = b.EncodeVarint(5<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.StructValue); err != nil {
return err
}
case *Value_ListValue:
_ = b.EncodeVarint(6<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.ListValue); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("Value.Kind has unexpected type %T", x)
}
return nil
}
示例7: _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
}