#[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,
})
}
}