protoutils

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyFieldMaskToNewMessage

func ApplyFieldMaskToNewMessage(source proto.Message, mask *fieldmaskpb.FieldMask) (proto.Message, error)

ApplyFieldMaskToNewMessage creates a new message containing only the fields specified in the FieldMask. If mask is nil then source is returned in its original unalterned state

func ApplyNestedField

func ApplyNestedField(target, source protoreflect.Message, path []string) error

ApplyNestedField sets the value of a nested field in the target message based on the source message.

func ClearProto

func ClearProto(in protoreflect.Message)

ClearProto resets fields on the proto message recursively

func ClearRepeatedFields

func ClearRepeatedFields(msg proto.Message)

ClearRepeatedFields will clear fields thare are of kind list FIX: Doesn't work on map fields

func GenerateFieldMask

func GenerateFieldMask(original, updated protoreflect.ProtoMessage) (*fieldmaskpb.FieldMask, error)

GenerateFieldMask compares two protobuf messages and generates a FieldMask with changed fields.

func MergeSlices

func MergeSlices[T any](base, patch []T, keyFunc MergeFunc[T], mergeItem func(base, patch T) T) []T

func StrategicMerge

func StrategicMerge[T proto.Message](base, patch T, mergeFuncs ...func(b, p T)) T

StrategicMerge merges patch into base strategically as defined by provided merge funcs. Non-repated fields are cleared recursively before mergefuncs are applied to avoid dupliced list elements. Does not currently support removal of list-elements.

Types

type MergeFunc

type MergeFunc[T any] func(item T) string

Jump to

Keyboard shortcuts

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