start EOF
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good
Rust/spacepackets/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2023-06-06 08:59:18 +02:00
parent bb1ecb29b6
commit 0b714b7426
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 37 additions and 8 deletions

0
src/cfdp/pdu/eof.rs Normal file
View File

View File

@ -130,7 +130,7 @@ impl<'seg_meta, 'file_data> FileDataPdu<'seg_meta, 'file_data> {
fn calc_pdu_datafield_len(&self) -> usize {
let mut len = core::mem::size_of::<u32>();
if self.pdu_header.pdu_conf.file_flag == LargeFileFlag::Large {
len += core::mem::size_of::<u32>();
len += 4;
}
if self.segment_metadata.is_some() {
len += self.segment_metadata.as_ref().unwrap().written_len()
@ -300,7 +300,7 @@ mod tests {
}
#[test]
fn test_with_seg_metadata() {
fn test_with_seg_metadata_serialization() {
let src_id = UbfU8::new(1);
let dest_id = UbfU8::new(2);
let transaction_seq_num = UbfU8::new(3);
@ -363,4 +363,33 @@ mod tests {
current_idx += 1;
assert_eq!(current_idx, fd_pdu.written_len());
}
#[test]
fn test_with_seg_metadata_deserialization() {
let src_id = UbfU8::new(1);
let dest_id = UbfU8::new(2);
let transaction_seq_num = UbfU8::new(3);
let common_conf =
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_num).unwrap();
let pdu_header = PduHeader::new_for_file_data(
common_conf,
0,
SegmentMetadataFlag::Present,
SegmentationControl::WithRecordBoundaryPreservation,
);
let file_data: [u8; 4] = [1, 2, 3, 4];
let seg_metadata: [u8; 4] = [4, 3, 2, 1];
let segment_meta =
SegmentMetadata::new(RecordContinuationState::StartAndEnd, Some(&seg_metadata))
.unwrap();
let fd_pdu = FileDataPdu::new_with_seg_metadata(pdu_header, segment_meta, 10, &file_data);
let mut buf: [u8; 32] = [0; 32];
fd_pdu
.write_to_bytes(&mut buf)
.expect("writing FD PDU failed");
let fd_pdu_read_back = FileDataPdu::from_bytes(&buf);
assert!(fd_pdu_read_back.is_ok());
let fd_pdu_read_back = fd_pdu_read_back.unwrap();
assert_eq!(fd_pdu_read_back, fd_pdu);
}
}

View File

@ -92,13 +92,13 @@ pub struct MetadataPdu<'src_name, 'dest_name, 'opts> {
}
impl<'src_name, 'dest_name, 'opts> MetadataPdu<'src_name, 'dest_name, 'opts> {
pub fn new(
pub fn new_no_opts(
pdu_header: PduHeader,
metadata_params: MetadataGenericParams,
src_file_name: Lv<'src_name>,
dest_file_name: Lv<'dest_name>,
) -> Self {
Self::new_generic(
Self::new(
pdu_header,
metadata_params,
src_file_name,
@ -114,7 +114,7 @@ impl<'src_name, 'dest_name, 'opts> MetadataPdu<'src_name, 'dest_name, 'opts> {
dest_file_name: Lv<'dest_name>,
options: &'opts [u8],
) -> Self {
Self::new_generic(
Self::new(
pdu_header,
metadata_params,
src_file_name,
@ -123,7 +123,7 @@ impl<'src_name, 'dest_name, 'opts> MetadataPdu<'src_name, 'dest_name, 'opts> {
)
}
pub fn new_generic(
pub fn new(
mut pdu_header: PduHeader,
metadata_params: MetadataGenericParams,
src_file_name: Lv<'src_name>,
@ -336,7 +336,7 @@ pub mod tests {
(
src_filename,
dest_filename,
MetadataPdu::new_generic(
MetadataPdu::new(
pdu_header,
metadata_params,
src_filename,
@ -541,7 +541,7 @@ pub mod tests {
let dest_filename =
Lv::new_from_str(DEST_FILENAME).expect("Generating destination LV failed");
let metadata_pdu =
MetadataPdu::new(pdu_header, metadata_params, src_filename, dest_filename);
MetadataPdu::new_no_opts(pdu_header, metadata_params, src_filename, dest_filename);
assert_eq!(metadata_pdu.pdu_header().pdu_type(), PduType::FileDirective);
}
}