fn cpu_load<'a>(req: &mut Request, response: Response<'a>) -> MiddlewareResult<'a> {
	let id = req.param("id").parse::<i32>().ok().expect("invalid cpu id");
	let mem_js = req.json_as::<Vec<String>>().unwrap();
	let mem_native: Vec<u8> = mem_js.iter().map(|hex| {
		match hex[..].from_hex() {
			Ok(decoded) => { if decoded.len() > 0 { decoded[0] } else { 0xFF } },
			Err(msg) => { debug!("error reading json memory: {}", msg); 0xFF },
		}
	}).collect();

	info!("length of mem instructions: {}", mem_native.len());

	// pair odd u8s with even u8s to produce u16 ops.
	let even_mn = mem_native.iter().enumerate().filter(|&(idx, _)| { idx % 2 == 0 });
	let odd_mn  = mem_native.iter().enumerate().filter(|&(idx, _)| { idx % 2 != 0 });
	let ops: Vec<u16> = even_mn.zip(odd_mn).map(|((_, &msb), (_, &lsb))| {
		((msb as u16) << 8) | (lsb as u16)
	}).collect();

	match req.extensions().get::<CpuDb>() {
		Some(cpuserv) => {
			match cpuserv.write().unwrap().database.get_mut(&id) {
				Some(cpu) => {
					cpu.state.init_mem(&ops[..]); // TODO: load from req.
					cpu.last = cpu.state;

					response.send(format!("{}", cpu.state.js_dump()))
				},
				None => { response.send("did not find the cpu") },
			}
		},

		None => { response.send("did not find cpu serv") }
	}
}
/// POST /cpu/:id/load
/// Overwrites the CPUs system memory with response data.
/// The current machine state is then dumped into the response as JSON.
POST /cpu/:id/load
Overwrites the CPUs system memory with response data.
The current machine state is then dumped into the response as JSON.
POST / cpu / : id / load Overwrites the CPUs system memory with response data . The current machine state is then dumped into the response as JSON .
fn cpu_load<'a>(req: &mut Request, response: Response<'a>) -> MiddlewareResult<'a> {
	let id = req.param("id").parse::<i32>().ok().expect("invalid cpu id");
	let mem_js = req.json_as::<Vec<String>>().unwrap();
	let mem_native: Vec<u8> = mem_js.iter().map(|hex| {
		match hex[..].from_hex() {
			Ok(decoded) => { if decoded.len() > 0 { decoded[0] } else { 0xFF } },
			Err(msg) => { debug!("error reading json memory: {}", msg); 0xFF },
		}
	}).collect();
	info!("length of mem instructions: {}", mem_native.len());
	// pair odd u8s with even u8s to produce u16 ops.
	let even_mn = mem_native.iter().enumerate().filter(|&(idx, _)| { idx % 2 == 0 });
	let odd_mn  = mem_native.iter().enumerate().filter(|&(idx, _)| { idx % 2 != 0 });
	let ops: Vec<u16> = even_mn.zip(odd_mn).map(|((_, &msb), (_, &lsb))| {
		((msb as u16) << 8) | (lsb as u16)
	}).collect();
	match req.extensions().get::<CpuDb>() {
		Some(cpuserv) => {
			match cpuserv.write().unwrap().database.get_mut(&id) {
				Some(cpu) => {
					cpu.state.init_mem(&ops[..]); // TODO: load from req.
					cpu.last = cpu.state;
					response.send(format!("{}", cpu.state.js_dump()))
				},
				None => { response.send("did not find the cpu") },
			}
		},
		None => { response.send("did not find cpu serv") }
	}
}
fn cpu_load < ' a > ( req : & mut Request , response : Response < ' a > ) -> MiddlewareResult < ' a > { let id = req . param ( " " ) . parse :: < i32 > ( ) . ok ( ) . expect ( " " ) ; let mem_js = req . json_as :: < Vec < String > > ( ) . unwrap ( ) ; let mem_native : Vec < u8 > = mem_js . iter ( ) . map ( | hex | { match hex [ .. ] . from_hex ( ) { Ok ( decoded ) => { if decoded . len ( ) > 0 { decoded [ 0 ] } else { 0xFF } } , Err ( msg ) => { debug ! ( " " msg ) ; 0xFF } , } } ) . collect ( ) ; info ! ( " " mem_native len ( ) ) ; // pair odd u8s with even u8s to produce u16 ops. let even_mn = mem_native . iter ( ) . enumerate ( ) . filter ( | & ( idx , _ ) | { idx % 2 == 0 } ) ; let odd_mn = mem_native . iter ( ) . enumerate ( ) . filter ( | & ( idx , _ ) | { idx % 2 != 0 } ) ; let ops : Vec < u16 > = even_mn . zip ( odd_mn ) . map ( | ( ( _ , & msb ) , ( _ , & lsb ) ) | { ( ( msb as u16 ) << 8 ) | ( lsb as u16 ) } ) . collect ( ) ; match req . extensions ( ) . get :: < CpuDb > ( ) { Some ( cpuserv ) => { match cpuserv . write ( ) . unwrap ( ) . database . get_mut ( & id ) { Some ( cpu ) => { cpu . state . init_mem ( & ops [ .. ] ) ; // TODO: load from req. cpu . last = cpu . state ; response . send ( format ! ( " " cpu state js_dump ( ) ) ) } , None => { response . send ( " " ) } , } } , None => { response . send ( " " ) } } }
POST /cpu/:id/load
Overwrites the CPUs system memory with response data.
POST / cpu / : id / load Overwrites the CPUs system memory with response data .
req
&mut Request
response
Response<'a>