Now with a hashmap for ops lookup
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use Result;
|
||||
use block::Block;
|
||||
use ops::{Operation,num_to_op};
|
||||
use ops::{num_to_op, Operation};
|
||||
use Result;
|
||||
|
||||
#[allow(unknown_lints, len_without_is_empty)]
|
||||
pub trait BinReadable {
|
||||
fn get(&mut self) -> Result<u8>;
|
||||
fn cur(&self) -> usize;
|
||||
fn len(&self) -> usize;
|
||||
fn slice(&mut self, len: usize) -> &[u8];
|
||||
|
||||
fn is_empty(&self) -> bool;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ pub trait BinRead {
|
||||
fn read_i32(&mut self) -> Result<i32>;
|
||||
|
||||
fn read_block(&mut self) -> Result<Block>;
|
||||
fn read_op(&mut self) -> Result<Operation>;
|
||||
fn read_op(&mut self) -> Result<&'static Operation>;
|
||||
}
|
||||
|
||||
impl<T: BinReadable> BinRead for T {
|
||||
@@ -47,13 +47,13 @@ impl<T: BinReadable> BinRead for T {
|
||||
|
||||
fn read_u16(&mut self) -> Result<u16> {
|
||||
let a = u16::from(self.read_u8()?);
|
||||
let b = u16::from( self.read_u8()?);
|
||||
let b = u16::from(self.read_u8()?);
|
||||
Ok(a << 8 | b)
|
||||
}
|
||||
|
||||
fn read_u32(&mut self) -> Result<u32> {
|
||||
let a = u32::from(self.read_u16()?);
|
||||
let b = u32::from( self.read_u16()?);
|
||||
let b = u32::from(self.read_u16()?);
|
||||
Ok(a << 16 | b)
|
||||
}
|
||||
fn read_i8(&mut self) -> Result<i8> {
|
||||
@@ -78,7 +78,7 @@ impl<T: BinReadable> BinRead for T {
|
||||
Ok(Block::new(origin, self.slice(len)))
|
||||
}
|
||||
|
||||
fn read_op(&mut self) -> Result<Operation> {
|
||||
fn read_op(&mut self) -> Result<&'static Operation> {
|
||||
Ok(num_to_op(self.read_u8()?))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user