60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
pub struct NameData {
|
|
id: u32,
|
|
count: u32,
|
|
file_descriptions: Vec<FileDescription>,
|
|
}
|
|
|
|
struct FileDescription {
|
|
filename: String,
|
|
longname: String,
|
|
attrs: u32,
|
|
}
|
|
|
|
impl NameData {
|
|
pub fn new(id: u32, files: &[String]) -> NameData {
|
|
let count = files.len();
|
|
let files: Vec<FileDescription> = files
|
|
.iter()
|
|
.map(|a| FileDescription {
|
|
filename: a.to_string(),
|
|
longname: a.to_string(),
|
|
attrs: 0,
|
|
})
|
|
.collect();
|
|
NameData {
|
|
id: id,
|
|
count: count as u32,
|
|
file_descriptions: files,
|
|
}
|
|
}
|
|
pub fn serialize(&self) -> Vec<u8> {
|
|
let mut serialized_data: Vec<u8> = Vec::new();
|
|
serialized_data.extend(&self.id.to_be_bytes());
|
|
serialized_data.extend(&self.count.to_be_bytes());
|
|
serialized_data.extend(
|
|
self.file_descriptions
|
|
.iter()
|
|
.map(|a| a.serialize())
|
|
.collect::<Vec<Vec<u8>>>()
|
|
.concat(),
|
|
);
|
|
serialized_data
|
|
}
|
|
}
|
|
|
|
impl FileDescription {
|
|
fn serialize(&self) -> Vec<u8> {
|
|
let mut serialized_data: Vec<u8> = Vec::new();
|
|
let filename = crate::packet::types::string::String {
|
|
content: self.filename.clone(),
|
|
};
|
|
let longname = crate::packet::types::string::String {
|
|
content: self.longname.clone(),
|
|
};
|
|
serialized_data.extend(filename.serialize());
|
|
serialized_data.extend(longname.serialize());
|
|
serialized_data.extend(&self.attrs.to_be_bytes());
|
|
serialized_data
|
|
}
|
|
}
|