toe_beans/v4/message/op.rs
1/// Variants of an op field in [Message](crate::v4::Message).
2#[derive(Debug, PartialEq)]
3#[repr(u8)]
4pub enum Ops {
5 /// 1. Client sending a request to the server
6 Request,
7 /// 2. Server sending a reply to the client
8 Reply,
9 /// Not implemented
10 Other(u8),
11}
12
13// Encode
14impl From<&Ops> for u8 {
15 fn from(op: &Ops) -> Self {
16 match op {
17 Ops::Request => 1,
18 Ops::Reply => 2,
19 Ops::Other(x) => *x,
20 }
21 }
22}
23
24// Decode
25impl From<&[u8]> for Ops {
26 fn from(bytes: &[u8]) -> Self {
27 let byte = bytes[0];
28 match byte {
29 1 => Self::Request,
30 2 => Self::Reply,
31 _ => Self::Other(byte),
32 }
33 }
34}