moq_transfork/message/
info.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
use std::time;

use super::GroupOrder;
use crate::coding::*;
use crate::Path;

#[derive(Clone, Debug)]
pub struct Info {
	pub track_priority: i8,
	pub group_order: GroupOrder,
	pub group_expires: time::Duration,
	pub group_latest: u64,
}

impl Encode for Info {
	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
		self.track_priority.encode(w);
		self.group_order.encode(w);
		self.group_expires.encode(w);
		self.group_latest.encode(w);
	}
}

impl Decode for Info {
	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
		let track_priority = i8::decode_more(r, 3)?;
		let group_order = GroupOrder::decode_more(r, 2)?;
		let group_expires = time::Duration::decode_more(r, 1)?;
		let group_latest = u64::decode(r)?;

		Ok(Self {
			track_priority,
			group_order,
			group_expires,
			group_latest,
		})
	}
}

#[derive(Clone, Debug)]
pub struct InfoRequest {
	pub path: Path,
}

impl Encode for InfoRequest {
	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
		self.path.encode(w);
	}
}

impl Decode for InfoRequest {
	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
		let path = Path::decode(r)?;
		Ok(Self { path })
	}
}