1use crate::PacketGenerator;
6
7pub struct Sync {
9 pub length: usize,
11}
12
13impl Default for Sync {
14 fn default() -> Self {
15 Self { length: 300 }
16 }
17}
18
19impl PacketGenerator for Sync {
20 fn packets(&self) -> Vec<Vec<u8>> {
21 const PING_BYTE: u8 = 0x78;
23 const SYNC_1_BYTE: u8 = 0x55;
24 const SYNC_2_BYTE: u8 = 0xaa;
25 const SYNC_2_LENGTH: usize = 40;
26
27 let mut packet = Vec::with_capacity(1 + self.length + SYNC_2_LENGTH);
29
30 packet.push(PING_BYTE);
32
33 packet.extend(vec![SYNC_1_BYTE; self.length]);
35
36 packet.extend(vec![SYNC_2_BYTE; SYNC_2_LENGTH]);
38
39 vec![packet]
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_sync() {
49 let sync = Sync::default();
50
51 #[rustfmt::skip]
53 let expected = vec![vec![120,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170]];
54
55 assert_eq!(sync.packets(), expected);
56 }
57}