#[repr(C)]pub struct UMessage { /* private fields */ }Expand description
One uProtocol message: attributes plus optional payload bytes.
Implementations§
Source§impl UMessage
impl UMessage
Sourcepub fn extract_protobuf<T: ProtobufMappable>(&self) -> Result<T, UMessageError>
pub fn extract_protobuf<T: ProtobufMappable>(&self) -> Result<T, UMessageError>
Deserializes this message’s protobuf payload into a type.
§Type Parameters
T: The target type of the data to be unpacked.
§Errors
Returns an error if the message payload format is neither UPayloadFormat::Protobuf nor UPayloadFormat::ProtobufWrappedInAny or if the bytes in the payload cannot be deserialized into the target type.
Source§impl UMessage
impl UMessage
Sourcepub fn with_assumed_payload_encoding(self, encoding: &PayloadEncoding) -> Self
pub fn with_assumed_payload_encoding(self, encoding: &PayloadEncoding) -> Self
Returns this message with an assumed payload encoding stamped on its attributes when the message has payload bytes and no encoding declaration yet.
This is for transports whose wire profile fixes payload encoding by topic convention rather than carrying it per message. Existing encoding declarations are preserved unchanged.
Sourcepub fn attributes(&self) -> &UAttributes
pub fn attributes(&self) -> &UAttributes
Get this message’s attributes.
This function simply delegates to UAttributes::type_.
§Example
use up_rust::{UMessageBuilder, UMessageType, UUri};
let topic = UUri::try_from("//my-vehicle/D45/23/A001")?;
let msg = UMessageBuilder::publish(topic).build()?;
assert_eq!(msg.type_(), UMessageType::Publish);Sourcepub fn type_(&self) -> UMessageType
pub fn type_(&self) -> UMessageType
Gets this message’s type.
Sourcepub fn id(&self) -> &UUID
pub fn id(&self) -> &UUID
Gets this message’s identifier.
This function simply delegates to UAttributes::id.
§Example
use up_rust::{UMessageBuilder, UMessageType, UUri, UUID};
let topic = UUri::try_from("//my-vehicle/D45/23/A001")?;
let msg_id = UUID::build();
let msg = UMessageBuilder::publish(topic).with_message_id(msg_id.clone()).build()?;
assert_eq!(msg.id(), &msg_id);Sourcepub fn source(&self) -> &UUri
pub fn source(&self) -> &UUri
Gets this message’s source address.
This function simply delegates to UAttributes::source.
§Example
use up_rust::{UMessageBuilder, UMessageType, UUri};
let topic = UUri::try_from("//my-vehicle/D45/23/A001")?;
let msg = UMessageBuilder::publish(topic.clone()).build()?;
assert_eq!(msg.source(), &topic);Sourcepub fn sink(&self) -> Option<&UUri>
pub fn sink(&self) -> Option<&UUri>
Gets this message’s sink address.
This function simply delegates to UAttributes::sink.
§Example
use up_rust::{UMessageBuilder, UMessageType, UUri};
let origin = UUri::try_from("//my-vehicle/D45/23/A001")?;
let dest = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::notification(origin, dest.clone()).build()?;
assert!(msg.sink().is_some_and(|sink| sink == &dest));Sourcepub fn sink_unchecked(&self) -> &UUri
pub fn sink_unchecked(&self) -> &UUri
Gets this message’s sink address.
This function simply delegates to UAttributes::sink_unchecked.
§Panics
if the property has no value.
§Example
use up_rust::{UMessageBuilder, UMessageType, UUri};
let origin = UUri::try_from("//my-vehicle/D45/23/A001")?;
let dest = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::notification(origin, dest.clone()).build()?;
assert_eq!(msg.sink_unchecked(), &dest);Sourcepub fn priority(&self) -> Option<UPriority>
pub fn priority(&self) -> Option<UPriority>
Gets this message’s priority.
This function simply delegates to UAttributes::priority.
§Example
use up_rust::{UMessageBuilder, UMessageType, UPriority, UUri};
let topic = UUri::try_from("//my-vehicle/D45/23/A001")?;
let msg = UMessageBuilder::publish(topic).with_priority(UPriority::CS3).build()?;
assert!(msg.priority().is_some_and(|prio| prio == UPriority::CS3));Sourcepub fn priority_unchecked(&self) -> UPriority
pub fn priority_unchecked(&self) -> UPriority
Gets this message’s priority.
This function simply delegates to UAttributes::priority_unchecked.
§Panics
if the property has no value.
§Example
use up_rust::{UMessageBuilder, UMessageType, UPriority, UUri};
let topic = UUri::try_from("//my-vehicle/D45/23/A001")?;
let msg = UMessageBuilder::publish(topic).with_priority(UPriority::CS3).build()?;
assert_eq!(msg.priority_unchecked(), UPriority::CS3);Sourcepub fn commstatus(&self) -> Option<UCode>
pub fn commstatus(&self) -> Option<UCode>
Gets this message’s commstatus.
This function simply delegates to UAttributes::commstatus.
§Example
use up_rust::{UCode, UMessageBuilder, UMessageType, UUID, UUri};
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::response(reply_to, UUID::build(), invoked_method)
.with_comm_status(UCode::Ok)
.build()?;
assert!(msg.commstatus().is_some_and(|status| status == UCode::Ok));Sourcepub fn commstatus_unchecked(&self) -> UCode
pub fn commstatus_unchecked(&self) -> UCode
Gets this message’s commstatus.
This function simply delegates to UAttributes::commstatus_unchecked.
§Panics
if the property has no value.
§Example
use up_rust::{UCode, UMessageBuilder, UMessageType, UUID, UUri};
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::response(reply_to, UUID::build(), invoked_method)
.with_comm_status(UCode::Internal)
.build()?;
assert_eq!(msg.commstatus_unchecked(), UCode::Internal);Sourcepub fn ttl(&self) -> Option<u32>
pub fn ttl(&self) -> Option<u32>
Gets this message’s time-to-live.
This function simply delegates to UAttributes::ttl.
§Returns
the time-to-live in milliseconds.
§Example
use up_rust::{UMessageBuilder, UUri};
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::request(invoked_method, reply_to, 5000)
.build()?;
assert!(msg.ttl().is_some_and(|ttl| ttl == 5000));Sourcepub fn ttl_unchecked(&self) -> u32
pub fn ttl_unchecked(&self) -> u32
Gets this message’s time-to-live.
This function simply delegates to UAttributes::ttl_unchecked.
§Returns
the time-to-live in milliseconds.
§Panics
if the property has no value.
§Example
use up_rust::{UMessageBuilder, UUri};
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::request(invoked_method, reply_to, 5000)
.build()?;
assert!(msg.ttl_unchecked() == 5000);Sourcepub fn permission_level(&self) -> Option<u32>
pub fn permission_level(&self) -> Option<u32>
Gets this message’s permission level.
This function simply delegates to UAttributes::permission_level.
§Example
use up_rust::{UMessageBuilder, UUri};
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::request(invoked_method, reply_to, 5000)
.with_permission_level(3)
.build()?;
assert!(msg.permission_level().is_some_and(|pl| pl == 3));Sourcepub fn token(&self) -> Option<&str>
pub fn token(&self) -> Option<&str>
Gets this message’s token.
This function simply delegates to UAttributes::token.
§Example
use up_rust::{UMessageBuilder, UUri};
let token = "my_token";
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::request(invoked_method, reply_to, 5000)
.with_token(token)
.build()?;
assert!(msg.token().is_some_and(|t| t == token));Sourcepub fn traceparent(&self) -> Option<&str>
pub fn traceparent(&self) -> Option<&str>
Gets this message’s traceparent.
This function simply delegates to UAttributes::traceparent.
§Example
use up_rust::{UMessageBuilder, UUri};
let traceparent = "my_traceparent";
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::request(invoked_method, reply_to, 5000)
.with_traceparent(traceparent)
.build()?;
assert!(msg.traceparent().is_some_and(|tp| tp == traceparent));Sourcepub fn request_id(&self) -> Option<&UUID>
pub fn request_id(&self) -> Option<&UUID>
Gets this message’s request identifier.
This function simply delegates to UAttributes::request_id.
§Example
use up_rust::{UCode, UMessageBuilder, UUID, UUri};
let request_id = UUID::build();
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::response(reply_to, request_id.clone(), invoked_method)
.build()?;
assert!(msg.request_id().is_some_and(|id| id == &request_id));Sourcepub fn request_id_unchecked(&self) -> &UUID
pub fn request_id_unchecked(&self) -> &UUID
Gets this message’s request identifier.
This function simply delegates to UAttributes::request_id_unchecked.
§Panics
if the property has no value.
§Example
use up_rust::{UCode, UMessageBuilder, UUID, UUri};
let request_id = UUID::build();
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::response(reply_to, request_id.clone(), invoked_method)
.build()?;
assert_eq!(msg.request_id_unchecked(), &request_id);Sourcepub fn payload_format(&self) -> Option<UPayloadFormat>
pub fn payload_format(&self) -> Option<UPayloadFormat>
Gets this message’s payload format.
This function simply delegates to UAttributes::payload_format.
§Example
use up_rust::{UMessageBuilder, UPayloadFormat, UUri};
let topic = UUri::try_from("//my-vehicle/D45/23/A001")?;
let msg = UMessageBuilder::publish(topic)
.build_with_payload("hello".as_bytes(), UPayloadFormat::Text)?;
assert!(msg.payload_format().is_some_and(|format| format == UPayloadFormat::Text));Sourcepub fn payload_format_unchecked(&self) -> UPayloadFormat
pub fn payload_format_unchecked(&self) -> UPayloadFormat
Gets this message’s payload format.
This function simply delegates to UAttributes::payload_format_unchecked.
§Panics
if the property has no value.
§Example
use up_rust::{UMessageBuilder, UPayloadFormat, UUri};
let topic = UUri::try_from("//my-vehicle/D45/23/A001")?;
let msg = UMessageBuilder::publish(topic)
.build_with_payload("hello".as_bytes(), UPayloadFormat::Text)?;
assert_eq!(msg.payload_format_unchecked(), UPayloadFormat::Text);Sourcepub fn is_publish(&self) -> bool
pub fn is_publish(&self) -> bool
Checks if this is a Publish message.
This function simply delegates to UAttributes::is_publish.
§Examples
use up_rust::{UMessageBuilder, UUri};
let topic = UUri::try_from("//my-vehicle/D45/23/A001")?;
let msg = UMessageBuilder::publish(topic).build()?;
assert!(msg.is_publish());Sourcepub fn is_request(&self) -> bool
pub fn is_request(&self) -> bool
Checks if this is an RPC Request message.
This function simply delegates to UAttributes::is_request.
§Examples
use up_rust::{UMessageBuilder, UUri};
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::request(invoked_method, reply_to, 5000)
.build()?;
assert!(msg.is_request());Sourcepub fn is_response(&self) -> bool
pub fn is_response(&self) -> bool
Checks if this is an RPC Response message.
This function simply delegates to UAttributes::is_response.
§Examples
use up_rust::{UCode, UMessageBuilder, UUID, UUri};
let invoked_method = UUri::try_from("//my-vehicle/D45/2/101")?;
let reply_to = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::response(reply_to, UUID::build(), invoked_method)
.build()?;
assert!(msg.is_response());Sourcepub fn is_notification(&self) -> bool
pub fn is_notification(&self) -> bool
Checks if this is a Notification message.
This function simply delegates to UAttributes::is_notification.
§Examples
use up_rust::{UMessageBuilder, UUri};
let origin = UUri::try_from("//my-vehicle/D45/23/A001")?;
let dest = UUri::try_from("//other-vehicle/D10/3/0")?;
let msg = UMessageBuilder::notification(origin, dest).build()?;
assert!(msg.is_notification());Sourcepub fn check_expired(&self) -> Result<(), UAttributesError>
pub fn check_expired(&self) -> Result<(), UAttributesError>
Checks if this message should be considered expired.
This function simply delegates to UAttributes::check_expired.
Sourcepub fn check_expired_for_reference(
&self,
reference_time: u128,
) -> Result<(), UAttributesError>
pub fn check_expired_for_reference( &self, reference_time: u128, ) -> Result<(), UAttributesError>
Checks if this message should be considered expired for a given reference time.
This function simply delegates to UAttributes::check_expired_for_reference.
§Arguments
reference_time- The reference time as milliseconds since UNIX epoch. The check will be performed in relation to this point in time.
Source§impl UMessage
impl UMessage
Sourcepub fn to_frame_metadata(
&self,
payload_encoding: PayloadEncoding,
) -> Result<UFrameMetadata, UFrameMetadataError>
pub fn to_frame_metadata( &self, payload_encoding: PayloadEncoding, ) -> Result<UFrameMetadata, UFrameMetadataError>
Projects this message to frame metadata carrying the given payload encoding.
§Errors
Returns an error if the message attributes and encoding disagree or the resulting metadata is invalid.
Sourcepub fn to_frame_metadata_unencoded(
&self,
) -> Result<UFrameMetadata, UFrameMetadataError>
pub fn to_frame_metadata_unencoded( &self, ) -> Result<UFrameMetadata, UFrameMetadataError>
Projects this message to frame metadata for a payload-free message.
§Errors
Returns an error if the message carries payload information or the resulting metadata is invalid.