Skip to main content

leodos_protocols/coding/
mod.rs

1/// Forward error-correction codes (Reed-Solomon, LDPC, convolutional).
2pub mod fec;
3/// Frame synchronization and transmission unit encoding (CADU, CLTU).
4pub mod framing;
5/// Re-export from application layer for backward compatibility.
6pub use crate::application::compression;
7/// CCSDS pseudo-randomization for TC and TM frames.
8pub mod randomizer;
9/// CRC-protected Space Packet wrapper.
10pub mod crc;
11
12use core::convert::Infallible;
13use core::future::Future;
14
15/// Coding pipeline that composes randomizer, FEC, and framer.
16pub mod pipeline;
17/// Proximity-1 coding pipeline (CCSDS 211.2-B-3).
18pub mod proximity1;
19
20// ── Layer boundary traits ──────────────────────────────────────
21
22/// Accepts a transfer frame and writes it through the coding chain
23/// to the physical layer.
24pub trait CodingWrite {
25    /// Error type for write operations.
26    type Error: core::error::Error;
27    /// Encodes and writes a transfer frame.
28    fn write(&mut self, frame: &[u8]) -> impl Future<Output = Result<(), Self::Error>>;
29}
30
31/// Reads coded bytes from the physical layer, decodes them, and
32/// returns the transfer frame.
33pub trait CodingRead {
34    /// Error type for read operations.
35    type Error: core::error::Error;
36    /// Reads and decodes a transfer frame into `buffer`.
37    fn read(&mut self, buffer: &mut [u8]) -> impl Future<Output = Result<usize, Self::Error>>;
38}
39
40// ── Group traits (re-exported from their respective modules) ──
41
42pub use fec::FecEncoder;
43pub use fec::FecDecoder;
44pub use framing::Framer;
45pub use framing::Deframer;
46
47// ── No-op types ──────────────────────────────────────────────
48
49/// No-op randomizer that passes data through unchanged.
50pub struct NoRandomizer;
51
52impl randomizer::Randomizer for NoRandomizer {
53    fn apply(&self, _buffer: &mut [u8]) {}
54    fn table(&self) -> &[u8] {
55        &[]
56    }
57}
58
59/// No-op FEC that passes data through unchanged.
60pub struct NoFec;
61
62impl FecEncoder for NoFec {
63    type Error = Infallible;
64    fn encode(&self, data: &[u8], output: &mut [u8]) -> Result<usize, Self::Error> {
65        let len = data.len();
66        output[..len].copy_from_slice(data);
67        Ok(len)
68    }
69}
70
71impl FecDecoder for NoFec {
72    type Error = Infallible;
73    fn decode(&self, data: &mut [u8]) -> Result<usize, Self::Error> {
74        Ok(data.len())
75    }
76}
77
78/// No-op framer that passes data through unchanged.
79pub struct NoFramer;
80
81impl Framer for NoFramer {
82    type Error = Infallible;
83    fn frame(&self, data: &[u8], output: &mut [u8]) -> Result<usize, Self::Error> {
84        let len = data.len();
85        output[..len].copy_from_slice(data);
86        Ok(len)
87    }
88}
89
90impl Deframer for NoFramer {
91    type Error = Infallible;
92    fn deframe(&self, data: &[u8], output: &mut [u8]) -> Result<usize, Self::Error> {
93        let len = data.len();
94        output[..len].copy_from_slice(data);
95        Ok(len)
96    }
97}