pub struct Message { /* private fields */ }
Expand description
A D-Bus Message.
The contents 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 the body (that you get using Message::body
) to zvariant::OwnedFd
if you want
to keep the FDs around after the containing message is dropped.
Implementations§
Source§impl Message
impl Message
Sourcepub fn method_call<'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>,
pub fn method_call<'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 a message of type Type::MethodCall
.
Sourcepub 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>,
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 a message of type Type::Signal
.
Sourcepub fn method_return(reply_to: &Header<'_>) -> Result<Builder<'static>>
pub fn method_return(reply_to: &Header<'_>) -> Result<Builder<'static>>
Create a builder for a message of type Type::MethodReturn
.
Sourcepub fn error<'b, 'e: 'b, E>(
reply_to: &Header<'_>,
name: E,
) -> Result<Builder<'b>>
pub fn error<'b, 'e: 'b, E>( reply_to: &Header<'_>, name: E, ) -> Result<Builder<'b>>
Create a builder for a message of type Type::Error
.
Sourcepub unsafe fn from_bytes(bytes: Data<'static, 'static>) -> Result<Self>
pub unsafe fn from_bytes(bytes: Data<'static, 'static>) -> Result<Self>
Create a message from bytes.
Note: Since the message is not constructed 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.
pub fn primary_header(&self) -> &PrimaryHeader
Sourcepub fn message_type(&self) -> Type
pub fn message_type(&self) -> Type
The message type.
Sourcepub fn body(&self) -> Body
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_call("/", "ping")?
.destination("zbus.test")?
.interface("zbus.test")?
.build(&send_body)?;
let header = message.header();
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_return(&header)?.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);
Sourcepub fn data(&self) -> &Data<'static, 'static>
pub fn data(&self) -> &Data<'static, 'static>
Get a reference to the underlying byte encoding of the message.
Sourcepub fn recv_position(&self) -> Sequence
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 From<InterfacesAdded> for Message
impl From<InterfacesAdded> for Message
Source§fn from(signal: InterfacesAdded) -> Self
fn from(signal: InterfacesAdded) -> Self
Source§impl From<InterfacesRemoved> for Message
impl From<InterfacesRemoved> for Message
Source§fn from(signal: InterfacesRemoved) -> Self
fn from(signal: InterfacesRemoved) -> Self
Source§impl From<NameAcquired> for Message
impl From<NameAcquired> for Message
Source§fn from(signal: NameAcquired) -> Self
fn from(signal: NameAcquired) -> Self
Source§impl From<NameOwnerChanged> for Message
impl From<NameOwnerChanged> for Message
Source§fn from(signal: NameOwnerChanged) -> Self
fn from(signal: NameOwnerChanged) -> Self
Source§impl From<PropertiesChanged> for Message
impl From<PropertiesChanged> for Message
Source§fn from(signal: PropertiesChanged) -> Self
fn from(signal: PropertiesChanged) -> Self
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)