diff --git a/ipc/codegen/src/codegen.rs b/ipc/codegen/src/codegen.rs index 5b2b63561..a3a470266 100644 --- a/ipc/codegen/src/codegen.rs +++ b/ipc/codegen/src/codegen.rs @@ -258,7 +258,9 @@ fn push_proxy( fn implement_proxy_method_body( cx: &ExtCtxt, builder: &aster::AstBuilder, - dispatch: &Dispatch) + index: u16, + dispatch: &Dispatch, + ) -> P { let request = if dispatch.input_arg_names.len() > 0 { @@ -329,8 +331,10 @@ fn implement_proxy_method_body( request_serialization_statements.push( quote_stmt!(cx, let serialized_payload = ::bincode::serde::serialize(&payload, ::bincode::SizeLimit::Infinite).unwrap())); + let index_ident = builder.id(format!("{}", index).as_str()); + request_serialization_statements.push( - quote_stmt!(cx, ::ipc::invoke(0, &Some(serialized_payload), &mut socket))); + quote_stmt!(cx, ::ipc::invoke($index_ident, &Some(serialized_payload), &mut socket))); request_serialization_statements @@ -361,11 +365,12 @@ fn implement_proxy_method_body( fn implement_proxy_method( cx: &ExtCtxt, builder: &aster::AstBuilder, + index: u16, dispatch: &Dispatch) -> ast::ImplItem { let method_name = builder.id(dispatch.function_name.as_str()); - let body = implement_proxy_method_body(cx, builder, dispatch); + let body = implement_proxy_method_body(cx, builder, index, dispatch); let ext_cx = &*cx; // expanded version of this @@ -418,8 +423,9 @@ fn push_proxy_implementation( dispatches: &[Dispatch], push: &mut FnMut(Annotatable)) { + let mut index = -1i32; let items = dispatches.iter() - .map(|dispatch| P(implement_proxy_method(cx, builder, dispatch))) + .map(|dispatch| { index = index + 1; P(implement_proxy_method(cx, builder, index as u16, dispatch)) }) .collect::>>(); let implement = quote_item!(cx, diff --git a/ipc/rpc/src/interface.rs b/ipc/rpc/src/interface.rs index f51e82dfa..c99cd3e35 100644 --- a/ipc/rpc/src/interface.rs +++ b/ipc/rpc/src/interface.rs @@ -24,8 +24,8 @@ pub trait IpcInterface { pub fn invoke(method_num: u16, params: &Option>, w: &mut W) where W: ::std::io::Write { let buf_len = match *params { None => 2, Some(ref val) => val.len() + 2 }; let mut buf = vec![0u8; buf_len]; - buf[0] = (method_num & (255<<8)) as u8; - buf[1] = (method_num >> 8) as u8; + buf[1] = (method_num & 255) as u8; + buf[0] = (method_num >> 8) as u8; if params.is_some() { buf[2..buf_len].clone_from_slice(params.as_ref().unwrap()); }