Documentation
¶
Index ¶
- Constants
- Variables
- func Append(base proto.Message, path string, new any, opts ...Option) error
- func Clear(base proto.Message, path string, opts ...Option) error
- func Copy(base proto.Message, targetPath, replacementPath string, opts ...Option) error
- func IdentityConverter(to, from any) (any, error)
- func Insert(base proto.Message, path string, new any, opts ...Option) error
- func Move(base proto.Message, targetPath, replacementPath string, opts ...Option) error
- func NewErrInPath(path string, err error) error
- func Set(base proto.Message, path string, to any, opts ...Option) error
- func Swap(base proto.Message, targetPath, replacementPath string, opts ...Option) error
- type Container
- type ContainerTransformer
- type ContainerTransformerFunc
- type Converter
- type ConverterFunc
- type ErrInPath
- type ErrNotFound
- type ErrOperationFailed
- type List
- type Map
- type Option
- type Path
- func (p Path) First() PathSegment
- func (p Path) Iter(yield func(PathSegment) bool)
- func (p Path) Join(other ...Path) Path
- func (p Path) JoinSegment(segments ...PathSegment) Path
- func (p Path) JoinSegmentValue(segments ...string) Path
- func (p Path) Last() PathSegment
- func (p Path) Segments() []PathSegment
- func (p Path) SegmentsCount() int
- type PathSegment
- func (ps PathSegment) FollowingPath() Path
- func (ps PathSegment) FollowingPathWithCurrentSegment() Path
- func (ps PathSegment) IsFirst() bool
- func (ps PathSegment) IsLast() bool
- func (ps PathSegment) Next() PathSegment
- func (ps PathSegment) PrecedingPath() Path
- func (ps PathSegment) PrecedingPathWithCurrentSegment() Path
- func (ps PathSegment) Previous() PathSegment
- func (ps PathSegment) Value() string
Constants ¶
const PathSegmentSeparator = "."
Variables ¶
var ( ErrAccessToNonContainer = errors.New("connot descend into specified key; attempted to access a sub-value in an entity that is not a message, list or map") ErrAppendToNonList = errors.New("connot append to non list field") ErrInsertToNonList = errors.New("connot insert to non list field") // ErrDeleteNonKey = errors.New("connot delete non key value") ErrMutationOfReadOnlyValue = errors.New("connot mutate read-only value") ErrMismatchingType = protoops.ErrMismatchingType )
var ErrNoContainerTransformationDefined = errors.New("no transformation defined for the provided container")
var ErrNoConversionDefined = errors.New("no conversion defined for the provided types")
Functions ¶
func IdentityConverter ¶
IdentityConverter converts the provided value to itself ensuring that provided types match. It returns ErrNoConversionDefined error for mismatched types.
func NewErrInPath ¶
Types ¶
type Container ¶
type Container interface {
// IsReadOnly reports wether underlying container value is read only.
IsReadOnly() bool
// Self returns underlying container value. For messages it returns its proto.Message value. For lists and maps it returns List and Map interfaces accordingly.
Self() any
// Get returns value associated with the given field / index / key. It returns error if the field / index / key is not found. For scalar types and messages it returns its value. For lists and maps it returns List and Map interfaces accordingly.
Get(string) (any, error)
// GetCopy returns a copy of value associated with the given field / index / key. It returns error if the field / index / key is not found. For scalar types and messages it returns its value. For lists and maps it returns List and Map interfaces accordingly.
GetCopy(string) (any, error)
// GetNew returns a zero value of the type of value associated with the given field / index / key. It returns error if the field is not found or if index / key is malformed. For scalar types and messages it returns its zero value. For lists and maps it returns List and Map interfaces accordingly without any elements.
GetNew(string) (any, error)
// Mutable is a mutable variant of Get method - it returns value associated with the given field / index / key. It returns error if the container is read-only or the field / index / key is not found. For scalar types and messages it returns its value. For lists and maps it returns List and Map interfaces accordingly.
Mutable(string) (any, error)
// Access descends into the given field / index / key and returns a new container for that value. It returns error if the field / index / key is not found or is not associated with a composite type.
Access(string) (Container, error)
// AccessMutable is a mutable variant of Access method - it descends into the given field / index / key and returns a new container for that value. It returns error if the container is read-only, if the field / index / key is not found or is not associated with a composite type.
AccessMutable(string) (Container, error)
// Set stores the provided value under the associated field / index / key. It returns error if the container is read-only, if the field / index / key is not found or if the value has wrong type. When the provided value is nil, it clears the associated field / index / key.
Set(string, any) error
// Append adds the provided value to the end of a list. It returns error if the container is read-only, if the container is not a list or if the value has wrong type.
Append(any) error
// Insert adds the provided value at specified position to a list or map. It returns error if the container is read-only, if the container is not a list or map container, if the index is not found or if the value has wrong type.
Insert(string, any) error
}
Container is a wrapper of a composite protocol buffer type (message, list or map) allowing easy traversal and operations.
func AccessMutable ¶
func MessageContainer ¶
type ContainerTransformer ¶
type ContainerTransformer interface {
// TransformContainer performs container transformation as needed. Returned value must be a valid container or function should return an error. If transformation is not defined for the given container function should return an unwrapped ErrNoContainerTransformationDefined error.
TransformContainer(container Container) (Container, error)
}
ContainerTransformer represents an entity that can modify freshly accessed container.
type ContainerTransformerFunc ¶
ContainerTransformerFunc allows to implement ContainerTransformer interface with a function.
func (ContainerTransformerFunc) TransformContainer ¶
func (fn ContainerTransformerFunc) TransformContainer(container Container) (Container, error)
type Converter ¶
type Converter interface {
// Convert performs type conversion to type of first provided item from the second provided value. Returned value must be of first item type or function should return an error. If conversion is not defined for provided types Convert function should return an unwrapped ErrNoConversionDefined error.
Convert(to, from any) (any, error)
}
Converter represents an entity that can change type of one entity to another.
type ConverterFunc ¶
ConverterFunc allows to implement Converter interface with a function.
type ErrNotFound ¶
func (ErrNotFound) Error ¶
func (e ErrNotFound) Error() string
type ErrOperationFailed ¶
func (ErrOperationFailed) Error ¶
func (e ErrOperationFailed) Error() string
func (ErrOperationFailed) Unwrap ¶
func (e ErrOperationFailed) Unwrap() error
type List ¶
List represents a protocol buffer list value.
func NewList ¶
func NewList(parentField protoreflect.FieldDescriptor, li protoreflect.List) List
type Map ¶
Map represents a protocol buffer map value.
func NewMap ¶
func NewMap(parentField protoreflect.FieldDescriptor, ma protoreflect.Map) Map
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithContainerTransformation ¶
func WithContainerTransformation(transformers ...ContainerTransformer) Option
func WithConversion ¶
type Path ¶
type Path string
func (Path) First ¶
func (p Path) First() PathSegment
func (Path) Iter ¶
func (p Path) Iter(yield func(PathSegment) bool)
func (Path) JoinSegment ¶
func (p Path) JoinSegment(segments ...PathSegment) Path
JoinSegment create a new Path by concatenating all provided segments at the ent of the give Path.
func (Path) JoinSegmentValue ¶
JoinSegmentValue create a new Path by concatenating all provided segment values at the ent of the give Path.
func (Path) Last ¶
func (p Path) Last() PathSegment
func (Path) Segments ¶
func (p Path) Segments() []PathSegment
func (Path) SegmentsCount ¶
type PathSegment ¶
type PathSegment struct {
// contains filtered or unexported fields
}
func (PathSegment) FollowingPath ¶
func (ps PathSegment) FollowingPath() Path
func (PathSegment) FollowingPathWithCurrentSegment ¶
func (ps PathSegment) FollowingPathWithCurrentSegment() Path
func (PathSegment) IsFirst ¶
func (ps PathSegment) IsFirst() bool
func (PathSegment) IsLast ¶
func (ps PathSegment) IsLast() bool
func (PathSegment) Next ¶
func (ps PathSegment) Next() PathSegment
func (PathSegment) PrecedingPath ¶
func (ps PathSegment) PrecedingPath() Path
func (PathSegment) PrecedingPathWithCurrentSegment ¶
func (ps PathSegment) PrecedingPathWithCurrentSegment() Path
func (PathSegment) Previous ¶
func (ps PathSegment) Previous() PathSegment
func (PathSegment) Value ¶
func (ps PathSegment) Value() string