Struct tokio_dbus::MessageBuf
source · pub struct MessageBuf { /* private fields */ }
Expand description
An owned D-Bus message.
This is the owned variant of a Message
, to convert to a Message
, use
MessageBuf::borrow
.
Implementations§
source§impl MessageBuf
impl MessageBuf
sourcepub fn method_call(
path: Box<ObjectPath>,
member: Box<str>,
serial: NonZeroU32
) -> Self
pub fn method_call( path: Box<ObjectPath>, member: Box<str>, serial: NonZeroU32 ) -> Self
Construct a method call.
§Examples
use tokio_dbus::{Message, ObjectPath, MessageBuf, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = Message::method_call(PATH, "Hello", send.next_serial()).to_owned();
let m2 = MessageBuf::method_call(PATH.into(), "Hello".into(), m.serial());
assert_eq!(m, m2);
sourcepub fn method_return(self, serial: NonZeroU32) -> Self
pub fn method_return(self, serial: NonZeroU32) -> Self
Convert this message into a MessageKind::MethodReturn
message with
an empty body where the reply serial matches that of the current
message.
The send
argument is used to populate the next serial number.
§Examples
use tokio_dbus::{Message, MessageKind, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello")
.with_sender("se.tedro.DBusExample")
.with_destination("org.freedesktop.DBus")
.to_owned();
let m2 = m.clone().method_return(send.next_serial());
assert!(matches!(m2.kind(), MessageKind::MethodReturn { .. }));
assert_eq!(m.sender(), m2.destination());
assert_eq!(m.destination(), m2.sender());
sourcepub fn signal(member: Box<str>, serial: NonZeroU32) -> Self
pub fn signal(member: Box<str>, serial: NonZeroU32) -> Self
Construct a signal MessageBuf
.
§Examples
use tokio_dbus::{MessageBuf, SendBuf};
let mut send = SendBuf::new();
let m = send.signal("Hello").to_owned();
let m2 = MessageBuf::signal("Hello".into(), m.serial());
assert_eq!(m, m2);
sourcepub fn error(self, error_name: Box<str>, serial: NonZeroU32) -> Self
pub fn error(self, error_name: Box<str>, serial: NonZeroU32) -> Self
Convert this message into a MessageKind::Error
message with
an empty body where the reply serial matches that of the current
message.
§Examples
use tokio_dbus::{Message, MessageKind, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello")
.with_sender("se.tedro.DBusExample")
.with_destination("org.freedesktop.DBus");
let m2 = m.clone().error("org.freedesktop.DBus.UnknownMethod", send.next_serial());
assert!(matches!(m2.kind(), MessageKind::Error { .. }));
assert_eq!(m.sender(), m2.destination());
assert_eq!(m.destination(), m2.sender());
sourcepub fn kind(&self) -> MessageKind<'_>
pub fn kind(&self) -> MessageKind<'_>
Get the kind of the message.
§Examples
use tokio_dbus::{Message, MessageKind, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello");
assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
let m2 = m.error("org.freedesktop.DBus.UnknownMethod", send.next_serial());
assert!(matches!(m2.kind(), MessageKind::Error { .. }));
sourcepub fn with_body(self, body: BodyBuf) -> Self
pub fn with_body(self, body: BodyBuf) -> Self
Modify the body and signature of the message to match that of the provided body buffer.
§Examples
use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf, Signature};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let mut body = BodyBuf::new();
body.store("Hello World!");
let m = send.method_call(PATH, "Hello")
.to_owned()
.with_body(body);
assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), Signature::STRING);
sourcepub fn body(&self) -> Body<'_>
pub fn body(&self) -> Body<'_>
Get a buffer to the body of the message.
§Examples
use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let mut body = BodyBuf::new();
body.store(42u32);
body.store("Hello World!");
let m = send.method_call(PATH, "Hello")
.to_owned()
.with_body(body);
assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), "us");
let mut r = m.body();
assert_eq!(r.load::<u32>()?, 42);
assert_eq!(r.read::<str>()?, "Hello World!");
sourcepub fn serial(&self) -> NonZeroU32
pub fn serial(&self) -> NonZeroU32
Get the serial of the message.
§Examples
use std::num::NonZeroU32;
use tokio_dbus::{Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello");
assert_eq!(m.serial().get(), 1);
let m2 = m.with_serial(NonZeroU32::new(1000).unwrap());
assert_eq!(m2.serial().get(), 1000);
sourcepub fn with_serial(self, serial: NonZeroU32) -> Self
pub fn with_serial(self, serial: NonZeroU32) -> Self
Modify the serial of the message.
§Examples
use std::num::NonZeroU32;
use tokio_dbus::{Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello");
assert_eq!(m.serial().get(), 1);
let m2 = m.with_serial(NonZeroU32::new(1000).unwrap());
assert_eq!(m2.serial().get(), 1000);
sourcepub fn flags(&self) -> Flags
pub fn flags(&self) -> Flags
Get the flags of the message.
§Examples
use tokio_dbus::{Flags, Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello");
assert_eq!(m.flags(), Flags::default());
let m2 = m.with_flags(Flags::NO_REPLY_EXPECTED);
assert_eq!(m2.flags(), Flags::NO_REPLY_EXPECTED);
sourcepub fn with_flags(self, flags: Flags) -> Self
pub fn with_flags(self, flags: Flags) -> Self
Modify the flags of the message.
§Examples
use tokio_dbus::{Flags, Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello");
assert_eq!(m.flags(), Flags::default());
let m2 = m.with_flags(Flags::NO_REPLY_EXPECTED);
assert_eq!(m2.flags(), Flags::NO_REPLY_EXPECTED);
sourcepub fn interface(&self) -> Option<&str>
pub fn interface(&self) -> Option<&str>
Get the interface of the message.
§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.interface(), None);
let m2 = m.with_interface("org.freedesktop.DBus".into());
assert_eq!(m2.interface(), Some("org.freedesktop.DBus"));
sourcepub fn with_interface(self, interface: Box<str>) -> Self
pub fn with_interface(self, interface: Box<str>) -> Self
Modify the interface of the message.
§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.interface(), None);
let m2 = m.with_interface("org.freedesktop.DBus".into());
assert_eq!(m2.interface(), Some("org.freedesktop.DBus"));
sourcepub fn destination(&self) -> Option<&str>
pub fn destination(&self) -> Option<&str>
Get the destination of the message.
§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.destination(), None);
let m2 = m.with_destination(":1.131".into());
assert_eq!(m2.destination(), Some(":1.131"));
sourcepub fn with_destination(self, destination: Box<str>) -> Self
pub fn with_destination(self, destination: Box<str>) -> Self
Modify the destination of the message.
§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.destination(), None);
let m2 = m.with_destination(":1.131".into());
assert_eq!(m2.destination(), Some(":1.131"));
sourcepub fn sender(&self) -> Option<&str>
pub fn sender(&self) -> Option<&str>
Get the sender of the message.
§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.destination(), None);
let m2 = m.with_sender(":1.131".into());
assert_eq!(m2.sender(), Some(":1.131"));
sourcepub fn with_sender(self, sender: Box<str>) -> Self
pub fn with_sender(self, sender: Box<str>) -> Self
Modify the sender of the message.
§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.destination(), None);
let m2 = m.with_sender(":1.131".into());
assert_eq!(m2.sender(), Some(":1.131"));
sourcepub fn signature(&self) -> &Signature
pub fn signature(&self) -> &Signature
Get the signature of the message.
§Examples
use tokio_dbus::{BodyBuf, ObjectPath, SendBuf, Signature};
const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");
let mut send = SendBuf::new();
let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.signature(), Signature::EMPTY);
let mut body = BodyBuf::new();
body.store("Hello World!");
let m2 = m.with_body(body);
assert_eq!(m2.signature(), Signature::STRING);
Trait Implementations§
source§impl Clone for MessageBuf
impl Clone for MessageBuf
source§fn clone(&self) -> MessageBuf
fn clone(&self) -> MessageBuf
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MessageBuf
impl Debug for MessageBuf
source§impl PartialEq<Message<'_>> for MessageBuf
impl PartialEq<Message<'_>> for MessageBuf
source§impl PartialEq<MessageBuf> for Message<'_>
impl PartialEq<MessageBuf> for Message<'_>
source§fn eq(&self, other: &MessageBuf) -> bool
fn eq(&self, other: &MessageBuf) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq for MessageBuf
impl PartialEq for MessageBuf
source§fn eq(&self, other: &MessageBuf) -> bool
fn eq(&self, other: &MessageBuf) -> bool
self
and other
values to be equal, and is used
by ==
.