Jonathan Reem and Zach Pomerantz
github.com/reem, github.com/zzmp
strukt! {
name = Many,
fields = {
one: i32 => 3,
two: String => 4,
three: Vec<Operation> => 9,
}
}
enom! {
name = Operation,
values = [
Add = 1,
Sub = 2,
Clear = 3,
],
default = Sub
}
#[macro_export]
macro_rules! strukt {
(name = $name:ident,
fields = { $($fname:ident: $fty:ty => $id:expr,)+ }) => {
#[derive(Debug, Clone, Default)]
pub struct $name {
$(pub $fname: Option<$fty>,)+
}
impl $crate::protocol::ThriftTyped for $name {
fn typ() -> $crate::protocol::Type { $crate::protocol::Type::Struct }
}
impl $crate::protocol::Encode for $name {
fn encode<P, T>(&self, protocol: &mut P, transport: &mut T) -> $crate::Result<()>
where P: $crate::Protocol, T: $crate::Transport {
try!(protocol.write_struct_begin(transport, stringify!($name)));
$(if let Some(ref x) = self.$fname {
try!(protocol.write_field_begin(transport, stringify!($fname),
<$fty as ThriftTyped>::typ(),
$id));
try!(x.encode(protocol, transport));
try!(protocol.write_field_end(transport));
})*
try!(protocol.write_field_stop(transport));
try!(protocol.write_struct_end(transport));
Ok(())
}
}