Created
October 4, 2018 07:22
-
-
Save nickik/02779fb877655317308324c7863a2b17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate serde_derive; | |
extern crate rmp_serde as rmps; | |
use std::collections::HashMap; | |
use serde::{Deserialize, Serialize}; | |
use rmps::{Deserializer, Serializer}; | |
type Entity = i64; | |
#[derive(Debug, PartialEq, Deserialize, Serialize)] | |
pub enum Direction { | |
Assert, | |
Retract | |
} | |
#[derive(Debug, PartialEq, Deserialize, Serialize)] | |
pub enum DatomValue { | |
i64(i64), | |
f64(f64), | |
entity(Entity), | |
string(String) | |
} | |
#[derive(Debug, PartialEq, Deserialize, Serialize)] | |
pub struct StorageDatum { | |
entity: Entity, | |
attribute: Entity, | |
direction: Direction, | |
tx: i64, | |
value: DatomValue | |
} | |
fn main() { | |
let mut buf = Vec::new(); | |
let val = StorageDatum { | |
entity: 1, | |
attribute: 2, | |
direction: Direction::Assert, | |
tx: 0, | |
value: DatomValue::entity(1) | |
}; | |
println!("{:?}", val); | |
val.serialize(&mut Serializer::new(&mut buf)).unwrap(); | |
let mut de = Deserializer::new(&buf[..]); | |
let val2 : StorageDatum = Deserialize::deserialize(&mut de).unwrap(); | |
println!("{:?}", val2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment