1use crate::coding::{Decode, DecodeError, Encode, Extension};
2
3pub enum Role {
4 Publisher,
5 Subscriber,
6 Both,
7}
8
9impl Encode for Role {
10 fn encode<W: bytes::BufMut>(&self, w: &mut W) {
11 let v: u64 = match self {
12 Role::Publisher => 0x01,
13 Role::Subscriber => 0x02,
14 Role::Both => 0x03,
15 };
16 v.encode(w);
17 }
18}
19
20impl Decode for Role {
21 fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
22 let value = u64::decode(r)?;
23 Ok(match value {
24 0x01 => Role::Publisher,
25 0x02 => Role::Subscriber,
26 0x03 => Role::Both,
27 _ => return Err(DecodeError::InvalidValue),
28 })
29 }
30}
31
32impl Extension for Role {
33 fn id() -> u64 {
34 0x00
35 }
36}