1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#[derive(Debug, Clone, PartialEq)]
pub struct DataFrame {
pub finished: bool,
pub reserved: [bool; 3],
pub opcode: Opcode,
pub data: Vec<u8>,
}
impl DataFrame {
pub fn new(finished: bool, opcode: Opcode, data: Vec<u8>) -> DataFrame {
DataFrame {
finished: finished,
reserved: [false; 3],
opcode: opcode,
data: data,
}
}
}
#[derive(Clone, Debug, Copy, PartialEq)]
pub enum Opcode {
Continuation,
Text,
Binary,
NonControl1,
NonControl2,
NonControl3,
NonControl4,
NonControl5,
Close,
Ping,
Pong,
Control1,
Control2,
Control3,
Control4,
Control5,
}
impl Opcode {
pub fn new(op: u8) -> Option<Opcode> {
Some(match op {
0 => Opcode::Continuation,
1 => Opcode::Text,
2 => Opcode::Binary,
3 => Opcode::NonControl1,
4 => Opcode::NonControl2,
5 => Opcode::NonControl3,
6 => Opcode::NonControl4,
7 => Opcode::NonControl5,
8 => Opcode::Close,
9 => Opcode::Ping,
10 => Opcode::Pong,
11 => Opcode::Control1,
12 => Opcode::Control2,
13 => Opcode::Control3,
14 => Opcode::Control4,
15 => Opcode::Control5,
_ => return None,
})
}
}