moq_lite/message/
stream.rs1use crate::coding::*;
2
3#[derive(Debug, PartialEq, Clone, Copy)]
4pub enum ControlType {
5 Session,
6 Announce,
7 Subscribe,
8
9 ClientCompat,
11 ServerCompat,
12}
13
14impl Decode for ControlType {
15 fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
16 let t = u64::decode(r)?;
17 match t {
18 0 => Ok(Self::Session),
19 1 => Ok(Self::Announce),
20 2 => Ok(Self::Subscribe),
21 0x40 => Ok(Self::ClientCompat),
22 0x41 => Ok(Self::ServerCompat),
23 _ => Err(DecodeError::InvalidMessage(t)),
24 }
25 }
26}
27
28impl Encode for ControlType {
29 fn encode<W: bytes::BufMut>(&self, w: &mut W) {
30 let v: u64 = match self {
31 Self::Session => 0,
32 Self::Announce => 1,
33 Self::Subscribe => 2,
34 Self::ClientCompat => 0x40,
35 Self::ServerCompat => 0x41,
36 };
37 v.encode(w)
38 }
39}
40
41#[derive(Debug, PartialEq, Clone, Copy)]
42pub enum DataType {
43 Group,
44}
45
46impl Decode for DataType {
47 fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
48 let t = u64::decode(r)?;
49 match t {
50 0 => Ok(Self::Group),
51 _ => Err(DecodeError::InvalidMessage(t)),
52 }
53 }
54}
55
56impl Encode for DataType {
57 fn encode<W: bytes::BufMut>(&self, w: &mut W) {
58 let v: u64 = match self {
59 Self::Group => 0,
60 };
61 v.encode(w)
62 }
63}