moq_lite/message/
subscribe.rs

1use crate::{
2	coding::{Decode, DecodeError, Encode, Message},
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 Message 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	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
33		self.id.encode(w);
34		self.broadcast.encode(w);
35		self.track.encode(w);
36		self.priority.encode(w);
37	}
38}
39
40#[derive(Clone, Debug)]
41pub struct SubscribeOk {
42	pub priority: u8,
43}
44
45impl Message for SubscribeOk {
46	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
47		self.priority.encode(w);
48	}
49
50	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
51		let priority = u8::decode(r)?;
52		Ok(Self { priority })
53	}
54}