Debian Codegraph @

tests/run-pass/weird_field_pos.rs

raw symbols SCIP
1 // Copyright (c) 2022 Yureka <[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 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 }