Skip to content

Instantly share code, notes, and snippets.

@Noxivs
Last active August 29, 2015 14:04
Show Gist options
  • Save Noxivs/7a5896b008495fa0dd3d to your computer and use it in GitHub Desktop.
Save Noxivs/7a5896b008495fa0dd3d to your computer and use it in GitHub Desktop.
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
})
}
pub enum Message {
HelloConnect(HelloConnectMessage)
// ...
}
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