start EOF
This commit is contained in:
parent
bb1ecb29b6
commit
0b714b7426
0
src/cfdp/pdu/eof.rs
Normal file
0
src/cfdp/pdu/eof.rs
Normal file
@ -130,7 +130,7 @@ impl<'seg_meta, 'file_data> FileDataPdu<'seg_meta, 'file_data> {
|
|||||||
fn calc_pdu_datafield_len(&self) -> usize {
|
fn calc_pdu_datafield_len(&self) -> usize {
|
||||||
let mut len = core::mem::size_of::<u32>();
|
let mut len = core::mem::size_of::<u32>();
|
||||||
if self.pdu_header.pdu_conf.file_flag == LargeFileFlag::Large {
|
if self.pdu_header.pdu_conf.file_flag == LargeFileFlag::Large {
|
||||||
len += core::mem::size_of::<u32>();
|
len += 4;
|
||||||
}
|
}
|
||||||
if self.segment_metadata.is_some() {
|
if self.segment_metadata.is_some() {
|
||||||
len += self.segment_metadata.as_ref().unwrap().written_len()
|
len += self.segment_metadata.as_ref().unwrap().written_len()
|
||||||
@ -300,7 +300,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_with_seg_metadata() {
|
fn test_with_seg_metadata_serialization() {
|
||||||
let src_id = UbfU8::new(1);
|
let src_id = UbfU8::new(1);
|
||||||
let dest_id = UbfU8::new(2);
|
let dest_id = UbfU8::new(2);
|
||||||
let transaction_seq_num = UbfU8::new(3);
|
let transaction_seq_num = UbfU8::new(3);
|
||||||
@ -363,4 +363,33 @@ mod tests {
|
|||||||
current_idx += 1;
|
current_idx += 1;
|
||||||
assert_eq!(current_idx, fd_pdu.written_len());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,13 +92,13 @@ pub struct MetadataPdu<'src_name, 'dest_name, 'opts> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'src_name, 'dest_name, 'opts> 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,
|
pdu_header: PduHeader,
|
||||||
metadata_params: MetadataGenericParams,
|
metadata_params: MetadataGenericParams,
|
||||||
src_file_name: Lv<'src_name>,
|
src_file_name: Lv<'src_name>,
|
||||||
dest_file_name: Lv<'dest_name>,
|
dest_file_name: Lv<'dest_name>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_generic(
|
Self::new(
|
||||||
pdu_header,
|
pdu_header,
|
||||||
metadata_params,
|
metadata_params,
|
||||||
src_file_name,
|
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>,
|
dest_file_name: Lv<'dest_name>,
|
||||||
options: &'opts [u8],
|
options: &'opts [u8],
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_generic(
|
Self::new(
|
||||||
pdu_header,
|
pdu_header,
|
||||||
metadata_params,
|
metadata_params,
|
||||||
src_file_name,
|
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,
|
mut pdu_header: PduHeader,
|
||||||
metadata_params: MetadataGenericParams,
|
metadata_params: MetadataGenericParams,
|
||||||
src_file_name: Lv<'src_name>,
|
src_file_name: Lv<'src_name>,
|
||||||
@ -336,7 +336,7 @@ pub mod tests {
|
|||||||
(
|
(
|
||||||
src_filename,
|
src_filename,
|
||||||
dest_filename,
|
dest_filename,
|
||||||
MetadataPdu::new_generic(
|
MetadataPdu::new(
|
||||||
pdu_header,
|
pdu_header,
|
||||||
metadata_params,
|
metadata_params,
|
||||||
src_filename,
|
src_filename,
|
||||||
@ -541,7 +541,7 @@ pub mod tests {
|
|||||||
let dest_filename =
|
let dest_filename =
|
||||||
Lv::new_from_str(DEST_FILENAME).expect("Generating destination LV failed");
|
Lv::new_from_str(DEST_FILENAME).expect("Generating destination LV failed");
|
||||||
let metadata_pdu =
|
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);
|
assert_eq!(metadata_pdu.pdu_header().pdu_type(), PduType::FileDirective);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user