Skip to main content

Component

Type Alias Component 

Source
pub type Component = IndexMap<String, Box<dyn Message>>;
Expand description

A component is key value ordered

Aliased Type§

pub struct Component { /* private fields */ }

Trait Implementations§

Source§

impl Message for Component

Source§

fn write(&self, writer: &mut dyn Write) -> RdpResult<()>

Write a component message Useful to better reading structure and have some dynamic option

§Example
    let mut s = Cursor::new(vec![]);
    let mut x = component![
        "field1" => 3 as u8,
        "field2" => U32::LE(6)
    ];
    x.write(&mut s);
    assert_eq!(s.into_inner(), [3, 6, 0, 0, 0])
Source§

fn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>

Read a component base pattern from a valid stream

§Example
    let mut s = Cursor::new(vec![3, 6, 0, 0, 0]);
    let mut x = component![
        "field1" => 0 as u8,
        "field2" => U32::LE(0)
    ];
    x.read(&mut s);
    assert_eq!(cast!(DataType::U32, x["field2"]).unwrap(), 6)
Source§

fn length(&self) -> u64

Compute the length in byte of the component

§Example
    let mut s = Cursor::new(vec![3, 6, 0, 0, 0]);
    let mut x = component![
        "field1" => 0 as u8,
        "field2" => U32::LE(0)
    ];
    x.read(&mut s);
    assert_eq!(x.length(), 5)
Source§

fn visit(&self) -> DataType<'_>

Cast a dyn Message into component

§Example
    let mut s = Cursor::new(vec![8, 3, 0, 0, 0, 0]);
    let mut x = trame![
        component![
            "field1" => 0 as u8,
            "field2" => U32::LE(0)
        ],
        0 as u8
    ];
    x.read(&mut s);
    let y = cast!(DataType::Component, x[0]).unwrap();
    assert_eq!(cast!(DataType::U32, y["field2"]).unwrap(), 3)
Source§

fn options(&self) -> MessageOption

A component have no option by default