testing write functions
parent
32855fa213
commit
07f08752d1
|
@ -476,6 +476,22 @@ impl OptU16
|
|||
Some(n) => Some(n.get() - 1),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the memory representation of this integer as a byte array
|
||||
/// in big-endian (network) byte order.
|
||||
#[inline]
|
||||
pub fn to_be_bytes(self) -> [u8; 2]
|
||||
{
|
||||
<Self as Into<u16>>::into(self).to_be_bytes()
|
||||
}
|
||||
|
||||
/// Return the memory representation of this integer as a byte array
|
||||
/// in little-endian byte order.
|
||||
#[inline]
|
||||
pub fn to_le_bytes(self) -> [u8; 2]
|
||||
{
|
||||
<Self as Into<u16>>::into(self).to_le_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for OptU16
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Cyclic redundancy check function.
|
||||
//! Checksum functions.
|
||||
|
||||
fn crc_accum(a: u32, _: u32) -> u32
|
||||
{
|
||||
|
|
|
@ -20,6 +20,18 @@ pub fn read_lightfunc(b: &[u8]) -> ResultS<LightFunc>
|
|||
Ok(LightFunc{ftype, prd_nrm, prd_dta, val_nrm, val_dta})
|
||||
}
|
||||
|
||||
/// Writes a `LightFunc` object.
|
||||
pub fn write_lightfunc(v: &LightFunc) -> Vec<u8>
|
||||
{
|
||||
let mut o = Vec::with_capacity(14);
|
||||
o.extend(&(v.ftype as u16).to_be_bytes());
|
||||
o.extend(&v.prd_nrm.to_be_bytes());
|
||||
o.extend(&v.prd_dta.to_be_bytes());
|
||||
o.extend(&v.val_nrm.to_be_bytes());
|
||||
o.extend(&v.val_dta.to_be_bytes());
|
||||
o
|
||||
}
|
||||
|
||||
/// Reads a `SideTex` object.
|
||||
pub fn read_sidetex(b: &[u8]) -> ResultS<SideTex>
|
||||
{
|
||||
|
@ -33,6 +45,15 @@ pub fn read_sidetex(b: &[u8]) -> ResultS<SideTex>
|
|||
Ok(SideTex{offs, tex_id})
|
||||
}
|
||||
|
||||
/// Writes a `SideTex` object.
|
||||
pub fn write_sidetex(v: &SideTex) -> Vec<u8>
|
||||
{
|
||||
let mut o = Vec::with_capacity(6);
|
||||
o.extend(write_point(&v.offs));
|
||||
o.extend(&v.tex_id.to_be_bytes());
|
||||
o
|
||||
}
|
||||
|
||||
/// Reads a `Point` object.
|
||||
pub fn read_point(b: &[u8]) -> ResultS<Point>
|
||||
{
|
||||
|
@ -46,6 +67,15 @@ pub fn read_point(b: &[u8]) -> ResultS<Point>
|
|||
Ok(Point{x, y})
|
||||
}
|
||||
|
||||
/// Writes a `Point` object.
|
||||
pub fn write_point(v: &Point) -> Vec<u8>
|
||||
{
|
||||
let mut o = Vec::with_capacity(4);
|
||||
o.extend(&v.x.to_be_bytes());
|
||||
o.extend(&v.y.to_be_bytes());
|
||||
o
|
||||
}
|
||||
|
||||
/// Reads a `Minf` chunk.
|
||||
pub fn read_minf(b: &[u8]) -> ResultS<Minf>
|
||||
{
|
||||
|
@ -65,6 +95,20 @@ pub fn read_minf(b: &[u8]) -> ResultS<Minf>
|
|||
entr_flags, level_name})
|
||||
}
|
||||
|
||||
/// Writes a `Minf` chunk.
|
||||
pub fn write_minf(v: &Minf) -> Vec<u8>
|
||||
{
|
||||
let mut o = Vec::with_capacity(4);
|
||||
o.extend(&v.texture_id.to_be_bytes());
|
||||
o.extend(&v.physics_id.to_be_bytes());
|
||||
o.extend(&v.skypict_id.to_be_bytes());
|
||||
o.extend(&v.miss_flags.bits().to_be_bytes());
|
||||
o.extend(&v.envi_flags.bits().to_be_bytes());
|
||||
o.extend(&pad_0(to_mac_roman(v.level_name), 66));
|
||||
o.extend(&v.entr_flags.bits().to_be_bytes());
|
||||
o
|
||||
}
|
||||
|
||||
/// Reads an old `Minf` chunk.
|
||||
pub fn read_old_minf(b: &[u8]) -> ResultS<Minf>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue