diff --git a/ipc/codegen/src/serialization.rs b/ipc/codegen/src/serialization.rs index c9f6b847c..79608b8f4 100644 --- a/ipc/codegen/src/serialization.rs +++ b/ipc/codegen/src/serialization.rs @@ -155,6 +155,16 @@ struct BinaryExpressions { pub read: P, } +fn replace_qualified(s: &str) -> String { + if let Some(pos) = s.find("<") { + let mut source = s.to_owned(); + source.insert(pos, ':'); + source.insert(pos, ':'); + source + } + else { s.to_owned() } +} + fn binary_expr_struct( cx: &ExtCtxt, builder: &aster::AstBuilder, @@ -169,7 +179,7 @@ fn binary_expr_struct( &::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty))); let field_type_ident_qualified = builder.id( - &::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty)).replace("<", "::<")); + replace_qualified(&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty)))); let index_ident = builder.id(format!("__field{}", index)); value_ident.and_then(|x| { @@ -205,7 +215,7 @@ fn binary_expr_struct( &::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty))); let field_type_ident_qualified = builder.id( - &::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty)).replace("<", "::<")); + replace_qualified(&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty)))); let member_expr = match value_ident { Some(x) => { @@ -376,7 +386,7 @@ fn fields_sequence( tt.push(Token( _sp, token::Ident( - ext_cx.ident_of(&::syntax::print::pprust::ty_to_string(&field.ty).replace("<", "::<")), + ext_cx.ident_of(&replace_qualified(&::syntax::print::pprust::ty_to_string(&field.ty))), token::Plain))); tt.push(Token(_sp, token::ModSep)); tt.push(Token(_sp, token::Ident(ext_cx.ident_of("from_bytes"), token::Plain))); @@ -450,7 +460,7 @@ fn named_fields_sequence( tt.push(Token( _sp, token::Ident( - ext_cx.ident_of(&::syntax::print::pprust::ty_to_string(&field.ty).replace("<", "::<")), + ext_cx.ident_of(&replace_qualified(&::syntax::print::pprust::ty_to_string(&field.ty))), token::Plain))); tt.push(Token(_sp, token::ModSep)); tt.push(Token(_sp, token::Ident(ext_cx.ident_of("from_bytes"), token::Plain))); diff --git a/ipc/rpc/src/binary.rs b/ipc/rpc/src/binary.rs index 3ace31b2f..3ba172c6e 100644 --- a/ipc/rpc/src/binary.rs +++ b/ipc/rpc/src/binary.rs @@ -17,6 +17,7 @@ //! Binary representation of types use util::bytes::Populatable; +use util::numbers::{U256, H256, H2048, Address}; use std::mem; use std::collections::VecDeque; @@ -208,6 +209,29 @@ impl BinaryConvertable for String { } } +impl BinaryConvertable for ::std::cell::RefCell where T: BinaryConvertable { + fn size(&self) -> usize { + self.borrow().size() + } + + fn from_empty_bytes() -> Result { + Ok(::std::cell::RefCell::new(try!(T::from_empty_bytes()))) + } + + fn from_bytes(buffer: &[u8], length_stack: &mut VecDeque) -> Result { + Ok(::std::cell::RefCell::new(try!(T::from_bytes(buffer, length_stack)))) + } + + fn to_bytes(&self, buffer: &mut [u8], length_stack: &mut VecDeque) -> Result<(), BinaryConvertError> { + try!(self.borrow().to_bytes(buffer, length_stack)); + Ok(()) + } + + fn len_params() -> usize { + T::len_params() + } +} + impl BinaryConvertable for Vec { fn size(&self) -> usize { self.len() @@ -370,8 +394,13 @@ macro_rules! binary_fixed_size { binary_fixed_size!(u64); binary_fixed_size!(u32); +binary_fixed_size!(usize); binary_fixed_size!(i32); binary_fixed_size!(bool); +binary_fixed_size!(U256); +binary_fixed_size!(H256); +binary_fixed_size!(H2048); +binary_fixed_size!(Address); #[test] fn vec_serialize() { diff --git a/ipc/tests/Cargo.toml b/ipc/tests/Cargo.toml index 286fffd18..bde5b4c62 100644 --- a/ipc/tests/Cargo.toml +++ b/ipc/tests/Cargo.toml @@ -9,8 +9,6 @@ path = "run.rs" [dependencies] "ethcore-ipc" = { path = "../rpc" } -bincode = "*" -serde = "0.7.0" ethcore-devtools = { path = "../../devtools" } semver = "0.2.0" nanomsg = { git = "https://github.com/ethcore/nanomsg.rs.git" }