Last active
August 29, 2015 14:04
-
-
Save Noxivs/7a5896b008495fa0dd3d 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
pub struct HelloConnectMessage { | |
salt: String, | |
key: Vec<u8> | |
} | |
impl HelloConnectMessage { | |
pub fn salt<'a>(&self) -> &'a String { | |
&self.salt | |
} | |
pub fn key<'a>(&self) -> &'a Vec<u8> { | |
&self.key | |
} | |
} | |
impl Serializable for HelloConnectMessage { | |
fn serialize(&self, _: &mut MemWriter) { | |
//serialize | |
} | |
} | |
#[msg_deserializer="3"] | |
pub fn deserialize_hello_connect(_: &mut MemReader, _: TypeFinder) -> Message { | |
// deserialize | |
let salt = String::new(); | |
let key = Vec::new(); | |
HelloConnect(HelloConnectMessage { | |
salt: salt, | |
key: key | |
}) | |
} |
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
pub enum Message { | |
HelloConnect(HelloConnectMessage) | |
// ... | |
} |
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
fn main() { | |
let reader = ... | |
let id_msg = 3; | |
let b = MessageBuilder::new(); | |
let message = b.parse(id_msg, reader); | |
match message { | |
HelloConnect(m) => println!("salt : {}", m.salt().as_slice()), | |
_ => println!("unknown message") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment