protoutils

package
v0.115.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 24 Imported by: 1

Documentation

Overview

Package protoutils are a collection of util methods for using proto in rdk

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMapToProtoAny added in v0.52.0

func ConvertMapToProtoAny(input map[string]interface{}) (map[string]*anypb.Any, error)

ConvertMapToProtoAny converts a map of string keys and interface{} values to a map of string keys and *anypb.Any values, where each value in the input map is converted to a protobuf Any type.

func ConvertOrientationToProto added in v0.0.6

func ConvertOrientationToProto(o spatialmath.Orientation) *commonpb.Orientation

ConvertOrientationToProto TODO.

func ConvertProtoToOrientation added in v0.0.6

func ConvertProtoToOrientation(o *commonpb.Orientation) spatialmath.Orientation

ConvertProtoToOrientation TODO.

func ConvertStringMapToAnyPBMap added in v0.1.0

func ConvertStringMapToAnyPBMap(params map[string]string) (map[string]*anypb.Any, error)

ConvertStringMapToAnyPBMap takes a string map and parses each value to an Any proto type.

func ConvertStringToAnyPB added in v0.1.0

func ConvertStringToAnyPB(str string) (*anypb.Any, error)

ConvertStringToAnyPB takes a string and parses it to an Any pb type.

func ConvertVectorProtoToR3 added in v0.0.6

func ConvertVectorProtoToR3(v *commonpb.Vector3) r3.Vector

ConvertVectorProtoToR3 TODO.

func ConvertVectorR3ToProto added in v0.0.6

func ConvertVectorR3ToProto(v r3.Vector) *commonpb.Vector3

ConvertVectorR3ToProto TODO.

func DoFromResourceClient added in v0.2.20

func DoFromResourceClient(ctx context.Context, svc ClientDoCommander, name string,
	cmd map[string]interface{},
) (map[string]interface{}, error)

DoFromResourceClient is a helper to allow DoCommand() calls from any client.

func DoFromResourceServer added in v0.2.20

func DoFromResourceServer(
	ctx context.Context,
	res resource.Resource,
	req *commonpb.DoCommandRequest,
) (*commonpb.DoCommandResponse, error)

DoFromResourceServer is a helper to allow DoCommand() calls from any server.

func MessageToProtoV1 added in v0.2.5

func MessageToProtoV1(msg interface{}) protov1.Message

MessageToProtoV1 converts a message to a protov1.Message. It is assumed it is either a proto.Message or a protov1.Message.

func MetadataFromProto added in v0.56.0

func MetadataFromProto(pbMetadata *robotpb.GetCloudMetadataResponse) cloud.Metadata

MetadataFromProto converts a proto GetCloudMetadataResponse to Metadata.

func MetadataToProto added in v0.56.0

func MetadataToProto(metadata cloud.Metadata) *robotpb.GetCloudMetadataResponse

MetadataToProto converts a Metadata its proto counterpart.

func ReadingGoToProto added in v0.0.8

func ReadingGoToProto(readings map[string]interface{}) (map[string]*structpb.Value, error)

ReadingGoToProto converts go readings to proto readings.

func ReadingProtoToGo added in v0.0.8

func ReadingProtoToGo(readings map[string]*structpb.Value) (map[string]interface{}, error)

ReadingProtoToGo converts proto readings to go readings.

func ResourceNameFromProto

func ResourceNameFromProto(name *commonpb.ResourceName) resource.Name

ResourceNameFromProto converts a proto ResourceName to its rdk counterpart.

func ResourceNameToProto

func ResourceNameToProto(name resource.Name) *commonpb.ResourceName

ResourceNameToProto converts a resource.Name to its proto counterpart.

Types

type ClientDoCommander added in v0.2.20

type ClientDoCommander interface {
	// DoCommand sends/receives arbitrary commands
	DoCommand(ctx context.Context, in *commonpb.DoCommandRequest,
		opts ...grpc.CallOption) (*commonpb.DoCommandResponse, error)
}

ClientDoCommander is a gRPC client that allows the execution of DoCommand.

type DelimitedProtoReader added in v0.105.0

type DelimitedProtoReader[T any, M interface {
	*T
	proto.Message
}] struct {
	RawDelimitedProtoReader
}

DelimitedProtoReader iterates over proto messages from an io.Reader with contents created by DelimitedProtoWriter. It automatically unmarshals the messages at each step of the iteration. To iterate over the raw bytes use RawDelimitedProtoReader.

func NewDelimitedProtoReader added in v0.105.0

func NewDelimitedProtoReader[T any, M interface {
	*T
	proto.Message
}](reader io.Reader) *DelimitedProtoReader[T, M]

NewDelimitedProtoReader creates a DelimitedProtoReader.

func (*DelimitedProtoReader[T, M]) All added in v0.105.0

func (o *DelimitedProtoReader[T, M]) All() iter.Seq[M]

All returns an iter.Seq that opens the underlying file and iterates over the individual messages while automatically unmarshaling them to T. Each iteration will incur an allocation so the returned *T can be owned by the caller. If you only need the value inside the iteration, you can use [TODO] to reuse memory across iterations.

func (*DelimitedProtoReader[T, M]) AllWithMemory added in v0.105.0

func (o *DelimitedProtoReader[T, M]) AllWithMemory(message M) iter.Seq[M]

AllWithMemory returns an iter.Seq that opens the underlying file and iterates over the individual messages while automatically unmarshalling them into message, which must be a non-nil pointer. Use this instead of DelimitedProtoReader.All to reduce allocations when you only need the message within the loop.

type DelimitedProtoWriter added in v0.105.0

type DelimitedProtoWriter[M proto.Message] struct {
	// contains filtered or unexported fields
}

DelimitedProtoWriter writes proto messages to an io.Writer. Each message is prefixed by its size in bytes so individual messages can later be retrieved. See also: DelimitedProtoReader.

func NewDelimitedProtoWriter added in v0.105.0

func NewDelimitedProtoWriter[M proto.Message](writer io.Writer) *DelimitedProtoWriter[M]

NewDelimitedProtoWriter creates a DelimitedProtoWriter.

func (*DelimitedProtoWriter[M]) Append added in v0.105.0

func (o *DelimitedProtoWriter[M]) Append(message M) error

Append marshals the provided message and writes it to the underlying io.Writer.

func (*DelimitedProtoWriter[_]) Close added in v0.105.0

func (o *DelimitedProtoWriter[_]) Close() error

Close will close the underlying writer if it is a io.Closer. Otherwise it is a noop.

type RawDelimitedProtoReader added in v0.105.0

type RawDelimitedProtoReader struct {
	// contains filtered or unexported fields
}

RawDelimitedProtoReader reads proto messages from an io.Reader containing contents created by DelimitedProtoWriter and returns the encoded messages as byte slices. To automatically unmarshal the messages during the iteration use a DelimitedProtoReader.

func NewRawDelimitedProtoReader added in v0.105.0

func NewRawDelimitedProtoReader(reader io.Reader) *RawDelimitedProtoReader

NewRawDelimitedProtoReader creates a RawDelimitedProtoReader.

func (*RawDelimitedProtoReader) All added in v0.105.0

func (o *RawDelimitedProtoReader) All() iter.Seq[[]byte]

All returns an iter.Seq that reads from the underlying io.Reader and iterates over the individual messages inside. The []byte yielded may be overwritten on subsequent iterations. If you need to use the yieded []byte outside an iteration you must copy it somewhere else.

func (*RawDelimitedProtoReader) Close added in v0.105.0

func (o *RawDelimitedProtoReader) Close() error

Close will close the underlying reader if it is a io.Closer. Otherwise it is a noop.

Jump to

Keyboard shortcuts

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