cockroach: github.com/cockroachdb/cockroach/pkg/util/protoutil Index | Files

package protoutil

import "github.com/cockroachdb/cockroach/pkg/util/protoutil"

Index

Package Files

clone.go clone.pb.go fuzz_disabled.go jsonpb_marshal.go marshal.go marshaler.go randnullability.go walk.go

Variables

var (
    ErrInvalidLengthClone = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowClone   = fmt.Errorf("proto: integer overflow")
)
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.

func Marshal Uses

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 MarshalToWithoutFuzzing Uses

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

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

func RandomZeroInsertingVisitor Uses

func RandomZeroInsertingVisitor(v reflect.Value)

RandomZeroInsertingVisitor inserts zero values randomly for fields that have the `cockroachdb:"randnullable"` struct tag set. "Randomly" here means the following: upon first encountering a given type (in a field with a tag) a coin is flipped, the result is stored until the process terminates, and the result of the flip is used to determine whether to insert zeroes for this type.

func Unmarshal Uses

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.

func Walk Uses

func Walk(x interface{}, replacingVisitor func(reflect.Value))

Walk .

func ZeroInsertingVisitor Uses

func ZeroInsertingVisitor(v reflect.Value)

ZeroInsertingVisitor replaces all nil struct fields which have the `cockroachdb:"randnullable"` tag by pointers to a zero value.

type JSONPb Uses

type JSONPb jsonpb.Marshaler

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

func (*JSONPb) ContentType Uses

func (*JSONPb) ContentType() string

ContentType implements gwruntime.Marshaler.

func (*JSONPb) Delimiter Uses

func (*JSONPb) Delimiter() []byte

Delimiter implements gwruntime.Delimited.

func (*JSONPb) Marshal Uses

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

Marshal implements gwruntime.Marshaler.

func (*JSONPb) NewDecoder Uses

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

NewDecoder implements gwruntime.Marshaler.

func (*JSONPb) NewEncoder Uses

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

NewEncoder implements gwruntime.Marshaler.

func (*JSONPb) Unmarshal Uses

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

Unmarshal implements gwruntime.Marshaler.

type Message Uses

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 Uses

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.

func MaybeFuzz Uses

func MaybeFuzz(pb Message) Message

MaybeFuzz takes the given proto and, if nullability fuzzing is enabled, walks it using a RandomZeroInsertingVisitor. A suitable copy is made and returned if fuzzing took place.

type ProtoPb Uses

type ProtoPb struct{}

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

func (*ProtoPb) ContentType Uses

func (*ProtoPb) ContentType() string

ContentType implements gwruntime.Marshaler.

func (*ProtoPb) Delimiter Uses

func (*ProtoPb) Delimiter() []byte

Delimiter implements gwruntime.Delimited.

func (*ProtoPb) Marshal Uses

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

Marshal implements gwruntime.Marshaler.

func (*ProtoPb) NewDecoder Uses

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

NewDecoder implements gwruntime.Marshaler.

func (*ProtoPb) NewEncoder Uses

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

NewEncoder implements gwruntime.Marshaler.

func (*ProtoPb) Unmarshal Uses

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

Unmarshal implements gwruntime.Marshaler.

type RecursiveAndUncloneable Uses

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/cockroachdb/cockroach/pkg/util/uuid.UUID" json:"uuid"`
}

func (*RecursiveAndUncloneable) Descriptor Uses

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

func (*RecursiveAndUncloneable) Marshal Uses

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

func (*RecursiveAndUncloneable) MarshalTo Uses

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

func (*RecursiveAndUncloneable) ProtoMessage Uses

func (*RecursiveAndUncloneable) ProtoMessage()

func (*RecursiveAndUncloneable) Reset Uses

func (m *RecursiveAndUncloneable) Reset()

func (*RecursiveAndUncloneable) Size Uses

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

func (*RecursiveAndUncloneable) String Uses

func (m *RecursiveAndUncloneable) String() string

func (*RecursiveAndUncloneable) Unmarshal Uses

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

func (*RecursiveAndUncloneable) XXX_DiscardUnknown Uses

func (m *RecursiveAndUncloneable) XXX_DiscardUnknown()

func (*RecursiveAndUncloneable) XXX_Marshal Uses

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

func (*RecursiveAndUncloneable) XXX_Merge Uses

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

func (*RecursiveAndUncloneable) XXX_Size Uses

func (m *RecursiveAndUncloneable) XXX_Size() int

func (*RecursiveAndUncloneable) XXX_Unmarshal Uses

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

type SimpleMessage Uses

type SimpleMessage = proto.Message

SimpleMessage aliases the proto.Message interface for use in APIs that do not require/support the Message interface defined above. This is needed, for example, to implement error encode/decode functions without a linter error.

Package protoutil imports 19 packages (graph) and is imported by 157 packages. Updated 2019-10-26. Refresh now. Tools for package owners.