moq_lite/message/
subscribe.rs

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