[cache (rust)] Implement Pack and Default for restoration
This commit is contained in:
parent
86e2db3a1a
commit
1907dab5ee
17
src/cache/hint.rs
vendored
17
src/cache/hint.rs
vendored
@ -1,3 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use byteorder::WriteBytesExt;
|
||||
use nom::IResult;
|
||||
use std::convert::TryInto;
|
||||
|
||||
@ -26,4 +28,19 @@ impl Unpack for Hint {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pack for Hint {
|
||||
fn pack<W: WriteBytesExt>(&self, data: &mut W) -> Result<()> {
|
||||
for v in &self.hint {
|
||||
data.write_u8(*v)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Hint {
|
||||
fn default() -> Self {
|
||||
Hint { hint: [0; 4] }
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
18
src/cache/mapping.rs
vendored
18
src/cache/mapping.rs
vendored
@ -1,3 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use byteorder::WriteBytesExt;
|
||||
use nom::number::complete::*;
|
||||
use nom::IResult;
|
||||
|
||||
@ -51,4 +53,20 @@ impl Unpack for Mapping {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pack for Mapping {
|
||||
fn pack<W: WriteBytesExt>(&self, data: &mut W) -> Result<()> {
|
||||
let m: u64 = (self.oblock << 16) | self.flags as u64;
|
||||
m.pack(data)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Mapping {
|
||||
fn default() -> Self {
|
||||
Mapping {
|
||||
oblock: 0,
|
||||
flags: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user