refactored to new serialization
This commit is contained in:
@@ -38,7 +38,7 @@ pub fn main() {
|
||||
let src = Path::new(&out_dir).join("nested_ipc.rs");
|
||||
let dst = Path::new(&out_dir).join("nested_cg.rs");
|
||||
let mut registry = syntex::Registry::new();
|
||||
serde_codegen::register(&mut registry);
|
||||
codegen::register(&mut registry);
|
||||
registry.expand("", &src, &dst).unwrap();
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn main() {
|
||||
let src = Path::new(&out_dir).join("service_ipc.rs");
|
||||
let dst = Path::new(&out_dir).join("service_cg.rs");
|
||||
let mut registry = syntex::Registry::new();
|
||||
serde_codegen::register(&mut registry);
|
||||
codegen::register(&mut registry);
|
||||
registry.expand("", &src, &dst).unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,12 +41,20 @@ mod tests {
|
||||
#[test]
|
||||
fn call_service_handshake() {
|
||||
let mut socket = TestSocket::new_ready(vec![0, 0,
|
||||
// protocol version
|
||||
0, 0, 0, 0, 0, 0, 0, 5, b'1', b'.', b'0', b'.', b'0',
|
||||
// api version
|
||||
0, 0, 0, 0, 0, 0, 0, 5, b'1', b'.', b'0', b'.', b'0',
|
||||
// reserved
|
||||
// part count = 3
|
||||
0, 0, 0, 0, 0, 0, 0, 3,
|
||||
// part sizes
|
||||
0, 0, 0, 0, 0, 0, 0, 5,
|
||||
0, 0, 0, 0, 0, 0, 0, 5,
|
||||
0, 0, 0, 0, 0, 0, 0, 64,
|
||||
// total payload length
|
||||
0, 0, 0, 0, 0, 0, 0, 70,
|
||||
// protocol version
|
||||
b'1', b'.', b'0', b'.', b'0',
|
||||
// api version
|
||||
b'1', b'.', b'0', b'.', b'0',
|
||||
// reserved
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
@@ -14,4 +14,5 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
|
||||
include!(concat!(env!("OUT_DIR"), "/nested_cg.rs"));
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
use std::sync::RwLock;
|
||||
use std::ops::*;
|
||||
use ipc::IpcConfig;
|
||||
use ipc::BinaryConvertable;
|
||||
use std::mem;
|
||||
use ipc::binary::BinaryConvertError;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
pub struct DB<L: Sized> {
|
||||
pub writes: RwLock<u64>,
|
||||
@@ -30,7 +34,7 @@ pub trait DBWriter {
|
||||
|
||||
impl<L: Sized> IpcConfig for DB<L> {}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Binary)]
|
||||
pub enum DBError { Write, Read }
|
||||
|
||||
#[derive(Ipc)]
|
||||
|
||||
@@ -14,4 +14,5 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
|
||||
include!(concat!(env!("OUT_DIR"), "/service_cg.rs"));
|
||||
|
||||
@@ -16,40 +16,20 @@
|
||||
|
||||
use std::sync::RwLock;
|
||||
use std::ops::*;
|
||||
use std::convert::*;
|
||||
use ipc::IpcConfig;
|
||||
use util::bytes::{FromRawBytes, BytesConvertable, FromBytesError};
|
||||
use std::mem;
|
||||
use ipc::binary::BinaryConvertError;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
pub struct Service {
|
||||
pub commits: RwLock<usize>,
|
||||
pub rollbacks: RwLock<usize>,
|
||||
}
|
||||
|
||||
#[derive(Binary)]
|
||||
pub struct CustomData {
|
||||
pub a: usize,
|
||||
pub b: usize,
|
||||
}
|
||||
|
||||
impl FromRawBytes for CustomData {
|
||||
fn from_bytes(bytes: &[u8]) -> Result<CustomData, FromBytesError> {
|
||||
Ok(CustomData {
|
||||
a: bytes[0] as usize * 256 + bytes[1] as usize,
|
||||
b: bytes[2] as usize * 256 + bytes[3] as usize
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl BytesConvertable for CustomData {
|
||||
fn bytes(&self) -> &[u8] {
|
||||
let ip: *const CustomData = self;
|
||||
let ptr: *const u8 = ip as *const _;
|
||||
unsafe {
|
||||
::std::slice::from_raw_parts(
|
||||
ptr,
|
||||
::std::mem::size_of::<CustomData>()
|
||||
)
|
||||
}
|
||||
}
|
||||
pub a: u64,
|
||||
pub b: u64,
|
||||
}
|
||||
|
||||
#[derive(Ipc)]
|
||||
@@ -69,8 +49,8 @@ impl Service {
|
||||
let mut clock = self.commits.write().unwrap();
|
||||
let mut rlock = self.commits.write().unwrap();
|
||||
|
||||
*clock = data.a;
|
||||
*rlock = data.b;
|
||||
*clock = data.a as usize;
|
||||
*rlock = data.b as usize;
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user