/// Load the simulator from the given binary data.
///
/// # Examples
///
/// ```
/// use ibcm::Simulator;
///
/// let input: &[u8] = &[0x00, 0x10, 0x00, 0x18, 0x00, 0x00];
/// let sim = Simulator::from_binary(input).unwrap();
///
/// assert_eq!(&[0x1000, 0x1800, 0x0000], &sim.memory()[..3]);
/// ```
Load the simulator from the given binary data.
Load the simulator from the given binary data .
pub fn from_binary<R: Read>(input: R) -> Result<Self> {
        let mut data = [0u16; 4096];
        let mut i = 0;
        // Whether we're filling the top half of the byte.
        // This is initially false because we're treating input as
        // little-endian for compatibility with the reference
        // implementation.
        let mut upper = false;
        for b in input.bytes() {
            let b = b.chain_err(|| ErrorKind::Io("could not read from binary input".into()))?;
            if i >= data.len() {
                return Err(ErrorKind::ProgramTooLong.into());
            }
            if upper {
                data[i] |= (b as u16) << 8;
                i += 1;
            } else {
                data[i] |= b as u16;
            }
            upper = !upper;
        }
        Ok(Simulator::from_memory(data, i))
    }
pub fn from_binary < R : Read > ( input : R ) -> Result < Self > { let mut data = [ 0u16 ; 4096 ] ; let mut i = 0 ; // Whether we're filling the top half of the byte. // This is initially false because we're treating input as // little-endian for compatibility with the reference // implementation. let mut upper = false ; for b in input . bytes ( ) { let b = b . chain_err ( | | ErrorKind :: Io ( " " . into ( ) ) ) ? ; if i >= data . len ( ) { return Err ( ErrorKind :: ProgramTooLong . into ( ) ) ; } if upper { data [ i ] |= ( b as u16 ) << 8 ; i += 1 ; } else { data [ i ] |= b as u16 ; } upper = ! upper ; } Ok ( Simulator :: from_memory ( data , i ) ) }
Load the simulator from the given binary data.
Load the simulator from the given binary data .
input
R
examples
```
use ibcm::Simulator.




` ` ` use ibcm :: Simulator .