ipc fixes
This commit is contained in:
		
							parent
							
								
									9a3e6a6135
								
							
						
					
					
						commit
						922400f191
					
				| @ -155,6 +155,16 @@ struct BinaryExpressions { | |||||||
| 	pub read: P<ast::Expr>, | 	pub read: P<ast::Expr>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 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( | fn binary_expr_struct( | ||||||
| 	cx: &ExtCtxt, | 	cx: &ExtCtxt, | ||||||
| 	builder: &aster::AstBuilder, | 	builder: &aster::AstBuilder, | ||||||
| @ -169,7 +179,7 @@ fn binary_expr_struct( | |||||||
| 			&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty))); | 			&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty))); | ||||||
| 
 | 
 | ||||||
| 		let field_type_ident_qualified = builder.id( | 		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)); | 		let index_ident = builder.id(format!("__field{}", index)); | ||||||
| 		value_ident.and_then(|x| { | 		value_ident.and_then(|x| { | ||||||
| @ -205,7 +215,7 @@ fn binary_expr_struct( | |||||||
| 			&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty))); | 			&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty))); | ||||||
| 
 | 
 | ||||||
| 		let field_type_ident_qualified = builder.id( | 		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 { | 		let member_expr = match value_ident { | ||||||
| 			Some(x) => { | 			Some(x) => { | ||||||
| @ -376,7 +386,7 @@ fn fields_sequence( | |||||||
| 				tt.push(Token( | 				tt.push(Token( | ||||||
| 					_sp, | 					_sp, | ||||||
| 					token::Ident( | 					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))); | 						token::Plain))); | ||||||
| 				tt.push(Token(_sp, token::ModSep)); | 				tt.push(Token(_sp, token::ModSep)); | ||||||
| 				tt.push(Token(_sp, token::Ident(ext_cx.ident_of("from_bytes"), token::Plain))); | 				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( | 				tt.push(Token( | ||||||
| 					_sp, | 					_sp, | ||||||
| 					token::Ident( | 					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))); | 						token::Plain))); | ||||||
| 				tt.push(Token(_sp, token::ModSep)); | 				tt.push(Token(_sp, token::ModSep)); | ||||||
| 				tt.push(Token(_sp, token::Ident(ext_cx.ident_of("from_bytes"), token::Plain))); | 				tt.push(Token(_sp, token::Ident(ext_cx.ident_of("from_bytes"), token::Plain))); | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ | |||||||
| //! Binary representation of types
 | //! Binary representation of types
 | ||||||
| 
 | 
 | ||||||
| use util::bytes::Populatable; | use util::bytes::Populatable; | ||||||
|  | use util::numbers::{U256, H256, H2048, Address}; | ||||||
| use std::mem; | use std::mem; | ||||||
| use std::collections::VecDeque; | use std::collections::VecDeque; | ||||||
| 
 | 
 | ||||||
| @ -208,6 +209,29 @@ impl BinaryConvertable for String { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl<T> BinaryConvertable for ::std::cell::RefCell<T> where T: BinaryConvertable { | ||||||
|  | 	fn size(&self) -> usize { | ||||||
|  | 		self.borrow().size() | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	fn from_empty_bytes() -> Result<Self, BinaryConvertError> { | ||||||
|  | 		Ok(::std::cell::RefCell::new(try!(T::from_empty_bytes()))) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	fn from_bytes(buffer: &[u8], length_stack: &mut VecDeque<usize>) -> Result<Self, BinaryConvertError> { | ||||||
|  | 		Ok(::std::cell::RefCell::new(try!(T::from_bytes(buffer, length_stack)))) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	fn to_bytes(&self, buffer: &mut [u8], length_stack: &mut VecDeque<usize>) -> Result<(), BinaryConvertError> { | ||||||
|  | 		try!(self.borrow().to_bytes(buffer, length_stack)); | ||||||
|  | 		Ok(()) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	fn len_params() -> usize { | ||||||
|  | 		T::len_params() | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| impl BinaryConvertable for Vec<u8> { | impl BinaryConvertable for Vec<u8> { | ||||||
| 	fn size(&self) -> usize { | 	fn size(&self) -> usize { | ||||||
| 		self.len() | 		self.len() | ||||||
| @ -370,8 +394,13 @@ macro_rules! binary_fixed_size { | |||||||
| 
 | 
 | ||||||
| binary_fixed_size!(u64); | binary_fixed_size!(u64); | ||||||
| binary_fixed_size!(u32); | binary_fixed_size!(u32); | ||||||
|  | binary_fixed_size!(usize); | ||||||
| binary_fixed_size!(i32); | binary_fixed_size!(i32); | ||||||
| binary_fixed_size!(bool); | binary_fixed_size!(bool); | ||||||
|  | binary_fixed_size!(U256); | ||||||
|  | binary_fixed_size!(H256); | ||||||
|  | binary_fixed_size!(H2048); | ||||||
|  | binary_fixed_size!(Address); | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
| fn vec_serialize() { | fn vec_serialize() { | ||||||
|  | |||||||
| @ -9,8 +9,6 @@ path = "run.rs" | |||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| "ethcore-ipc" = { path = "../rpc" } | "ethcore-ipc" = { path = "../rpc" } | ||||||
| bincode = "*" |  | ||||||
| serde = "0.7.0" |  | ||||||
| ethcore-devtools = { path = "../../devtools" } | ethcore-devtools = { path = "../../devtools" } | ||||||
| semver = "0.2.0" | semver = "0.2.0" | ||||||
| nanomsg = { git = "https://github.com/ethcore/nanomsg.rs.git" } | nanomsg = { git = "https://github.com/ethcore/nanomsg.rs.git" } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user