mapping and custom serializers
This commit is contained in:
@@ -15,7 +15,7 @@ ethcore-devtools = { path = "../../devtools" }
|
||||
semver = "0.2.0"
|
||||
nanomsg = "0.5.0"
|
||||
ethcore-ipc-nano = { path = "../nano" }
|
||||
|
||||
ethcore-util = { path = "../../util" }
|
||||
|
||||
[build-dependencies]
|
||||
syntex = "*"
|
||||
|
||||
@@ -21,6 +21,7 @@ extern crate ethcore_devtools as devtools;
|
||||
extern crate semver;
|
||||
extern crate nanomsg;
|
||||
extern crate ethcore_ipc_nano as nanoipc;
|
||||
extern crate ethcore_util as util;
|
||||
|
||||
pub mod service;
|
||||
mod examples;
|
||||
|
||||
@@ -16,13 +16,32 @@
|
||||
|
||||
use std::sync::RwLock;
|
||||
use std::ops::*;
|
||||
use std::convert::*;
|
||||
use ipc::IpcConfig;
|
||||
use util::bytes::{FromRawBytes, BytesConvertable, FromBytesError};
|
||||
|
||||
pub struct Service {
|
||||
pub commits: RwLock<usize>,
|
||||
pub rollbacks: RwLock<usize>,
|
||||
}
|
||||
|
||||
pub struct CustomData {
|
||||
a: usize,
|
||||
b: usize,
|
||||
}
|
||||
|
||||
impl FromRawBytes for CustomData {
|
||||
fn from_bytes(bytes: &[u8]) -> Result<CustomData, FromBytesError> {
|
||||
Ok(CustomData { a: bytes[0] * 256 + bytes[1], b: bytes[2] * 256 + bytes[3]})
|
||||
}
|
||||
}
|
||||
|
||||
impl BytesConvertable for CustomData {
|
||||
fn bytes(&self) -> &[u8] {
|
||||
unsafe { &::std::mem::transmute::<[u8;8]>(self) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Ipc)]
|
||||
impl Service {
|
||||
fn commit(&self, f: u32) -> u32 {
|
||||
@@ -36,6 +55,15 @@ impl Service {
|
||||
*lock = *lock + a_0 as usize - b as usize;
|
||||
(a_0 - b) as i32
|
||||
}
|
||||
pub fn push_custom(&self, data: CustomData) -> bool {
|
||||
let clock = self.commits.write().unwrap();
|
||||
let rlock = self.commits.write().unwrap();
|
||||
|
||||
*clock = data.a;
|
||||
*rlock = data.b;
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Service {
|
||||
|
||||
Reference in New Issue
Block a user