|
@@ -92,6 +92,32 @@ impl<T> ByteReader<T> where T: Iterator<Item=u8> {
|
|
|
Ok(b as f32 / 255.0)
|
|
|
}
|
|
|
|
|
|
+ pub fn read_u64be(&mut self) -> Result<u64, String> {
|
|
|
+ let a = try!(self.next());
|
|
|
+ let b = try!(self.next());
|
|
|
+ let c = try!(self.next());
|
|
|
+ let d = try!(self.next());
|
|
|
+ let e = try!(self.next());
|
|
|
+ let f = try!(self.next());
|
|
|
+ let g = try!(self.next());
|
|
|
+ let h = try!(self.next());
|
|
|
+ let rs = [ h, g, f, e, d, c, b, a ];
|
|
|
+ unsafe { Ok(mem::transmute::<[u8;8],u64>(rs)) }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn read_u64le(&mut self) -> Result<u64, String> {
|
|
|
+ let a = try!(self.next());
|
|
|
+ let b = try!(self.next());
|
|
|
+ let c = try!(self.next());
|
|
|
+ let d = try!(self.next());
|
|
|
+ let e = try!(self.next());
|
|
|
+ let f = try!(self.next());
|
|
|
+ let g = try!(self.next());
|
|
|
+ let h = try!(self.next());
|
|
|
+ let rs = [ a, b, c, d, e, f, g, h ];
|
|
|
+ unsafe { Ok(mem::transmute::<[u8;8],u64>(rs)) }
|
|
|
+ }
|
|
|
+
|
|
|
pub fn read_u32be(&mut self) -> Result<u32, String> {
|
|
|
let a = try!(self.next());
|
|
|
let b = try!(self.next());
|
|
@@ -101,6 +127,15 @@ impl<T> ByteReader<T> where T: Iterator<Item=u8> {
|
|
|
unsafe { Ok(mem::transmute::<[u8;4],u32>(rs)) }
|
|
|
}
|
|
|
|
|
|
+ pub fn read_u32le(&mut self) -> Result<u32, String> {
|
|
|
+ let a = try!(self.next());
|
|
|
+ let b = try!(self.next());
|
|
|
+ let c = try!(self.next());
|
|
|
+ let d = try!(self.next());
|
|
|
+ let rs = [ a, b, c, d ];
|
|
|
+ unsafe { Ok(mem::transmute::<[u8;4],u32>(rs)) }
|
|
|
+ }
|
|
|
+
|
|
|
pub fn read_u16be(&mut self) -> Result<u16, String> {
|
|
|
let a = try!(self.next());
|
|
|
let b = try!(self.next());
|
|
@@ -108,6 +143,13 @@ impl<T> ByteReader<T> where T: Iterator<Item=u8> {
|
|
|
unsafe { Ok(mem::transmute::<[u8;2],u16>(rs)) }
|
|
|
}
|
|
|
|
|
|
+ pub fn read_u16le(&mut self) -> Result<u16, String> {
|
|
|
+ let a = try!(self.next());
|
|
|
+ let b = try!(self.next());
|
|
|
+ let rs = [ a, b ];
|
|
|
+ unsafe { Ok(mem::transmute::<[u8;2],u16>(rs)) }
|
|
|
+ }
|
|
|
+
|
|
|
/// This reads a 64-bit int with a packed PrefixInteger representation.
|
|
|
/// The shorter the int, the shorter the representation.
|
|
|
pub fn read_prefix_int(&mut self) -> Result<u64, String> {
|