leodos_protocols/network/mod.rs
1use core::future::Future;
2
3/// Bidirectional bridge between network and datalink layers.
4pub mod bridge;
5/// CCSDS core Flight Executive (cFE) command and telemetry headers.
6pub mod cfe;
7/// Inter-Satellite Link (ISL) addressing, routing, and gossip protocols.
8pub mod isl;
9/// A point-to-point network layer that forwards directly to the datalink.
10pub mod ptp;
11/// CCSDS Space Packet Protocol (SPP) — re-exported from
12/// [`datalink::spp`](crate::datalink::spp).
13pub use crate::datalink::spp;
14
15/// Send direction of the network layer.
16pub trait NetworkWrite {
17 /// Error type for write operations.
18 type Error: core::error::Error;
19
20 /// Writes a packet to the network.
21 fn write(&mut self, data: &[u8]) -> impl Future<Output = Result<(), Self::Error>>;
22}
23
24/// Receive direction of the network layer.
25pub trait NetworkRead {
26 /// Error type for read operations.
27 type Error: core::error::Error;
28
29 /// Reads a packet into the provided buffer, returning its length.
30 fn read(&mut self, buffer: &mut [u8]) -> impl Future<Output = Result<usize, Self::Error>>;
31}
32
33/// A bidirectional network layer that can be split into
34/// independent read and write halves.
35pub trait Network {
36 /// Read half type.
37 type Reader: NetworkRead;
38 /// Write half type.
39 type Writer: NetworkWrite;
40
41 /// Split into independent read and write halves.
42 fn split(&mut self) -> (&mut Self::Reader, &mut Self::Writer);
43}
44
45impl<R: NetworkRead, W: NetworkWrite> Network for (R, W) {
46 type Reader = R;
47 type Writer = W;
48
49 fn split(&mut self) -> (&mut R, &mut W) {
50 (&mut self.0, &mut self.1)
51 }
52}