vintage/record/
protocol_status.rs1use crate::error::Error;
2use std::io::{self, Write};
3
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub enum ProtocolStatus {
7 RequestComplete,
8 MultiplexingUnsupported,
9 Overloaded,
10 UnknownRole,
11}
12
13impl ProtocolStatus {
14 pub fn id(&self) -> u8 {
15 match self {
16 Self::RequestComplete => 0,
17 Self::MultiplexingUnsupported => 1,
18 Self::Overloaded => 2,
19 Self::UnknownRole => 3,
20 }
21 }
22
23 pub fn from_record_byte(byte: u8) -> Result<Self, Error> {
24 let status = match byte {
25 0 => Self::RequestComplete,
26 1 => Self::MultiplexingUnsupported,
27 2 => Self::Overloaded,
28 3 => Self::UnknownRole,
29 _ => return Err(Error::UnspportedProtocolStatus(byte)),
30 };
31
32 Ok(status)
33 }
34
35 pub fn as_record_byte<W: Write>(&self, writer: &mut W) -> Result<(), io::Error> {
36 let id = self.id();
37 writer.write_all(&[id])
38 }
39}