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