prototool

package
v19.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_internal_tool_prototool_prototool_proto protoreflect.FileDescriptor

Functions

func BuildPredeclaredProtoFiles added in v19.1.0

func BuildPredeclaredProtoFiles(fds ...protoreflect.FileDescriptor) (*protoregistry.Files, error)

func ConstPayload added in v19.4.0

func ConstPayload(m proto.Message) func() []byte

ConstPayload marshals a message whose contents are fixed, producing the bytes once on first use rather than on every call. Deferring the marshal is what makes the result safe to hold in a package-level variable of the package that generated m's type: those types register themselves in an init function, which runs after that package's variables are initialized. A marshal failure is a build-time mistake rather than a runtime condition, so it panics.

The returned bytes are shared by every caller and must not be modified.

func DefaultSlice

func DefaultSlice[V any](v *[]V, defaultValue []V)

func DefaultVal

func DefaultVal[V comparable](v *V, defaultValue V)

func DefaultValPtr

func DefaultValPtr[V any](v **V, defaultValue V)

func Duration

func Duration(d **durationpb.Duration, defaultValue time.Duration)

func HeaderKVToHTTPHeader

func HeaderKVToHTTPHeader(from []*HeaderKV) http.Header

HeaderKVToHTTPHeader converts the internal []*HeaderKV type to http.Header. The returned http.Header has canonicalized keys.

func MarshalAny added in v19.5.0

func MarshalAny(m Marshaler, msg proto.Message) ([]byte, error)

MarshalAny marshals msg packed into an Any, so that UnmarshalAny can instantiate a message of the same type. msg is packed with NewAny. The Any itself is not validated, only marshaled with m's options.

func NewAny added in v19.5.0

func NewAny(m Marshaler, msg proto.Message) (*anypb.Any, error)

NewAny packs msg into an Any, validating it through m and marshaling it with m's options. protovalidate does not look inside an Any, so this is what validates the packed message.

func NotNil

func NotNil(field any)

NotNil ensures that the memory that the field pointer is pointing to is not nil. field must be a valid pointer. It's target is checked for nil-ness and populated if it's nil.

func ParseYAMLToProto

func ParseYAMLToProto(rawYAML []byte, msg proto.Message) error

func QueryKVToURLValues

func QueryKVToURLValues(from []*QueryKV) url.Values

func UnmarshalAny added in v19.5.0

func UnmarshalAny(m Marshaler, data []byte) (proto.Message, error)

UnmarshalAny reverses MarshalAny. The Any itself is not validated, only unmarshaled with m's options. The message it holds is unpacked with UnmarshalAnyNew.

func UnmarshalAnyNew added in v19.5.0

func UnmarshalAnyNew(m Marshaler, a *anypb.Any) (proto.Message, error)

UnmarshalAnyNew unpacks the message a holds into a new message of the type a names, unmarshaling it with m's options and validating it through m.

func UnmarshalAnyTo added in v19.5.0

func UnmarshalAnyTo(m Marshaler, a *anypb.Any, dst proto.Message) error

UnmarshalAnyTo unpacks the message a holds into dst, unmarshaling it with m's options and validating it through m. It fails if a holds a message of a type other than that of dst.

func UnmarshalProto

func UnmarshalProto(opts proto.UnmarshalOptions, data mem.BufferSlice, v any) error

func UnmarshalTyped added in v19.3.0

func UnmarshalTyped[O proto.Message](m Marshaler, data []byte) (O, error)

UnmarshalTyped unmarshals data into a new message of type O through m.

Types

type HeaderKV

type HeaderKV struct {
	Key   []byte        `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
	Value *HeaderValues `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func HTTPHeaderToHeaderKV

func HTTPHeaderToHeaderKV(from http.Header) []*HeaderKV

func (*HeaderKV) Descriptor deprecated

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

Deprecated: Use HeaderKV.ProtoReflect.Descriptor instead.

func (*HeaderKV) GetKey

func (x *HeaderKV) GetKey() []byte

func (*HeaderKV) GetValue

func (x *HeaderKV) GetValue() *HeaderValues

func (*HeaderKV) ProtoMessage

func (*HeaderKV) ProtoMessage()

func (*HeaderKV) ProtoReflect

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

func (*HeaderKV) Reset

func (x *HeaderKV) Reset()

func (*HeaderKV) String

func (x *HeaderKV) String() string

type HeaderValues

type HeaderValues struct {
	Value [][]byte `protobuf:"bytes,1,rep,name=value" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*HeaderValues) Descriptor deprecated

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

Deprecated: Use HeaderValues.ProtoReflect.Descriptor instead.

func (*HeaderValues) GetValue

func (x *HeaderValues) GetValue() [][]byte

func (*HeaderValues) ProtoMessage

func (*HeaderValues) ProtoMessage()

func (*HeaderValues) ProtoReflect

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

func (*HeaderValues) Reset

func (x *HeaderValues) Reset()

func (*HeaderValues) String

func (x *HeaderValues) String() string

type HttpRequest

type HttpRequest struct {
	Method  string      `protobuf:"bytes,1,opt,name=method" json:"method,omitempty"`
	Header  []*HeaderKV `protobuf:"bytes,2,rep,name=header" json:"header,omitempty"`
	UrlPath string      `protobuf:"bytes,3,opt,name=url_path,json=urlPath" json:"url_path,omitempty"`
	Query   []*QueryKV  `protobuf:"bytes,4,rep,name=query" json:"query,omitempty"`
	// contains filtered or unexported fields
}

func (*HttpRequest) Descriptor deprecated

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

Deprecated: Use HttpRequest.ProtoReflect.Descriptor instead.

func (*HttpRequest) GetHeader

func (x *HttpRequest) GetHeader() []*HeaderKV

func (*HttpRequest) GetMethod

func (x *HttpRequest) GetMethod() string

func (*HttpRequest) GetQuery

func (x *HttpRequest) GetQuery() []*QueryKV

func (*HttpRequest) GetUrlPath

func (x *HttpRequest) GetUrlPath() string

func (*HttpRequest) HTTPHeader

func (x *HttpRequest) HTTPHeader() http.Header

func (*HttpRequest) IsUpgrade

func (x *HttpRequest) IsUpgrade() bool

func (*HttpRequest) ProtoMessage

func (*HttpRequest) ProtoMessage()

func (*HttpRequest) ProtoReflect

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

func (*HttpRequest) Reset

func (x *HttpRequest) Reset()

func (*HttpRequest) String

func (x *HttpRequest) String() string

func (*HttpRequest) URLQuery

func (x *HttpRequest) URLQuery() url.Values

type HttpResponse

type HttpResponse struct {
	StatusCode int32       `protobuf:"varint,1,opt,name=status_code,json=statusCode" json:"status_code,omitempty"`
	Status     string      `protobuf:"bytes,2,opt,name=status" json:"status,omitempty"`
	Header     []*HeaderKV `protobuf:"bytes,3,rep,name=header" json:"header,omitempty"`
	// contains filtered or unexported fields
}

func (*HttpResponse) Descriptor deprecated

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

Deprecated: Use HttpResponse.ProtoReflect.Descriptor instead.

func (*HttpResponse) GetHeader

func (x *HttpResponse) GetHeader() []*HeaderKV

func (*HttpResponse) GetStatus

func (x *HttpResponse) GetStatus() string

func (*HttpResponse) GetStatusCode

func (x *HttpResponse) GetStatusCode() int32

func (*HttpResponse) HTTPHeader

func (x *HttpResponse) HTTPHeader() http.Header

func (*HttpResponse) ProtoMessage

func (*HttpResponse) ProtoMessage()

func (*HttpResponse) ProtoReflect

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

func (*HttpResponse) Reset

func (x *HttpResponse) Reset()

func (*HttpResponse) String

func (x *HttpResponse) String() string

type Marshaler added in v19.5.0

type Marshaler interface {
	protovalidate.Validator
	Marshal(proto.Message) ([]byte, error)
	MarshalOpts(proto.Message, proto.MarshalOptions) ([]byte, error)
	Unmarshal([]byte, proto.Message) error
	UnmarshalOpts([]byte, proto.Message, proto.UnmarshalOptions) error
	// MarshalOptions returns the options Marshal uses.
	MarshalOptions() proto.MarshalOptions
	// UnmarshalOptions returns the options Unmarshal uses.
	UnmarshalOptions() proto.UnmarshalOptions
}

Marshaler can marshal, unmarshal, and validate protobuf messages.

type NopValidator

type NopValidator struct{}

func (NopValidator) Validate

type ProtoErrMarshaler

type ProtoErrMarshaler struct {
	Marshaler Marshaler
}

ProtoErrMarshaler marshals errors that are protobuf messages. The error is packed into an Any so that Unmarshal can restore its type.

func (ProtoErrMarshaler) Marshal

func (m ProtoErrMarshaler) Marshal(err error) ([]byte, error)

func (ProtoErrMarshaler) Unmarshal

func (m ProtoErrMarshaler) Unmarshal(data []byte) (error, error)

type QueryKV

type QueryKV struct {
	Key   []byte       `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
	Value *QueryValues `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func URLValuesToQueryKV

func URLValuesToQueryKV(from url.Values) []*QueryKV

func (*QueryKV) Descriptor deprecated

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

Deprecated: Use QueryKV.ProtoReflect.Descriptor instead.

func (*QueryKV) GetKey

func (x *QueryKV) GetKey() []byte

func (*QueryKV) GetValue

func (x *QueryKV) GetValue() *QueryValues

func (*QueryKV) ProtoMessage

func (*QueryKV) ProtoMessage()

func (*QueryKV) ProtoReflect

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

func (*QueryKV) Reset

func (x *QueryKV) Reset()

func (*QueryKV) String

func (x *QueryKV) String() string

type QueryValues

type QueryValues struct {
	Value [][]byte `protobuf:"bytes,1,rep,name=value" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*QueryValues) Descriptor deprecated

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

Deprecated: Use QueryValues.ProtoReflect.Descriptor instead.

func (*QueryValues) GetValue

func (x *QueryValues) GetValue() [][]byte

func (*QueryValues) ProtoMessage

func (*QueryValues) ProtoMessage()

func (*QueryValues) ProtoReflect

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

func (*QueryValues) Reset

func (x *QueryValues) Reset()

func (*QueryValues) String

func (x *QueryValues) String() string

type ValidatingMarshaler added in v19.5.0

type ValidatingMarshaler struct {
	protovalidate.Validator
	DefaultMarshalOpts   proto.MarshalOptions
	DefaultUnmarshalOpts proto.UnmarshalOptions
}

ValidatingMarshaler validates a message before marshaling it and after unmarshaling it. Marshal and Unmarshal use the default options, MarshalOpts and UnmarshalOpts use the supplied ones.

func (*ValidatingMarshaler) Marshal added in v19.5.0

func (v *ValidatingMarshaler) Marshal(m proto.Message) ([]byte, error)

func (*ValidatingMarshaler) MarshalOptions added in v19.5.0

func (v *ValidatingMarshaler) MarshalOptions() proto.MarshalOptions

func (*ValidatingMarshaler) MarshalOpts added in v19.5.0

func (v *ValidatingMarshaler) MarshalOpts(m proto.Message, o proto.MarshalOptions) ([]byte, error)

func (*ValidatingMarshaler) Unmarshal added in v19.5.0

func (v *ValidatingMarshaler) Unmarshal(b []byte, m proto.Message) error

func (*ValidatingMarshaler) UnmarshalOptions added in v19.5.0

func (v *ValidatingMarshaler) UnmarshalOptions() proto.UnmarshalOptions

func (*ValidatingMarshaler) UnmarshalOpts added in v19.5.0

func (v *ValidatingMarshaler) UnmarshalOpts(b []byte, m proto.Message, o proto.UnmarshalOptions) error

Jump to

Keyboard shortcuts

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