1#[repr(u16)]
5#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
6pub enum ControlOpcode {
7 PrepareTransition = 0x0001,
9 ReadyForTransition = 0x0002,
11 ExecuteTransition = 0x0003,
13 AbortTransition = 0x0004,
15 GroupStateDigestRequest = 0x0005,
17 GroupStateDigestResponse = 0x0006,
19 ReportInvalidCommit = 0x0007,
21 CapabilitiesAdvertise = 0x0008,
23 Ack = 0x0009,
25 Nack = 0x000A,
27}
28
29impl ControlOpcode {
30 pub fn name(self) -> &'static str {
32 use ControlOpcode::*;
33 match self {
34 PrepareTransition => "PREPARE_TRANSITION",
35 ReadyForTransition => "READY_FOR_TRANSITION",
36 ExecuteTransition => "EXECUTE_TRANSITION",
37 AbortTransition => "ABORT_TRANSITION",
38 GroupStateDigestRequest => "GROUP_STATE_DIGEST_REQUEST",
39 GroupStateDigestResponse => "GROUP_STATE_DIGEST_RESPONSE",
40 ReportInvalidCommit => "REPORT_INVALID_COMMIT",
41 CapabilitiesAdvertise => "CAPABILITIES_ADVERTISE",
42 Ack => "ACK",
43 Nack => "NACK",
44 }
45 }
46}
47
48impl TryFrom<u16> for ControlOpcode {
49 type Error = u16;
50 fn try_from(v: u16) -> Result<Self, u16> {
51 use ControlOpcode::*;
52 Ok(match v {
53 0x0001 => PrepareTransition,
54 0x0002 => ReadyForTransition,
55 0x0003 => ExecuteTransition,
56 0x0004 => AbortTransition,
57 0x0005 => GroupStateDigestRequest,
58 0x0006 => GroupStateDigestResponse,
59 0x0007 => ReportInvalidCommit,
60 0x0008 => CapabilitiesAdvertise,
61 0x0009 => Ack,
62 0x000A => Nack,
63 other => return Err(other),
64 })
65 }
66}