Struct zbus::message::Message

source ·
pub struct Message { /* private fields */ }
Expand description

A D-Bus Message.

The content of the message are stored in serialized format. To get the body of the message, use the Message::body method, and use Body methods to deserialize it. You may also access the header and other details with the various other getters.

Also provided are constructors for messages of different types. These will mainly be useful for very advanced use cases as typically you will want to create a message for immediate dispatch and hence use the API provided by Connection, even when using the low-level API.

Note: The message owns the received FDs and will close them when dropped. You can deserialize to zvariant::OwnedFd the body (that you get using Message::body) if you want to keep the FDs around after the containing message is dropped.

Implementations§

source§

impl Message

source

pub fn method<'b, 'p: 'b, 'm: 'b, P, M>( path: P, method_name: M ) -> Result<Builder<'b>>
where P: TryInto<ObjectPath<'p>>, M: TryInto<MemberName<'m>>, P::Error: Into<Error>, M::Error: Into<Error>,

Create a builder for message of type Type::MethodCall.

source

pub fn signal<'b, 'p: 'b, 'i: 'b, 'm: 'b, P, I, M>( path: P, iface: I, signal_name: M ) -> Result<Builder<'b>>
where P: TryInto<ObjectPath<'p>>, I: TryInto<InterfaceName<'i>>, M: TryInto<MemberName<'m>>, P::Error: Into<Error>, I::Error: Into<Error>, M::Error: Into<Error>,

Create a builder for message of type Type::Signal.

source

pub fn method_reply(call: &Self) -> Result<Builder<'_>>

Create a builder for message of type Type::MethodReturn.

source

pub fn method_error<'b, 'e: 'b, E>(call: &Self, name: E) -> Result<Builder<'b>>
where E: TryInto<ErrorName<'e>>, E::Error: Into<Error>,

Create a builder for message of type Type::Error.

source

pub unsafe fn from_bytes(bytes: Data<'static, 'static>) -> Result<Self>

Create a message from bytes.

Note: Since the constructed message is not construct by zbus, the receive sequence, which can be acquired from Message::recv_position, is not applicable and hence set to 0.

§Safety

This method is unsafe as bytes may have an invalid encoding.

source

pub fn primary_header(&self) -> &PrimaryHeader

source

pub fn header(&self) -> Header<'_>

The message header.

Note: This method does not deserialize the header but it does currently allocate so its not zero-cost. While the allocation is small and will hopefully be removed in the future, it’s best to keep the header around if you need to access it a lot.

source

pub fn message_type(&self) -> Type

The message type.

source

pub fn path(&self) -> Option<ObjectPath<'_>>

👎Deprecated since 4.0.0: Use Message::header with message::Header::path instead

The object to send a call to, or the object a signal is emitted from.

source

pub fn interface(&self) -> Option<InterfaceName<'_>>

👎Deprecated since 4.0.0: Use Message::header with message::Header::interface instead

The interface to invoke a method call on, or that a signal is emitted from.

source

pub fn member(&self) -> Option<MemberName<'_>>

👎Deprecated since 4.0.0: Use Message::header with message::Header::member instead

The member, either the method name or signal name.

source

pub fn reply_serial(&self) -> Option<NonZeroU32>

👎Deprecated since 4.0.0: Use Message::header with message::Header::reply_serial instead

The serial number of the message this message is a reply to.

source

pub fn body(&self) -> Body

The body that you can deserialize using Body::deserialize.

§Example
let send_body = (7i32, (2i32, "foo"), vec!["bar"]);
let message = Message::method("/", "ping")?
    .destination("zbus.test")?
    .interface("zbus.test")?
    .build(&send_body)?;
let body = message.body();
let body: zbus::zvariant::Structure = body.deserialize()?;
let fields = body.fields();
assert!(matches!(fields[0], zvariant::Value::I32(7)));
assert!(matches!(fields[1], zvariant::Value::Structure(_)));
assert!(matches!(fields[2], zvariant::Value::Array(_)));

let reply_body = Message::method_reply(&message)?.build(&body)?.body();
let reply_value : (i32, (i32, &str), Vec<String>) = reply_body.deserialize()?;

assert_eq!(reply_value.0, 7);
assert_eq!(reply_value.2.len(), 1);
source

pub fn data(&self) -> &Data<'static, 'static>

Get a reference to the underlying byte encoding of the message.

source

pub fn recv_position(&self) -> Sequence

Get the receive ordering of a message.

This may be used to identify how two events were ordered on the bus. It only produces a useful ordering for messages that were produced by the same zbus::Connection.

This is completely unrelated to the serial number on the message, which is set by the peer and might not be ordered at all.

Trait Implementations§

source§

impl Clone for Message

source§

fn clone(&self) -> Message

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 Message

source§

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

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

impl Display for Message

source§

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

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

impl From<InterfacesAdded> for Message

source§

fn from(signal: InterfacesAdded) -> Self

Converts to this type from the input type.
source§

impl From<InterfacesAdded> for Message

source§

fn from(signal: InterfacesAdded) -> Self

Converts to this type from the input type.
source§

impl From<InterfacesRemoved> for Message

source§

fn from(signal: InterfacesRemoved) -> Self

Converts to this type from the input type.
source§

impl From<InterfacesRemoved> for Message

source§

fn from(signal: InterfacesRemoved) -> Self

Converts to this type from the input type.
source§

impl From<Message> for Error

source§

fn from(message: Message) -> Error

Converts to this type from the input type.
source§

impl From<NameAcquired> for Message

source§

fn from(signal: NameAcquired) -> Self

Converts to this type from the input type.
source§

impl From<NameAcquired> for Message

source§

fn from(signal: NameAcquired) -> Self

Converts to this type from the input type.
source§

impl From<NameLost> for Message

source§

fn from(signal: NameLost) -> Self

Converts to this type from the input type.
source§

impl From<NameLost> for Message

source§

fn from(signal: NameLost) -> Self

Converts to this type from the input type.
source§

impl From<NameOwnerChanged> for Message

source§

fn from(signal: NameOwnerChanged) -> Self

Converts to this type from the input type.
source§

impl From<NameOwnerChanged> for Message

source§

fn from(signal: NameOwnerChanged) -> Self

Converts to this type from the input type.
source§

impl From<PropertiesChanged> for Message

source§

fn from(signal: PropertiesChanged) -> Self

Converts to this type from the input type.
source§

impl From<PropertiesChanged> for Message

source§

fn from(signal: PropertiesChanged) -> Self

Converts to this type from the input type.

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
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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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