pub struct Msg {
pub header: Header,
pub topic: String,
pub message: Vec<u8>,
pub channel: Option<Sender<Msg>>,
pub client_id: Option<String>,
}Expand description
structure containing the complete information about a message.
Fields§
§header: HeaderHeader: the header of the message.
topic: StringThe topic for the message.
message: Vec<u8>the actual message, bytes.
channel: Option<Sender<Msg>>tokio::broadcast::sync::Sender the channel for passing the messages across.
client_id: Option<String>client_id: to identify each socket connection/client.
Implementations§
Source§impl Msg
impl Msg
Sourcepub fn new(pkt_type: PktType, topic: String, message: Option<Vec<u8>>) -> Msg
pub fn new(pkt_type: PktType, topic: String, message: Option<Vec<u8>>) -> Msg
Creates a new Msg with the given data.
use simple_pub_sub_message::message::Msg;
use simple_pub_sub_message::PktType;
let msg = Msg::new(PktType::PUBLISH, "Test".to_string(), Some(b"The message".to_vec()));Sourcepub fn channel(&mut self, chan: Sender<Msg>)
pub fn channel(&mut self, chan: Sender<Msg>)
adds the given channel to the message.
use simple_pub_sub_message::message::Msg;
use simple_pub_sub_message::PktType;
use tokio::sync::broadcast::Sender;
let mut msg = Msg::new(PktType::PUBLISH, "Test".to_string(), Some(b"The message".to_vec()));
let chan: tokio::sync::broadcast::Sender<Msg> =
tokio::sync::broadcast::Sender::new(1);
msg.channel(chan)Sourcepub fn client_id(&mut self, client_id: String)
pub fn client_id(&mut self, client_id: String)
returns the client id for the message.
use simple_pub_sub_message::message::Msg;
use simple_pub_sub_message::PktType;
use uuid;
let mut msg = Msg::new(PktType::PUBLISH, "Test".to_string(), Some(b"The message".to_vec()));
let client_id = uuid::Uuid::new_v4().to_string();
msg.client_id(client_id)Sourcepub fn response_msg(&self, message: Vec<u8>) -> Result<Msg, Error>
pub fn response_msg(&self, message: Vec<u8>) -> Result<Msg, Error>
generates the response Msg with the given data.
use simple_pub_sub_message::message::Msg;
use simple_pub_sub_message::PktType;
let mut msg = Msg::new(PktType::PUBLISH, "Test".to_string(), Some(b"The message".to_vec()));
let response_msg = msg.response_msg(vec![]);Trait Implementations§
Source§impl TryFrom<&[u8]> for Msg
impl TryFrom<&[u8]> for Msg
Source§fn try_from(bytes: &[u8]) -> Result<Msg, Error>
fn try_from(bytes: &[u8]) -> Result<Msg, Error>
Parses a Msg from a Vec<u8>.
use simple_pub_sub_message::message::Msg;
let buf = [15, 0, 1, 2, 3, 0, 12, 0, 97, 98,
99, 116, 101, 115, 116, 32, 109, 101, 115,
115, 97, 103, 101];
let msg = Msg::try_from(buf.as_ref()).unwrap();
println!("{:?}", msg);Source§impl TryFrom<Vec<u8>> for Msg
impl TryFrom<Vec<u8>> for Msg
Auto Trait Implementations§
impl Freeze for Msg
impl !RefUnwindSafe for Msg
impl Send for Msg
impl Sync for Msg
impl Unpin for Msg
impl !UnwindSafe for Msg
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
Mutably borrows from an owned value. Read more