moq_transfork/message/
stream.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::coding::*;

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Stream {
	Session,
	Announce,
	Subscribe,
	Fetch,
	Info,
}

impl Decode for Stream {
	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
		let t = u64::decode(r)?;
		match t {
			0 => Ok(Self::Session),
			1 => Ok(Self::Announce),
			2 => Ok(Self::Subscribe),
			3 => Ok(Self::Fetch),
			4 => Ok(Self::Info),
			_ => Err(DecodeError::InvalidValue),
		}
	}
}

impl Encode for Stream {
	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
		let v: u64 = match self {
			Self::Session => 0,
			Self::Announce => 1,
			Self::Subscribe => 2,
			Self::Fetch => 3,
			Self::Info => 4,
		};
		v.encode(w)
	}
}

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum StreamUni {
	Group,
}

impl Decode for StreamUni {
	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
		let t = u64::decode(r)?;
		match t {
			0 => Ok(Self::Group),
			_ => Err(DecodeError::InvalidValue),
		}
	}
}

impl Encode for StreamUni {
	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
		let v: u64 = match self {
			Self::Group => 0,
		};
		v.encode(w)
	}
}