Preview of the proposed up-rust native-frame-model branch (up-rust b6b99c6d, up-spec f0e9b17) — not released documentation. branch · write-up

Struct UMessage

Source
#[repr(C)]
pub struct UMessage { /* private fields */ }
Expand description

One uProtocol message: attributes plus optional payload bytes.

Implementations§

Source§

impl UMessage

Source

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

Source

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.

Source

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);
Source

pub fn type_(&self) -> UMessageType

Gets this message’s type.

Source

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);
Source

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);
Source

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));
Source

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);
Source

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));
Source

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);
Source

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));
Source

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);
Source

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));
Source

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);
Source

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));
Source

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));
Source

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));
Source

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));
Source

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);
Source

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));
Source

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);
Source

pub fn payload(&self) -> Option<Bytes>

Returns the payload bytes, if the message carries any.

Source

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());
Source

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());
Source

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());
Source

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());
Source

pub fn check_expired(&self) -> Result<(), UAttributesError>

Checks if this message should be considered expired.

This function simply delegates to UAttributes::check_expired.

Source

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

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for UMessage

Source§

fn clone(&self) -> UMessage

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for UMessage

Source§

fn eq(&self, other: &UMessage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ProtobufMappable for UMessage

Source§

fn parse_from_protobuf_bytes(proto: &[u8]) -> Result<Self, SerializationError>

Parses an instance of this type from the given protobuf bytes. Read more
Source§

fn parse_from_packed_protobuf_bytes( proto: &[u8], ) -> Result<Self, SerializationError>

Parses an instance of this type from the given packed protobuf bytes. Read more
Source§

fn write_to_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>

Serializes this instance to protobuf bytes. Read more
Source§

fn write_to_packed_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>

Serializes this instance to packed protobuf bytes. Read more
Source§

impl TryFrom<CloudEvent> for UMessage

Source§

type Error = UMessageError

The type returned in the event of a conversion error.
Source§

fn try_from(event: CloudEvent) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<UMessage> for CloudEvent

Source§

type Error = UMessageError

The type returned in the event of a conversion error.
Source§

fn try_from(message: UMessage) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for UMessage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<TCore> UWithNativePrefixWire for TCore

Source§

fn into_native_prefix_wire_transport<W>( self, wire: W, ) -> UWireTransport<TCore, W, NativePrefixFrameMetadataCodec>
where W: UWire,

Wraps this core with an external or custom selected wire using canonical metadata.
Source§

fn into_protobuf_transport( self, ) -> UWireTransport<TCore, ProtobufWire, NativePrefixFrameMetadataCodec>

Wraps this core with the Protocol Buffers selected-wire profile.
Source§

fn into_stable_container_transport( self, ) -> UWireTransport<TCore, StableContainerWireFormat, NativePrefixFrameMetadataCodec>

Wraps this core with the stable-container selected-wire profile.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more