Documentation
¶
Index ¶
- func Clone[M proto.Message](m M) M
- func CloneSlice[S ~[]M, M proto.Message](s S) S
- func CopyValue(value *structpb.Value) *structpb.Value
- func MergeList(target *structpb.ListValue, source *structpb.ListValue)
- func MergeStruct(target *structpb.Struct, source *structpb.Struct)
- func MergeStructs(values ...*structpb.Struct) *structpb.Struct
- func MessageSlice[S []E, E proto.Message](s S) []proto.Message
- func MessageToStruct(msg proto.Message) (*structpb.Struct, error)
- func ProtoSlice[S []E, E proto.Message](s []proto.Message) S
- func UnwrapBoolSlice(s []*wrapperspb.BoolValue) []bool
- func UnwrapBytesSlice(s []*wrapperspb.BytesValue) [][]byte
- func UnwrapFloat32Slice(s []*wrapperspb.FloatValue) []float32
- func UnwrapFloat64Slice(s []*wrapperspb.DoubleValue) []float64
- func UnwrapInt32Slice(s []*wrapperspb.Int32Value) []int32
- func UnwrapInt64Slice(s []*wrapperspb.Int64Value) []int64
- func UnwrapStringSlice(s []*wrapperspb.StringValue) []string
- func UnwrapUint32Slice(s []*wrapperspb.UInt32Value) []uint32
- func UnwrapUint64Slice(s []*wrapperspb.UInt64Value) []uint64
- func WrapBoolSlice(s []bool) []*wrapperspb.BoolValue
- func WrapBytesSlice(s [][]byte) []*wrapperspb.BytesValue
- func WrapFloat32Slice(s []float32) []*wrapperspb.FloatValue
- func WrapFloat64Slice(s []float64) []*wrapperspb.DoubleValue
- func WrapInt32Slice(s []int32) []*wrapperspb.Int32Value
- func WrapInt64Slice(s []int64) []*wrapperspb.Int64Value
- func WrapStringSlice(s []string) []*wrapperspb.StringValue
- func WrapUint32Slice(s []uint32) []*wrapperspb.UInt32Value
- func WrapUint64Slice(s []uint64) []*wrapperspb.UInt64Value
- type Builder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
Clone creates a deep copy of a protobuf message.
Parameters:
- m: the message to clone.
Returns:
- M: a deep copy of the input message.
func CloneSlice ¶
CloneSlice creates a deep copy of a slice of protobuf messages. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of messages to clone.
Returns:
- S: a new slice containing deep copies of the input messages.
func CopyValue ¶ added in v0.3.13
CopyValue creates a deep copy of a protobuf Value. Handles all types of Value including structs, lists and primitive types. Returns NullValue for nil or unknown types.
Parameters:
- value: the protobuf Value to copy.
Returns:
- *structpb.Value: a deep copy of the input value, or nil if input is nil.
func MergeList ¶ added in v0.3.13
MergeList merges values from source ListValue into target ListValue. Appends each item from source to target after making a copy.
Parameters:
- target: the list to append values to.
- source: the list to copy values from.
func MergeStruct ¶
MergeStruct merges fields from source struct into target struct. For each field in source, it makes a deep copy and adds to target.
Parameters:
- target: the struct to merge fields into.
- source: the struct to copy fields from.
func MergeStructs ¶ added in v0.3.13
MergeStructs combines multiple structpb.Struct values into a single struct. It creates a new target struct and merges all source structs into it.
Parameters:
- values: the source structs to merge.
Returns:
- *structpb.Struct: the merged struct containing all fields.
func MessageSlice ¶
MessageSlice converts a typed slice of protobuf messages to a slice of the proto.Message interface. If the input slice is nil, it returns nil.
Parameters:
- s: the typed slice of messages.
Returns:
- []proto.Message: the converted slice of interface values.
func MessageToStruct ¶ added in v0.3.13
MessageToStruct converts a protobuf message to a structpb.Struct. It marshals the message to JSON using proto names, then unmarshals into a map and creates a struct from it.
Parameters:
- msg: the protobuf message to convert.
Returns:
- *structpb.Struct: the resulting struct representation.
- error: an error if marshaling or unmarshaling fails.
func ProtoSlice ¶
ProtoSlice converts a slice of proto.Message interface values to a typed slice of a specific message type. Elements that do not match the target type are skipped. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of proto.Message interface values.
Returns:
- S: the typed slice containing only elements of type E.
func UnwrapBoolSlice ¶
func UnwrapBoolSlice(s []*wrapperspb.BoolValue) []bool
UnwrapBoolSlice unwraps a slice of BoolValue wrappers into a slice of bool values. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of BoolValue wrappers.
Returns:
- []bool: the unwrapped slice.
func UnwrapBytesSlice ¶
func UnwrapBytesSlice(s []*wrapperspb.BytesValue) [][]byte
UnwrapBytesSlice unwraps a slice of BytesValue wrappers into a slice of byte slices. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of BytesValue wrappers.
Returns:
- [][]byte: the unwrapped slice.
func UnwrapFloat32Slice ¶
func UnwrapFloat32Slice(s []*wrapperspb.FloatValue) []float32
UnwrapFloat32Slice unwraps a slice of FloatValue wrappers into a slice of float32 values. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of FloatValue wrappers.
Returns:
- []float32: the unwrapped slice.
func UnwrapFloat64Slice ¶
func UnwrapFloat64Slice(s []*wrapperspb.DoubleValue) []float64
UnwrapFloat64Slice unwraps a slice of DoubleValue wrappers into a slice of float64 values. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of DoubleValue wrappers.
Returns:
- []float64: the unwrapped slice.
func UnwrapInt32Slice ¶
func UnwrapInt32Slice(s []*wrapperspb.Int32Value) []int32
UnwrapInt32Slice unwraps a slice of Int32Value wrappers into a slice of int32 values. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of Int32Value wrappers.
Returns:
- []int32: the unwrapped slice.
func UnwrapInt64Slice ¶
func UnwrapInt64Slice(s []*wrapperspb.Int64Value) []int64
UnwrapInt64Slice unwraps a slice of Int64Value wrappers into a slice of int64 values. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of Int64Value wrappers.
Returns:
- []int64: the unwrapped slice.
func UnwrapStringSlice ¶
func UnwrapStringSlice(s []*wrapperspb.StringValue) []string
UnwrapStringSlice unwraps a slice of StringValue wrappers into a slice of string values. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of StringValue wrappers.
Returns:
- []string: the unwrapped slice.
func UnwrapUint32Slice ¶
func UnwrapUint32Slice(s []*wrapperspb.UInt32Value) []uint32
UnwrapUint32Slice unwraps a slice of UInt32Value wrappers into a slice of uint32 values. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of UInt32Value wrappers.
Returns:
- []uint32: the unwrapped slice.
func UnwrapUint64Slice ¶
func UnwrapUint64Slice(s []*wrapperspb.UInt64Value) []uint64
UnwrapUint64Slice unwraps a slice of UInt64Value wrappers into a slice of uint64 values. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of UInt64Value wrappers.
Returns:
- []uint64: the unwrapped slice.
func WrapBoolSlice ¶
func WrapBoolSlice(s []bool) []*wrapperspb.BoolValue
WrapBoolSlice wraps a slice of bool values into a slice of BoolValue wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of bool values.
Returns:
- []*wrapperspb.BoolValue: the wrapped slice.
func WrapBytesSlice ¶
func WrapBytesSlice(s [][]byte) []*wrapperspb.BytesValue
WrapBytesSlice wraps a slice of byte slices into a slice of BytesValue wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of byte slices.
Returns:
- []*wrapperspb.BytesValue: the wrapped slice.
func WrapFloat32Slice ¶
func WrapFloat32Slice(s []float32) []*wrapperspb.FloatValue
WrapFloat32Slice wraps a slice of float32 values into a slice of FloatValue wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of float32 values.
Returns:
- []*wrapperspb.FloatValue: the wrapped slice.
func WrapFloat64Slice ¶
func WrapFloat64Slice(s []float64) []*wrapperspb.DoubleValue
WrapFloat64Slice wraps a slice of float64 values into a slice of DoubleValue wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of float64 values.
Returns:
- []*wrapperspb.DoubleValue: the wrapped slice.
func WrapInt32Slice ¶
func WrapInt32Slice(s []int32) []*wrapperspb.Int32Value
WrapInt32Slice wraps a slice of int32 values into a slice of Int32Value wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of int32 values.
Returns:
- []*wrapperspb.Int32Value: the wrapped slice.
func WrapInt64Slice ¶
func WrapInt64Slice(s []int64) []*wrapperspb.Int64Value
WrapInt64Slice wraps a slice of int64 values into a slice of Int64Value wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of int64 values.
Returns:
- []*wrapperspb.Int64Value: the wrapped slice.
func WrapStringSlice ¶
func WrapStringSlice(s []string) []*wrapperspb.StringValue
WrapStringSlice wraps a slice of string values into a slice of StringValue wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of string values.
Returns:
- []*wrapperspb.StringValue: the wrapped slice.
func WrapUint32Slice ¶
func WrapUint32Slice(s []uint32) []*wrapperspb.UInt32Value
WrapUint32Slice wraps a slice of uint32 values into a slice of UInt32Value wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of uint32 values.
Returns:
- []*wrapperspb.UInt32Value: the wrapped slice.
func WrapUint64Slice ¶
func WrapUint64Slice(s []uint64) []*wrapperspb.UInt64Value
WrapUint64Slice wraps a slice of uint64 values into a slice of UInt64Value wrappers. If the input slice is nil, it returns nil.
Parameters:
- s: the slice of uint64 values.
Returns:
- []*wrapperspb.UInt64Value: the wrapped slice.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds a set of strings with shared lifetime. This differs from strings.Builder, which is for building a single string.
It optimizes memory allocation for large batches where each built string shares the same lifetime and does not need to be independently retained.
func (*Builder) AppendFullName ¶
func (sb *Builder) AppendFullName(prefix protoreflect.FullName, name protoreflect.Name) protoreflect.FullName
AppendFullName appends a name to a prefix and returns the resulting FullName. It is equivalent to protoreflect.FullName.Append, but optimized for large batches where each name has a shared lifetime.
Parameters:
- prefix: the parent FullName to append to.
- name: the name to append.
Returns:
- protoreflect.FullName: the concatenated full name.
func (*Builder) MakeString ¶
MakeString creates a string from a byte slice. It is equivalent to string(b), but optimized for large batches with a shared lifetime.
Parameters:
- b: the bytes to convert into a string.
Returns:
- string: the resulting string.