feat: add byte conversion to full header
This commit is contained in:
1 parent
c8213ce5a2
commit
21e0e7a113
1 file changed
+23
@@ -11,4 +11,27 @@ pub struct Header {
|
||||
extra_field_header: Option<ExtraFieldHeader>,
|
||||
original_file_name: Option<CString>,
|
||||
comment: Option<CString>,
|
||||
crc16: Option<u16>,
|
||||
}
|
||||
|
||||
impl From<Header> for Vec<u8> {
|
||||
fn from(header: Header) -> Self {
|
||||
let mut result = Vec::new();
|
||||
result.extend::<[u8; 10]>(header.base_header.into());
|
||||
if let Some(extra_field_header) = header.extra_field_header {
|
||||
result.append(&mut extra_field_header.into());
|
||||
}
|
||||
if let Some(original_file_name) = header.original_file_name {
|
||||
result.extend_from_slice(original_file_name.as_bytes_with_nul());
|
||||
}
|
||||
if let Some(comment) = header.comment {
|
||||
result.extend_from_slice(comment.as_bytes_with_nul());
|
||||
}
|
||||
if let Some(crc) = header.crc16 {
|
||||
let crc = crc.to_le_bytes();
|
||||
result.push(crc[0]);
|
||||
result.push(crc[1]);
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user