• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang proto.Buffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/maditya/protobuf/proto.Buffer的典型用法代码示例。如果您正苦于以下问题:Golang Buffer类的具体用法?Golang Buffer怎么用?Golang Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: _OneofStdTypes_OneofUnmarshaler

func _OneofStdTypes_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
	m := msg.(*OneofStdTypes)
	switch tag {
	case 1: // OneOfStdTimes.timestamp
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeRawBytes(true)
		if err != nil {
			return true, err
		}
		c := new(time.Time)
		if err2 := github_com_maditya_protobuf_types.StdTimeUnmarshal(c, x); err2 != nil {
			return true, err
		}
		m.OneOfStdTimes = &OneofStdTypes_Timestamp{c}
		return true, err
	case 2: // OneOfStdTimes.duration
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeRawBytes(true)
		if err != nil {
			return true, err
		}
		c := new(time.Duration)
		if err2 := github_com_maditya_protobuf_types.StdDurationUnmarshal(c, x); err2 != nil {
			return true, err
		}
		m.OneOfStdTimes = &OneofStdTypes_Duration{c}
		return true, err
	default:
		return false, nil
	}
}
开发者ID:maditya,项目名称:protobuf,代码行数:35,代码来源:stdtypes.pb.go


示例2: _MsgWithOneof_OneofUnmarshaler

func _MsgWithOneof_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
	m := msg.(*MsgWithOneof)
	switch tag {
	case 1: // union.title
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeStringBytes()
		m.Union = &MsgWithOneof_Title{x}
		return true, err
	case 2: // union.salary
		if wire != proto.WireVarint {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeVarint()
		m.Union = &MsgWithOneof_Salary{int64(x)}
		return true, err
	case 3: // union.Country
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeStringBytes()
		m.Union = &MsgWithOneof_Country{x}
		return true, err
	case 4: // union.home_address
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeStringBytes()
		m.Union = &MsgWithOneof_HomeAddress{x}
		return true, err
	default:
		return false, nil
	}
}
开发者ID:maditya,项目名称:protobuf,代码行数:35,代码来源:test_objects.pb.go


示例3: _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
}
开发者ID:maditya,项目名称:protobuf,代码行数:28,代码来源:stdtypes.pb.go


示例4: _Bar_OneofUnmarshaler

func _Bar_OneofUnmarshaler(msg proto1.Message, tag, wire int, b *proto1.Buffer) (bool, error) {
	m := msg.(*Bar)
	switch tag {
	case 11: // pick.a
		if wire != proto1.WireVarint {
			return true, proto1.ErrInternalBadWireType
		}
		x, err := b.DecodeVarint()
		m.Pick = &Bar_A{x != 0}
		return true, err
	case 12: // pick.b
		if wire != proto1.WireVarint {
			return true, proto1.ErrInternalBadWireType
		}
		x, err := b.DecodeVarint()
		m.Pick = &Bar_B{x != 0}
		return true, err
	default:
		return false, nil
	}
}
开发者ID:maditya,项目名称:protobuf,代码行数:21,代码来源:oneofembed.pb.go


示例5: _VerifierStep_OneofUnmarshaler

func _VerifierStep_OneofUnmarshaler(msg proto1.Message, tag, wire int, b *proto1.Buffer) (bool, error) {
	m := msg.(*VerifierStep)
	switch tag {
	case 1: // type.Update
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(SignedEntryUpdate)
		err := b.DecodeMessage(msg)
		m.Type = &VerifierStep_Update{msg}
		return true, err
	case 2: // type.Epoch
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(SignedEpochHead)
		err := b.DecodeMessage(msg)
		m.Type = &VerifierStep_Epoch{msg}
		return true, err
	default:
		return false, nil
	}
}
开发者ID:maditya,项目名称:coname,代码行数:23,代码来源:verifier.pb.go


示例6: _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
}
开发者ID:maditya,项目名称:coname,代码行数:20,代码来源:verifier.pb.go


示例7: _KeyserverStep_OneofUnmarshaler

func _KeyserverStep_OneofUnmarshaler(msg proto1.Message, tag, wire int, b *proto1.Buffer) (bool, error) {
	m := msg.(*KeyserverStep)
	switch tag {
	case 2: // type.update
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(UpdateRequest)
		err := b.DecodeMessage(msg)
		m.Type = &KeyserverStep_Update{msg}
		return true, err
	case 3: // type.epoch_delimiter
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(EpochDelimiter)
		err := b.DecodeMessage(msg)
		m.Type = &KeyserverStep_EpochDelimiter{msg}
		return true, err
	case 4: // type.replica_signed
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(SignedEpochHead)
		err := b.DecodeMessage(msg)
		m.Type = &KeyserverStep_ReplicaSigned{msg}
		return true, err
	case 5: // type.verifier_signed
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(SignedEpochHead)
		err := b.DecodeMessage(msg)
		m.Type = &KeyserverStep_VerifierSigned{msg}
		return true, err
	default:
		return false, nil
	}
}
开发者ID:maditya,项目名称:coname,代码行数:39,代码来源:replication.pb.go


示例8: _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:maditya,项目名称:protobuf,代码行数:24,代码来源:oneofembed.pb.go


示例9: _Value_OneofUnmarshaler

func _Value_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
	m := msg.(*Value)
	switch tag {
	case 1: // kind.null_value
		if wire != proto.WireVarint {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeVarint()
		m.Kind = &Value_NullValue{NullValue(x)}
		return true, err
	case 2: // kind.number_value
		if wire != proto.WireFixed64 {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeFixed64()
		m.Kind = &Value_NumberValue{math.Float64frombits(x)}
		return true, err
	case 3: // kind.string_value
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeStringBytes()
		m.Kind = &Value_StringValue{x}
		return true, err
	case 4: // kind.bool_value
		if wire != proto.WireVarint {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeVarint()
		m.Kind = &Value_BoolValue{x != 0}
		return true, err
	case 5: // kind.struct_value
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		msg := new(Struct)
		err := b.DecodeMessage(msg)
		m.Kind = &Value_StructValue{msg}
		return true, err
	case 6: // kind.list_value
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		msg := new(ListValue)
		err := b.DecodeMessage(msg)
		m.Kind = &Value_ListValue{msg}
		return true, err
	default:
		return false, nil
	}
}
开发者ID:maditya,项目名称:protobuf,代码行数:51,代码来源:struct.pb.go


示例10: _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
}
开发者ID:maditya,项目名称:protobuf,代码行数:36,代码来源:struct.pb.go


示例11: _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
}
开发者ID:maditya,项目名称:coname,代码行数:30,代码来源:replication.pb.go


示例12: _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
}
开发者ID:maditya,项目名称:protobuf,代码行数:22,代码来源:test_objects.pb.go


示例13: _Communique_OneofUnmarshaler

func _Communique_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
	m := msg.(*Communique)
	switch tag {
	case 5: // union.number
		if wire != proto.WireVarint {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeVarint()
		m.Union = &Communique_Number{int32(x)}
		return true, err
	case 6: // union.name
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeStringBytes()
		m.Union = &Communique_Name{x}
		return true, err
	case 7: // union.data
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeRawBytes(true)
		m.Union = &Communique_Data{x}
		return true, err
	case 8: // union.temp_c
		if wire != proto.WireFixed64 {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeFixed64()
		m.Union = &Communique_TempC{math.Float64frombits(x)}
		return true, err
	case 9: // union.height
		if wire != proto.WireFixed32 {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeFixed32()
		m.Union = &Communique_Height{math.Float32frombits(uint32(x))}
		return true, err
	case 10: // union.today
		if wire != proto.WireVarint {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeVarint()
		m.Union = &Communique_Today{Days(x)}
		return true, err
	case 11: // union.maybe
		if wire != proto.WireVarint {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeVarint()
		m.Union = &Communique_Maybe{x != 0}
		return true, err
	case 12: // union.delta
		if wire != proto.WireVarint {
			return true, proto.ErrInternalBadWireType
		}
		x, err := b.DecodeZigzag32()
		m.Union = &Communique_Delta_{int32(x)}
		return true, err
	case 13: // union.msg
		if wire != proto.WireBytes {
			return true, proto.ErrInternalBadWireType
		}
		msg := new(Reply)
		err := b.DecodeMessage(msg)
		m.Union = &Communique_Msg{msg}
		return true, err
	case 14: // union.somegroup
		if wire != proto.WireStartGroup {
			return true, proto.ErrInternalBadWireType
		}
		msg := new(Communique_SomeGroup)
		err := b.DecodeGroup(msg)
		m.Union = &Communique_Somegroup{msg}
		return true, err
	default:
		return false, nil
	}
}
开发者ID:maditya,项目名称:protobuf,代码行数:79,代码来源:test.pb.go


示例14: _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:maditya,项目名称:protobuf,代码行数:49,代码来源:test.pb.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang descriptor.FieldDescriptorProto类代码示例发布时间:2022-05-23
下一篇:
Golang proto.UnmarshalText函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap