| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
extern crate pnet_macros; |
| 10 |
extern crate pnet_macros_support; |
| 11 |
use pnet_macros::packet; |
| 12 |
use pnet_macros_support::types::*; |
| 13 |
|
| 14 |
#[packet] |
| 15 |
pub struct Test { |
| 16 |
banana: u2, |
| 17 |
apple: u4, |
| 18 |
potato: u6, |
| 19 |
the_rest: u20be, |
| 20 |
#[payload] |
| 21 |
payload: Vec<u8>, |
| 22 |
} |
| 23 |
|
| 24 |
fn main() { |
| 25 |
let test = Test { |
| 26 |
banana: 0b10, |
| 27 |
apple: 0b1010, |
| 28 |
potato: 0b101010, |
| 29 |
the_rest: 0b10101010101010101010, |
| 30 |
payload: vec![], |
| 31 |
}; |
| 32 |
|
| 33 |
let mut buf = vec![0; TestPacket::packet_size(&test)]; |
| 34 |
let mut packet = MutableTestPacket::new(&mut buf).unwrap(); |
| 35 |
packet.populate(&test); |
| 36 |
assert_eq!(packet.get_banana(), test.banana); |
| 37 |
assert_eq!(packet.get_apple(), test.apple); |
| 38 |
assert_eq!(packet.get_potato(), test.potato); |
| 39 |
assert_eq!(packet.get_the_rest(), test.the_rest); |
| 40 |
} |