Debian Codegraph @

tests/run-pass/variable_length_fields.rs

raw symbols SCIP
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 PacketWithPayload {
16 banana: u8,
17 #[length_fn = "length_fn"]
18 var_length: Vec<u8>,
19 #[payload]
20 payload: Vec<u8>,
21 }
22
23 #[packet]
24 pub struct PacketWithU16 {
25 length: u8,
26 #[length = "length"]
27 data: Vec<u16be>,
28 #[payload]
29 payload: Vec<u8>,
30 }
31
32 fn length_fn(_: &PacketWithPayloadPacket) -> usize {
33 unimplemented!()
34 }
35
36 fn main() {
37
38 // Test if we can add data to the u16be
39 let mut packet = [0u8; 7];
40 {
41 let mut p = MutablePacketWithU16Packet::new(&mut packet[..]).unwrap();
42 p.set_length(6);
43 p.set_data(&vec![0x0001, 0x1223, 0x3ff4]);
44 }
45
46 let ref_packet = [0x06 /* length */, 0x00, 0x01, 0x12, 0x23, 0x3f, 0xf4];
47
48 assert_eq!(&ref_packet[..], &packet[..]);
49
50 }