protobuf

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package protobuf provides a Marsha implementation for Protocol Buffers backed by `*.pb.go` files pre-generated by `protoc`.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotPBStructPtr = errors.New("not a protobuf.StructPtr")
	ErrWrongPBType    = errors.New("wrong protocol buffers type")
)
View Source
var File_test2_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Marsha added in v0.0.2

type Marsha struct{}

Marsha is a `marsha.Marsha` implementation for Protocol Buffers backed by `*.pb.go` files pre-generated by `protoc`. Only `MarshalStruct` and `UnmarshalStruct` are supported by this implementation because of the limitation of Protocol Buffers.

func New

func New() *Marsha

New creates a Marsha.

func (*Marsha) MarshalPrimitive added in v0.0.2

func (m *Marsha) MarshalPrimitive(_ interface{}) ([]byte, error)

Not implemented

func (*Marsha) MarshalStruct added in v0.0.2

func (m *Marsha) MarshalStruct(p marsha.StructPtr) ([]byte, error)

func (*Marsha) MarshalStructSlice added in v0.0.2

func (m *Marsha) MarshalStructSlice(_ marsha.StructSlicePtr) ([]byte, error)

Not implemented

func (*Marsha) NewDecoder added in v0.0.2

func (m *Marsha) NewDecoder(_ io.Reader) marsha.Decoder

Not implemented

func (*Marsha) NewEncoder added in v0.0.2

func (m *Marsha) NewEncoder(_ io.Writer) marsha.Encoder

Not implemented

func (*Marsha) UnmarshalPrimitive added in v0.0.2

func (m *Marsha) UnmarshalPrimitive(_ []byte, _ interface{}) (int, error)

Not implemented

func (*Marsha) UnmarshalStruct added in v0.0.2

func (m *Marsha) UnmarshalStruct(bin []byte, p marsha.StructPtr) (read int, err error)

func (*Marsha) UnmarshalStructSlice added in v0.0.2

func (m *Marsha) UnmarshalStructSlice(_ []byte, _ marsha.StructSlicePtr) (int, error)

Not implemented

type Struct

type Struct interface {
	proto.Message
}

Struct implementations should embed their corresponding `proto.Message`s by pointer.

type StructPtr

type StructPtr interface {
	marsha.Struct

	// EmptyPB should return an empty corresponding `proto.Message`.
	EmptyPB() proto.Message

	// LoadPB should load data from `m` into the Struct this StructPtr points to.
	LoadPB(m proto.Message) error

	// PB should return a corresponding `proto.Message` filled with data of the Struct this StructPtr points to.
	PB() proto.Message
}

type Test

type Test struct {
	Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*Test) Descriptor deprecated

func (*Test) Descriptor() ([]byte, []int)

Deprecated: Use Test.ProtoReflect.Descriptor instead.

func (*Test) GetData

func (x *Test) GetData() string

func (*Test) ProtoMessage

func (*Test) ProtoMessage()

func (*Test) ProtoReflect

func (x *Test) ProtoReflect() protoreflect.Message

func (*Test) Reset

func (x *Test) Reset()

func (*Test) String

func (x *Test) String() string

type Test2

type Test2 struct {
	Data2 int32 `protobuf:"varint,1,opt,name=data2,proto3" json:"data2,omitempty"`
	// contains filtered or unexported fields
}

func (*Test2) Descriptor deprecated

func (*Test2) Descriptor() ([]byte, []int)

Deprecated: Use Test2.ProtoReflect.Descriptor instead.

func (*Test2) GetData2

func (x *Test2) GetData2() int32

func (*Test2) ProtoMessage

func (*Test2) ProtoMessage()

func (*Test2) ProtoReflect

func (x *Test2) ProtoReflect() protoreflect.Message

func (*Test2) Reset

func (x *Test2) Reset()

func (*Test2) String

func (x *Test2) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL