protoutil

package
v0.0.0-...-1b6ad0c Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 15 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthClone = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowClone   = fmt.Errorf("proto: integer overflow")
)
View Source
var Interceptor = func(_ Message) {}

Interceptor will be called with every proto before it is marshaled. Interceptor is not safe to modify concurrently with calls to Marshal.

Functions

func Marshal

func Marshal(pb Message) ([]byte, error)

Marshal encodes pb into the wire format. It is used throughout the code base to intercept calls to proto.Marshal.

func MarshalTo

func MarshalTo(pb Message, dest []byte) (int, error)

MarshalTo encodes pb into the wire format. It is used throughout the code base to intercept calls to pb.MarshalTo.

func RegisterUnclonableType

func RegisterUnclonableType(typ reflect.Type, verbotenKind reflect.Kind)

RegisterUnclonableType registers a type as not being allowed for cloning. This is an added hack on top of the hack to allow clients of this package to disallow cloning of certain types which are not recursed into due to how oneof is implemented. In particular it may be the case that one of the implementations of an interface is unclonable. In this case, due to the type (rather than value) traversal, we'd not discover this fact.

See the comment on Clone.

func Unmarshal

func Unmarshal(data []byte, pb Message) error

Unmarshal parses the protocol buffer representation in buf and places the decoded result in pb. If the struct underlying pb does not match the data in buf, the results can be unpredictable.

Unmarshal resets pb before starting to unmarshal, so any existing data in pb is always removed.

Types

type JSONPb

type JSONPb jsonpb.Marshaler

JSONPb is a gwruntime.Marshaler that uses github.com/gogo/protobuf/jsonpb.

func (*JSONPb) ContentType

func (*JSONPb) ContentType() string

ContentType implements gwruntime.Marshaler.

func (*JSONPb) Delimiter

func (*JSONPb) Delimiter() []byte

Delimiter implements gwruntime.Delimited.

func (*JSONPb) Marshal

func (j *JSONPb) Marshal(v interface{}) ([]byte, error)

Marshal implements gwruntime.Marshaler.

func (*JSONPb) NewDecoder

func (j *JSONPb) NewDecoder(r io.Reader) gwruntime.Decoder

NewDecoder implements gwruntime.Marshaler.

func (*JSONPb) NewEncoder

func (j *JSONPb) NewEncoder(w io.Writer) gwruntime.Encoder

NewEncoder implements gwruntime.Marshaler.

func (*JSONPb) Unmarshal

func (j *JSONPb) Unmarshal(data []byte, v interface{}) error

Unmarshal implements gwruntime.Marshaler.

type Message

type Message interface {
	proto.Message
	MarshalTo(data []byte) (int, error)
	Unmarshal(data []byte) error
	Size() int
}

Message extends the proto.Message interface with the MarshalTo and Size methods we tell gogoproto to generate for us.

func Clone

func Clone(pb Message) Message

Clone uses proto.Clone to return a deep copy of pb. It panics if pb recursively contains any instances of types which are known to be unsupported by proto.Clone.

This function and its associated lint (see build/style_test.go) exist to ensure we do not attempt to proto.Clone types which are not supported by proto.Clone. This hackery is necessary because proto.Clone gives no direct indication that it has incompletely cloned a type; it merely logs to standard output (see https://github.com/golang/protobuf/blob/89238a3/proto/clone.go#L204).

The concrete case against which this is currently guarding may be resolved upstream, see https://github.com/gogo/protobuf/issues/147.

type ProtoPb

type ProtoPb struct{}

ProtoPb is a gwruntime.Marshaler that uses github.com/gogo/protobuf/proto.

func (*ProtoPb) ContentType

func (*ProtoPb) ContentType() string

ContentType implements gwruntime.Marshaler.

func (*ProtoPb) Delimiter

func (*ProtoPb) Delimiter() []byte

Delimiter implements gwruntime.Delimited.

func (*ProtoPb) Marshal

func (*ProtoPb) Marshal(v interface{}) ([]byte, error)

Marshal implements gwruntime.Marshaler.

func (*ProtoPb) NewDecoder

func (*ProtoPb) NewDecoder(r io.Reader) gwruntime.Decoder

NewDecoder implements gwruntime.Marshaler.

func (*ProtoPb) NewEncoder

func (*ProtoPb) NewEncoder(w io.Writer) gwruntime.Encoder

NewEncoder implements gwruntime.Marshaler.

func (*ProtoPb) Unmarshal

func (*ProtoPb) Unmarshal(data []byte, v interface{}) error

Unmarshal implements gwruntime.Marshaler.

type RecursiveAndUncloneable

type RecursiveAndUncloneable struct {
	R    *RecursiveAndUncloneable                            `protobuf:"bytes,1,opt,name=r,proto3" json:"r,omitempty"`
	Uuid github_com_cockroachdb_cockroach_pkg_util_uuid.UUID `protobuf:"bytes,2,opt,name=uuid,proto3,customtype=github.com/ruiaylin/pgparser/utils/uuid.UUID" json:"uuid"`
}

func (*RecursiveAndUncloneable) Descriptor

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

func (*RecursiveAndUncloneable) Marshal

func (m *RecursiveAndUncloneable) Marshal() (dAtA []byte, err error)

func (*RecursiveAndUncloneable) MarshalTo

func (m *RecursiveAndUncloneable) MarshalTo(dAtA []byte) (int, error)

func (*RecursiveAndUncloneable) ProtoMessage

func (*RecursiveAndUncloneable) ProtoMessage()

func (*RecursiveAndUncloneable) Reset

func (m *RecursiveAndUncloneable) Reset()

func (*RecursiveAndUncloneable) Size

func (m *RecursiveAndUncloneable) Size() (n int)

func (*RecursiveAndUncloneable) String

func (m *RecursiveAndUncloneable) String() string

func (*RecursiveAndUncloneable) Unmarshal

func (m *RecursiveAndUncloneable) Unmarshal(dAtA []byte) error

func (*RecursiveAndUncloneable) XXX_DiscardUnknown

func (m *RecursiveAndUncloneable) XXX_DiscardUnknown()

func (*RecursiveAndUncloneable) XXX_Marshal

func (m *RecursiveAndUncloneable) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RecursiveAndUncloneable) XXX_Merge

func (m *RecursiveAndUncloneable) XXX_Merge(src proto.Message)

func (*RecursiveAndUncloneable) XXX_Size

func (m *RecursiveAndUncloneable) XXX_Size() int

func (*RecursiveAndUncloneable) XXX_Unmarshal

func (m *RecursiveAndUncloneable) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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