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
31impl 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}