Skip to main content

leodos_protocols/transport/cfdp/pdu/file_data/
mod.rs

1use crate::transport::cfdp::CfdpError;
2
3/// File Data PDU with segment metadata.
4pub mod with_meta;
5/// File Data PDU without segment metadata.
6pub mod without_meta;
7
8/// A parsed File Data PDU, dispatching between with-metadata and without-metadata variants.
9#[derive(Debug, Clone, Copy)]
10pub enum FileDataPdu<'a> {
11    /// File Data PDU that includes segment metadata.
12    WithMeta(&'a with_meta::FileDataPduWithMeta),
13    /// File Data PDU without segment metadata.
14    WithoutMeta(&'a without_meta::FileDataPduWithoutMeta),
15}
16
17impl<'a> FileDataPdu<'a> {
18    /// Returns the file data payload bytes.
19    pub fn file_data(&self, large_file_flag: bool) -> Result<&'a [u8], CfdpError> {
20        match self {
21            FileDataPdu::WithMeta(pdu) => pdu.file_data(large_file_flag),
22            FileDataPdu::WithoutMeta(pdu) => pdu.file_data(large_file_flag),
23        }
24    }
25
26    /// Returns the byte offset into the file for this data segment.
27    pub fn offset(&self, large_file_flag: bool) -> Result<u64, CfdpError> {
28        match self {
29            FileDataPdu::WithMeta(pdu) => pdu.offset(large_file_flag),
30            FileDataPdu::WithoutMeta(pdu) => pdu.offset(large_file_flag),
31        }
32    }
33}