moq_lite/message/
stream.rs

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