本文整理汇总了Golang中github.com/golang/protobuf/proto.Buffer类的典型用法代码示例。如果您正苦于以下问题:Golang Buffer类的具体用法?Golang Buffer怎么用?Golang Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Marshal
// Marshal serializes a `KVRead`
func (r *KVRead) Marshal(buf *proto.Buffer) error {
if err := buf.EncodeStringBytes(r.Key); err != nil {
return err
}
versionBytes := []byte{}
if r.Version != nil {
versionBytes = r.Version.ToBytes()
}
if err := buf.EncodeRawBytes(versionBytes); err != nil {
return err
}
return nil
}
示例2: _CommitRequest_OneofMarshaler
func _CommitRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*CommitRequest)
// transaction_selector
switch x := m.TransactionSelector.(type) {
case *CommitRequest_Transaction:
b.EncodeVarint(1<<3 | proto.WireBytes)
b.EncodeRawBytes(x.Transaction)
case nil:
default:
return fmt.Errorf("CommitRequest.TransactionSelector has unexpected type %T", x)
}
return nil
}
示例3: unmarshalTrieNodeValueFromBuffer
func unmarshalTrieNodeValueFromBuffer(buffer *proto.Buffer) []byte {
valueMarker, err := buffer.DecodeVarint()
if err != nil {
panic(fmt.Errorf("This error is not excpected: %s", err))
}
if valueMarker == 0 {
return nil
}
value, err := buffer.DecodeRawBytes(false)
if err != nil {
panic(fmt.Errorf("This error is not excpected: %s", err))
}
return value
}
示例4: _CommitRequest_OneofUnmarshaler
func _CommitRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*CommitRequest)
switch tag {
case 1: // transaction_selector.transaction
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeRawBytes(true)
m.TransactionSelector = &CommitRequest_Transaction{x}
return true, err
default:
return false, nil
}
}
示例5: Unmarshal
// Unmarshal deserializes a `KVRead`
func (r *KVRead) Unmarshal(buf *proto.Buffer) error {
var err error
var versionBytes []byte
if r.Key, err = buf.DecodeStringBytes(); err != nil {
return err
}
if versionBytes, err = buf.DecodeRawBytes(false); err != nil {
return err
}
if len(versionBytes) > 0 {
r.Version, _ = version.NewHeightFromBytes(versionBytes)
}
return nil
}
示例6: _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
}
}
示例7: _Interest_OneofUnmarshaler
func _Interest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*Interest)
switch tag {
case 2: // RegInfo.chaincodeRegInfo
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(ChaincodeReg)
err := b.DecodeMessage(msg)
m.RegInfo = &Interest_ChaincodeRegInfo{msg}
return true, err
default:
return false, nil
}
}
示例8: _Interest_OneofMarshaler
func _Interest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*Interest)
// RegInfo
switch x := m.RegInfo.(type) {
case *Interest_ChaincodeRegInfo:
b.EncodeVarint(2<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.ChaincodeRegInfo); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("Interest.RegInfo has unexpected type %T", x)
}
return nil
}
示例9: _Message_OneofUnmarshaler
func _Message_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*Message)
switch tag {
case 1: // protocol.lorawan
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(lorawan.Message)
err := b.DecodeMessage(msg)
m.Protocol = &Message_Lorawan{msg}
return true, err
default:
return false, nil
}
}
示例10: _ZoneServerMsg_OneofMarshaler
func _ZoneServerMsg_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*ZoneServerMsg)
// Msg
switch x := m.Msg.(type) {
case *ZoneServerMsg_ForWardZoneStartupMsg:
b.EncodeVarint(1<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.ForWardZoneStartupMsg); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("ZoneServerMsg.Msg has unexpected type %T", x)
}
return nil
}
示例11: _ZoneServerMsg_OneofUnmarshaler
func _ZoneServerMsg_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*ZoneServerMsg)
switch tag {
case 1: // Msg.ForWardZoneStartupMsg
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(ForWardZoneStartupMsg)
err := b.DecodeMessage(msg)
m.Msg = &ZoneServerMsg_ForWardZoneStartupMsg{msg}
return true, err
default:
return false, nil
}
}
示例12: _PipelineSource_OneofMarshaler
func _PipelineSource_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*PipelineSource)
// typed_pipeline_source
switch x := m.TypedPipelineSource.(type) {
case *PipelineSource_GithubPipelineSource:
b.EncodeVarint(4<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.GithubPipelineSource); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("PipelineSource.TypedPipelineSource has unexpected type %T", x)
}
return nil
}
示例13: marshal
func (chaincodeStateDelta *ChaincodeStateDelta) marshal(buffer *proto.Buffer) {
err := buffer.EncodeVarint(uint64(len(chaincodeStateDelta.UpdatedKVs)))
if err != nil {
panic(fmt.Errorf("This error should not occur: %s", err))
}
for key, valueHolder := range chaincodeStateDelta.UpdatedKVs {
err = buffer.EncodeStringBytes(key)
if err != nil {
panic(fmt.Errorf("This error should not occur: %s", err))
}
chaincodeStateDelta.marshalValueWithMarker(buffer, valueHolder.Value)
chaincodeStateDelta.marshalValueWithMarker(buffer, valueHolder.PreviousValue)
}
return
}
示例14: _PipelineSource_OneofUnmarshaler
func _PipelineSource_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*PipelineSource)
switch tag {
case 4: // typed_pipeline_source.github_pipeline_source
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(GithubPipelineSource)
err := b.DecodeMessage(msg)
m.TypedPipelineSource = &PipelineSource_GithubPipelineSource{msg}
return true, err
default:
return false, nil
}
}
示例15: _Policy_OneofUnmarshaler
func _Policy_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*Policy)
switch tag {
case 1: // Type.SignaturePolicy
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(SignaturePolicyEnvelope)
err := b.DecodeMessage(msg)
m.Type = &Policy_SignaturePolicy{msg}
return true, err
default:
return false, nil
}
}