moq_transport/message/
subscribe_error.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
use crate::coding::{Decode, DecodeError, Encode, EncodeError};

/// Sent by the publisher to reject a Subscribe.
#[derive(Clone, Debug)]
pub struct SubscribeError {
	// The ID for this subscription.
	pub id: u64,

	// An error code.
	pub code: u64,

	// An optional, human-readable reason.
	pub reason: String,

	/// An optional track alias, only used when error == Retry Track Alias
	pub alias: u64,
}

impl Decode for SubscribeError {
	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
		let id = u64::decode(r)?;
		let code = u64::decode(r)?;
		let reason = String::decode(r)?;
		let alias = u64::decode(r)?;

		Ok(Self {
			id,
			code,
			reason,
			alias,
		})
	}
}

impl Encode for SubscribeError {
	fn encode<W: bytes::BufMut>(&self, w: &mut W) -> Result<(), EncodeError> {
		self.id.encode(w)?;
		self.code.encode(w)?;
		self.reason.encode(w)?;
		self.alias.encode(w)?;

		Ok(())
	}
}