Documentation
¶
Overview ¶
Package protoutils are a collection of util methods for using proto in rdk
Index ¶
- func ConvertMapToProtoAny(input map[string]interface{}) (map[string]*anypb.Any, error)
- func ConvertOrientationToProto(o spatialmath.Orientation) *commonpb.Orientation
- func ConvertProtoToOrientation(o *commonpb.Orientation) spatialmath.Orientation
- func ConvertStringMapToAnyPBMap(params map[string]string) (map[string]*anypb.Any, error)
- func ConvertStringToAnyPB(str string) (*anypb.Any, error)
- func ConvertVectorProtoToR3(v *commonpb.Vector3) r3.Vector
- func ConvertVectorR3ToProto(v r3.Vector) *commonpb.Vector3
- func DoFromResourceClient(ctx context.Context, svc ClientDoCommander, name string, ...) (map[string]interface{}, error)
- func DoFromResourceServer(ctx context.Context, res resource.Resource, req *commonpb.DoCommandRequest) (*commonpb.DoCommandResponse, error)
- func MessageToProtoV1(msg interface{}) protov1.Message
- func MetadataFromProto(pbMetadata *robotpb.GetCloudMetadataResponse) cloud.Metadata
- func MetadataToProto(metadata cloud.Metadata) *robotpb.GetCloudMetadataResponse
- func ReadingGoToProto(readings map[string]interface{}) (map[string]*structpb.Value, error)
- func ReadingProtoToGo(readings map[string]*structpb.Value) (map[string]interface{}, error)
- func ResourceNameFromProto(name *commonpb.ResourceName) resource.Name
- func ResourceNameToProto(name resource.Name) *commonpb.ResourceName
- type ClientDoCommander
- type DelimitedProtoReader
- type DelimitedProtoWriter
- type RawDelimitedProtoReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertMapToProtoAny ¶ added in v0.52.0
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
ConvertStringMapToAnyPBMap takes a string map and parses each value to an Any proto type.
func ConvertStringToAnyPB ¶ added in v0.1.0
ConvertStringToAnyPB takes a string and parses it to an Any pb type.
func ConvertVectorProtoToR3 ¶ added in v0.0.6
ConvertVectorProtoToR3 TODO.
func ConvertVectorR3ToProto ¶ added in v0.0.6
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
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
ReadingGoToProto converts go readings to proto readings.
func ReadingProtoToGo ¶ added in v0.0.8
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
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.