init: initial commit of packager
This commit is contained in:
commit
36c782a564
25 changed files with 478 additions and 0 deletions
36
pkgfile/src/lib.rs
Normal file
36
pkgfile/src/lib.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
pub struct PKGFile {
|
||||
pub manifest: String,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for PKGFile {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: Vec<u8>) -> Result<Self, ()> {
|
||||
match value[0] {
|
||||
1 => {
|
||||
let header: Vec<u32> = value[..3]
|
||||
.iter()
|
||||
.map(|v| u32::from(*v))
|
||||
.collect();
|
||||
let manifest_size: u32 = ((header[1] << 8) | header[2]);
|
||||
if manifest_size > value.len() as u32 {
|
||||
return Err(());
|
||||
}
|
||||
Ok(PKGFile {
|
||||
manifest: match String::from_utf8(
|
||||
value[
|
||||
3..(manifest_size as usize)
|
||||
].to_vec()
|
||||
)
|
||||
{
|
||||
Ok(s) => s,
|
||||
_ => return Err(())
|
||||
},
|
||||
data: value[(manifest_size as usize)..].to_vec(),
|
||||
})
|
||||
}
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue