proto

package
v0.0.0-...-ca44064 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) *wrapperspb.BoolValue

func Bytes

func Bytes(b []byte) *wrapperspb.BytesValue

func Double

func Double(f float64) *wrapperspb.DoubleValue

func Duration

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

func FindMessageType

func FindMessageType(typeUrl string) (protoreflect.MessageType, error)

func FromJSON

func FromJSON(content []byte, out proto.Message) error

func FromYAML

func FromYAML(content []byte, pb proto.Message) error

Note: we continue to use github.com/golang/protobuf/jsonpb because it unmarshals types the way we expect in go. See https://github.com/golang/protobuf/issues/1374

func MarshalAnyDeterministic

func MarshalAnyDeterministic(pb proto.Message) (*anypb.Any, error)

When saving Snapshot in SnapshotCache we generate version based on proto.Equal() Therefore we need deterministic way of marshaling Any which is part of the Protobuf on which we execute Equal()

Based on proto.MarshalAny

func Merge

func Merge(dst, src proto.Message)

func MergeAnys

func MergeAnys(dst *anypb.Any, src *anypb.Any) (*anypb.Any, error)

MergeAnys merges two Any messages of the same type. We cannot just use proto#Merge on Any directly because values are encoded in byte slices. Instead we have to unmarshal types, merge them and marshal again.

func MustMarshalAny

func MustMarshalAny(pb proto.Message) *anypb.Any

func MustMarshalJSON

func MustMarshalJSON(in proto.Message) []byte

func MustNewValueForStruct

func MustNewValueForStruct(in interface{}) *structpb.Value

func MustStruct

func MustStruct(in map[string]interface{}) *structpb.Struct

func MustTimestampFromProto

func MustTimestampFromProto(ts *timestamppb.Timestamp) *time.Time

func MustTimestampProto

func MustTimestampProto(t time.Time) *timestamppb.Timestamp

func MustToStruct

func MustToStruct(message proto.Message) *structpb.Struct

func NewValueForStruct

func NewValueForStruct(in interface{}) (*structpb.Value, error)

func Now

func Now() *timestamppb.Timestamp

func Replace

func Replace(dst, src proto.Message)

func String

func String(s string) *wrapperspb.StringValue

func Struct

func Struct(in map[string]interface{}) (*structpb.Struct, error)

func ToJSON

func ToJSON(pb proto.Message) ([]byte, error)

func ToJSONIndent

func ToJSONIndent(pb proto.Message, indent string) ([]byte, error)

func ToStruct

func ToStruct(message proto.Message) (*structpb.Struct, error)

Converts loosely typed Struct to strongly typed Message

func ToTyped

func ToTyped(protoStruct *structpb.Struct, message proto.Message) error

Converts loosely typed Struct to strongly typed Message

func ToYAML

func ToYAML(pb proto.Message) ([]byte, error)

func UInt32

func UInt32(u uint32) *wrapperspb.UInt32Value

func UInt64

func UInt64(u uint64) *wrapperspb.UInt64Value

func UnmarshalAnyTo

func UnmarshalAnyTo(src *anypb.Any, dst proto.Message) error

Types

type MergeFunction

type MergeFunction func(dst, src protoreflect.Message)
var ReplaceMergeFn MergeFunction = func(dst, src protoreflect.Message) {
	dst.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
		dst.Clear(fd)
		return true
	})
	src.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
		dst.Set(fd, v)
		return true
	})
}

ReplaceMergeFn instead of merging all subfields one by one, takes src and set it to dest

type OptionFn

type OptionFn func(options mergeOptions) mergeOptions

func MergeFunctionOptionFn

func MergeFunctionOptionFn(name protoreflect.FullName, function MergeFunction) OptionFn

Jump to

Keyboard shortcuts

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