Created
January 20, 2013 09:30
-
-
Save jld/4577482 to your computer and use it in GitHub Desktop.
Fun With Macros
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 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