moq_lite/message/
subscribe.rs

1use crate::{
2	coding::{Decode, DecodeError, Encode},
3	Path,
4};
5
6/// Sent by the subscriber to request all future objects for the given track.
7///
8/// Objects will use the provided ID instead of the full track name, to save bytes.
9#[derive(Clone, Debug)]
10pub struct Subscribe {
11	pub id: u64,
12	pub broadcast: Path,
13	pub track: String,
14	pub priority: u8,
15}
16
17impl Decode for Subscribe {
18	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
19		let id = u64::decode(r)?;
20		let broadcast = Path::decode(r)?;
21		let track = String::decode(r)?;
22		let priority = u8::decode(r)?;
23
24		Ok(Self {
25			id,
26			broadcast,
27			track,
28			priority,
29		})
30	}
31}
32
33impl Encode for Subscribe {
34	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
35		self.id.encode(w);
36		self.broadcast.encode(w);
37		self.track.encode(w);
38		self.priority.encode(w);
39	}
40}
41
42#[derive(Clone, Debug)]
43pub struct SubscribeOk {
44	pub priority: u8,
45}
46
47impl Encode for SubscribeOk {
48	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
49		self.priority.encode(w);
50	}
51}
52
53impl Decode for SubscribeOk {
54	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
55		let priority = u8::decode(r)?;
56		Ok(Self { priority })
57	}
58}