dbus_message_parser/
lib.rs

1//! A library to encode and decode [DBus message].
2//!
3//! # Example
4//! The following examples show how to create a [`METHOD_CALL`] message and a [`SIGNAL`] message.
5//! ```rust
6//! use bytes::{Bytes, BytesMut};
7//! use dbus_message_parser::message::Message;
8//! use dbus_message_parser::value::Value;
9//! use std::convert::TryInto;
10//!
11//! fn create_method_call() {
12//!     // Create a MessageCall
13//!     // Arguments:
14//!     // 1. destination
15//!     // 2. object path
16//!     // 3. interface
17//!     // 4. method
18//!     let mut msg = Message::method_call(
19//!         "destination.address".try_into().unwrap(),
20//!         "/object/path".try_into().unwrap(),
21//!         "interface.name".try_into().unwrap(),
22//!         "MethodName".try_into().unwrap(),
23//!     );
24//!
25//!     // Add the first argument to the MessageCall
26//!     msg.add_value(Value::String("String Argument".to_string()));
27//!     // Add the second argument to the MessageCall
28//!     msg.add_value(Value::Uint32(0));
29//!
30//!     println!("{:?}", msg);
31//!
32//!     let bytes = msg.encode().unwrap();
33//!
34//!     println!("{:?}", bytes);
35//! }
36//!
37//! fn create_signal() {
38//!     // Create a Signal
39//!     // Arguments
40//!     // 1. object path
41//!     // 2. interface
42//!     // 3. Signal name
43//!     let mut signal = Message::signal(
44//!         "/object/path".try_into().unwrap(),
45//!         "interface.name".try_into().unwrap(),
46//!         "SignalName".try_into().unwrap(),
47//!     );
48//!
49//!     // Add the first argument to the MessageCall
50//!     signal.add_value(Value::Uint32(0));
51//!     // Add the second argument to the MessageCall
52//!     signal.add_value(Value::Double(1.0));
53//!
54//!     println!("{:?}", signal);
55//!
56//!     let bytes = signal.encode().unwrap();
57//!
58//!     println!("{:?}", bytes);
59//! }
60//!
61//! fn decode_method_call() {
62//!     // A message encoded as bytes
63//!     let bytes = Bytes::copy_from_slice(
64//!         &b"\x6c\x01\x00\x01\x0a\x00\x00\x00\xb1\x00\x00\x00\x9e\x00\x00\x00\x01\x01\x6f\x00\x15\x00\
65//!         \x00\x00\x2f\x6f\x72\x67\x2f\x66\x72\x65\x65\x64\x65\x73\x6b\x74\x6f\x70\x2f\x44\x42\x75\
66//!         \x73\x00\x00\x00\x02\x01\x73\x00\x14\x00\x00\x00\x6f\x72\x67\x2e\x66\x72\x65\x65\x64\x65\
67//!         \x73\x6b\x74\x6f\x70\x2e\x44\x42\x75\x73\x00\x00\x00\x00\x06\x01\x73\x00\x14\x00\x00\x00\
68//!         \x6f\x72\x67\x2e\x66\x72\x65\x65\x64\x65\x73\x6b\x74\x6f\x70\x2e\x44\x42\x75\x73\x00\x00\
69//!         \x00\x00\x08\x01\x67\x00\x01\x73\x00\x00\x03\x01\x73\x00\x1a\x00\x00\x00\x47\x65\x74\x43\
70//!         \x6f\x6e\x6e\x65\x63\x74\x69\x6f\x6e\x55\x6e\x69\x78\x50\x72\x6f\x63\x65\x73\x73\x49\x44\
71//!         \x00\x00\x00\x00\x00\x00\x07\x01\x73\x00\x05\x00\x00\x00\x3a\x31\x2e\x35\x30\x00\x00\x00\
72//!         \x05\x00\x00\x00\x3a\x31\x2e\x35\x35\x00"[..],
73//!     );
74//!     // Decode the message
75//!     let msg = Message::decode(bytes).unwrap();
76//!     println!("Message is decoded: {:?}", msg);
77//! }
78//! ```
79//!
80//! [DBus message]: https://dbus.freedesktop.org/doc/dbus-specification.html
81//! [`METHOD_CALL`]: crate::message::MessageType::MethodCall
82//! [`SIGNAL`]: crate::message::MessageType::Signal
83
84pub mod decode;
85pub mod encode;
86pub mod match_rule;
87pub mod message;
88pub mod value;