Skip to content

Instantly share code, notes, and snippets.

@jld
Created January 20, 2013 09:30
Show Gist options
  • Save jld/4577482 to your computer and use it in GitHub Desktop.
Save jld/4577482 to your computer and use it in GitHub Desktop.
Fun With Macros
pub struct SetupRequest {
byte_order: u8,
protocol_major_version: u16,
protocol_minor_version: u16,
authorization_protocol_name: ~[u8],
authorization_protocol_data: ~[u8],
}
struct_io!{
SetupRequest;
copy byte_order;
.. 1;
copy protocol_major_version;
copy protocol_minor_version;
let authorization_protocol_name_len: u16 = self.authorization_protocol_name.len();
let authorization_protocol_data_len: u16 = self.authorization_protocol_data.len();
.. 2;
for (authorization_protocol_name_len as uint) copy authorization_protocol_name;
.. -(authorization_protocol_name_len as uint) & 3;
for (authorization_protocol_data_len as uint) copy authorization_protocol_data;
.. -(authorization_protocol_data_len as uint) & 3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment