Skip to main content

ChannelLayer

Trait ChannelLayer 

Source
pub trait ChannelLayer {
    // Required methods
    fn bridge_send(&mut self, channel: u8, msg: &[u8]) -> bool;
    fn bridge_recv(&mut self, channel: u8) -> Option<Vec<u8>>;
    fn is_live(&self) -> bool;
}
Expand description

Simulation ↔ live channel bridging.

Implements L4 Channel → plato-sim-bridge.

§Examples

use plato_ship_protocol::ChannelLayer;

struct MockChannel { live: bool }

impl ChannelLayer for MockChannel {
    fn bridge_send(&mut self, _channel: u8, _msg: &[u8]) -> bool { self.live }
    fn bridge_recv(&mut self, _channel: u8) -> Option<Vec<u8>> {
        if self.live { Some(b"ack".to_vec()) } else { None }
    }
    fn is_live(&self) -> bool { self.live }
}

let mut ch = MockChannel { live: true };
assert!(ch.is_live());
assert!(ch.bridge_send(0, b"ping"));
assert_eq!(ch.bridge_recv(0), Some(b"ack".to_vec()));

Required Methods§

Source

fn bridge_send(&mut self, channel: u8, msg: &[u8]) -> bool

Send a message on the given channel id. Returns true if delivered.

Source

fn bridge_recv(&mut self, channel: u8) -> Option<Vec<u8>>

Receive a message from the given channel. Returns None if nothing waiting.

Source

fn is_live(&self) -> bool

Whether this channel is operating in live (vs. simulation) mode.

Implementors§