| 1 | // Copyright (c) 2015 Robert Clipsham <[email protected]> |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 6 | // option. This file may not be copied, modified, or distributed |
| 7 | // except according to those terms. |
| 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 WithVariableLengthField { |
| 16 | banana: u32be, |
| 17 | #[length = "3"] |
| 18 | var_length: Vec<u8>, |
| 19 | #[payload] |
| 20 | payload: Vec<u8>, |
| 21 | } |
| 22 | |
| 23 | fn main() { |
| 24 | let data = [1, 1, 1, 1, 2, 3, 4, 5, 6]; |
| 25 | let packet = WithVariableLengthFieldPacket::new(&data[..]).unwrap(); |
| 26 | assert_eq!(packet.get_var_length(), vec![2, 3, 4]); |
| 27 | } |