Debian Codegraph @

tests/run-pass/packet_size.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
13 #[packet]
14 pub struct Key {
15 banana: u8,
16 #[length = "banana"]
17 #[payload]
18 payload: Vec<u8>,
19 }
20
21 #[packet]
22 pub struct AnotherKey {
23 banana: u8,
24 #[length = "banana + 7"]
25 #[payload]
26 payload: Vec<u8>,
27 }
28
29 #[packet]
30 pub struct NoLength {
31 banana: u8,
32 #[payload]
33 payload: Vec<u8>,
34 }
35
36 fn main() {
37 let key_payload = vec![1, 2, 3, 4];
38 let key = Key {
39 banana: key_payload.len() as u8,
40 payload: key_payload,
41 };
42 assert_eq!(KeyPacket::packet_size(&key), 5);
43
44 let another_key_payload = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
45 let another_key = AnotherKey {
46 banana: (another_key_payload.len() - 7) as u8,
47 payload: another_key_payload,
48 };
49 assert_eq!(AnotherKeyPacket::packet_size(&another_key), 11);
50
51 let no_length = NoLength {
52 banana: 123,
53 payload: vec![1, 2, 3, 4, 5, 6],
54 };
55 assert_eq!(NoLengthPacket::packet_size(&no_length), 7);
56 }