moq_lite/ietf/
message.rs

1use crate::coding::{Decode, DecodeError, Encode};
2
3pub enum MessageId {
4	SubscribeUpdate,
5	Subscribe,
6	SubscribeOk,
7	SubscribeError,
8	Announce,
9	AnnounceOk,
10	AnnounceError,
11	Unannounce,
12	Unsubscribe,
13	SubscribeDone,
14	AnnounceCancel,
15	TrackStatusRequest,
16	TrackStatus,
17	GoAway,
18	SubscribeAnnounces,
19	SubscribeAnnouncesOk,
20	SubscribeAnnouncesError,
21	UnsubscribeAnnounces,
22	MaxSubscribeId,
23	Fetch,
24	FetchCancel,
25	FetchOk,
26	FetchError,
27	ClientSetup,
28	ServerSetup,
29}
30
31/*
320x2	SUBSCRIBE_UPDATE (Section 6.5)
330x3	SUBSCRIBE (Section 6.4)
340x4	SUBSCRIBE_OK (Section 6.15)
350x5	SUBSCRIBE_ERROR (Section 6.16)
360x6	ANNOUNCE (Section 6.21)
370x7	ANNOUNCE_OK (Section 6.9)
380x8	ANNOUNCE_ERROR (Section 6.10)
390x9	UNANNOUNCE (Section 6.22)
400xA	UNSUBSCRIBE (Section 6.6)
410xB	SUBSCRIBE_DONE (Section 6.19)
420xC	ANNOUNCE_CANCEL (Section 6.11)
430xD	TRACK_STATUS_REQUEST (Section 6.12)
440xE	TRACK_STATUS (Section 6.23)
450x10	GOAWAY (Section 6.3)
460x11	SUBSCRIBE_ANNOUNCES (Section 6.13)
470x12	SUBSCRIBE_ANNOUNCES_OK (Section 6.24)
480x13	SUBSCRIBE_ANNOUNCES_ERROR (Section 6.25
490x14	UNSUBSCRIBE_ANNOUNCES (Section 6.14)
500x15	MAX_SUBSCRIBE_ID (Section 6.20)
510x16	FETCH (Section 6.7)
520x17	FETCH_CANCEL (Section 6.8)
530x18	FETCH_OK (Section 6.17)
540x19	FETCH_ERROR (Section 6.18)
550x40	CLIENT_SETUP (Section 6.2)
560x41	SERVER_SETUP (Section 6.2)
57*/
58
59impl Encode for MessageId {
60	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
61		let id: u64 = match self {
62			Self::SubscribeUpdate => 0x02,
63			Self::Subscribe => 0x03,
64			Self::SubscribeOk => 0x04,
65			Self::SubscribeError => 0x05,
66			Self::Announce => 0x06,
67			Self::AnnounceOk => 0x07,
68			Self::AnnounceError => 0x08,
69			Self::Unannounce => 0x09,
70			Self::Unsubscribe => 0x0A,
71			Self::SubscribeDone => 0x0B,
72			Self::AnnounceCancel => 0x0C,
73			Self::TrackStatusRequest => 0x0D,
74			Self::TrackStatus => 0x0E,
75			Self::GoAway => 0x10,
76			Self::SubscribeAnnounces => 0x11,
77			Self::SubscribeAnnouncesOk => 0x12,
78			Self::SubscribeAnnouncesError => 0x13,
79			Self::UnsubscribeAnnounces => 0x14,
80			Self::MaxSubscribeId => 0x15,
81			Self::Fetch => 0x16,
82			Self::FetchCancel => 0x17,
83			Self::FetchOk => 0x18,
84			Self::FetchError => 0x19,
85			Self::ClientSetup => 0x40,
86			Self::ServerSetup => 0x41,
87		};
88		id.encode(w)
89	}
90}
91
92impl Decode for MessageId {
93	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
94		let id = u64::decode(r)?;
95		Ok(match id {
96			0x02 => Self::SubscribeUpdate,
97			0x03 => Self::Subscribe,
98			0x04 => Self::SubscribeOk,
99			0x05 => Self::SubscribeError,
100			0x06 => Self::Announce,
101			0x07 => Self::AnnounceOk,
102			0x08 => Self::AnnounceError,
103			0x09 => Self::Unannounce,
104			0x0A => Self::Unsubscribe,
105			0x0B => Self::SubscribeDone,
106			0x0C => Self::AnnounceCancel,
107			0x0D => Self::TrackStatusRequest,
108			0x0E => Self::TrackStatus,
109			0x10 => Self::GoAway,
110			0x11 => Self::SubscribeAnnounces,
111			0x12 => Self::SubscribeAnnouncesOk,
112			0x13 => Self::SubscribeAnnouncesError,
113			0x14 => Self::UnsubscribeAnnounces,
114			0x15 => Self::MaxSubscribeId,
115			0x16 => Self::Fetch,
116			0x17 => Self::FetchCancel,
117			0x18 => Self::FetchOk,
118			0x19 => Self::FetchError,
119			0x40 => Self::ClientSetup,
120			0x41 => Self::ServerSetup,
121			_ => return Err(DecodeError::InvalidValue),
122		})
123	}
124}