pub trait Message: Send {
// Required methods
fn write(&self, writer: &mut dyn Write) -> RdpResult<()>;
fn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>;
fn length(&self) -> u64;
fn visit(&self) -> DataType<'_>;
fn options(&self) -> MessageOption;
}Expand description
All is a message
A message can be Read or Write from a Stream
Required Methods§
Sourcefn write(&self, writer: &mut dyn Write) -> RdpResult<()>
fn write(&self, writer: &mut dyn Write) -> RdpResult<()>
Write node to the Stream
Write current element into a writable stream
Sourcefn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>
fn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>
Read node from stream
Read and set current variable from readable stream
Sourcefn visit(&self) -> DataType<'_>
fn visit(&self) -> DataType<'_>
Cast value on Message Tree
Visit value and try to return inner type This is based on Tree visitor pattern
Sourcefn options(&self) -> MessageOption
fn options(&self) -> MessageOption
Retrieve options of a subtype
Allow subtype to show some options That will impact current operation on parent like skipping some fields of a component
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Message for u8
u8 message
impl Message for u8
u8 message
Implement Message trait for basic type u8
Source§fn write(&self, writer: &mut dyn Write) -> RdpResult<()>
fn write(&self, writer: &mut dyn Write) -> RdpResult<()>
Write u8 value into stream
§Example
let mut s = Cursor::new(Vec::new());
let value : u8 = 8;
value.write(&mut s);
assert_eq!(*s.get_ref(), vec![8 as u8]);Source§fn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>
fn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>
Read u8 value from stream
§Example
let mut stream = Cursor::new(vec![8]);
let mut value = 0 as u8;
value.read(&mut stream); // set the value according to stream content
assert_eq!(value, 8);Source§fn visit(&self) -> DataType<'_>
fn visit(&self) -> DataType<'_>
Use visitor pattern to retrieve leaf value in case of node component
§Example
let x : u8 = 8;
if let DataType::U8(value) = x.visit() {
assert_eq!(value, 8)
}
else {
panic!("Invalid cast");
}Source§fn options(&self) -> MessageOption
fn options(&self) -> MessageOption
Retrieve option of a subnode
Allow a parent to retrieve some optional value That will influence the current node operation like skipping field of a component
This kind of node have no option
Source§impl<T: Message> Message for Option<T>
This is an optional fields
Actually always write but read if and only if the reader
buffer could read the size of inner Message
impl<T: Message> Message for Option<T>
This is an optional fields Actually always write but read if and only if the reader buffer could read the size of inner Message
Source§fn write(&self, writer: &mut dyn Write) -> RdpResult<()>
fn write(&self, writer: &mut dyn Write) -> RdpResult<()>
Write an optional message Actually always try to write
§Example
use std::io::Cursor;
use rdp::model::data::Message;
let mut s1 = Cursor::new(vec![]);
Some(4).write(&mut s1);
assert_eq!(s1.into_inner(), [4]);
let mut s2 = Cursor::new(vec![]);
Option::<u8>::None.write(&mut s2);
assert_eq!(s2.into_inner(), [])Source§fn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>
fn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>
Read an optional field Read the value if and only if there is enough space in the reader
§Example
#[macro_use]
let mut s1 = Cursor::new(vec![1, 0, 0, 0]);
let mut x = Some(U32::LE(0));
x.read(&mut s1);
assert_eq!(1, cast!(DataType::U32, x).unwrap());
let mut s2 = Cursor::new(vec![1, 0, 0]);
let mut y = Some(U32::LE(0));
y.read(&mut s2);
assert!(y == None);
let mut s3 = Cursor::new(vec![1, 0, 0]);
// case in component
let mut z = component![
"optional" => Some(U32::LE(0))
];
z.read(&mut s3);
assert!(is_none!(z["optional"]))Source§fn length(&self) -> u64
fn length(&self) -> u64
This compute the length of the optionaln field
§Example
use rdp::model::data::{U32, Message};
assert_eq!(Some(U32::LE(4)).length(), 4);
assert_eq!(Option::<U32>::None.length(), 0);Source§fn visit(&self) -> DataType<'_>
fn visit(&self) -> DataType<'_>
Visitor pattern for optional field
§Example
#[macro_use]
assert_eq!(4, cast!(DataType::U32, Some(U32::LE(4))).unwrap());
assert!(is_none!(Option::<U32>::None));fn options(&self) -> MessageOption
Implementors§
impl Message for Component
impl Message for Trame
Trame is a Message too
impl Message for U16
impl Message for U32
impl<T: 'static + Message> Message for Array<T>
Implement the message trait for Array
impl<T: Message + Clone + PartialEq> Message for Check<T>
impl<T: Message> Message for DynOption<T>
Dynamic option is a transparent object for the inner