moq_transport/message/
go_away.rs1use crate::coding::{Decode, DecodeError, Encode, EncodeError, SessionUri};
2
3#[derive(Clone, Debug, Eq, PartialEq)]
5pub struct GoAway {
6 pub uri: SessionUri,
7}
8
9impl Decode for GoAway {
10 fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
11 let uri = SessionUri::decode(r)?;
12 Ok(Self { uri })
13 }
14}
15
16impl Encode for GoAway {
17 fn encode<W: bytes::BufMut>(&self, w: &mut W) -> Result<(), EncodeError> {
18 self.uri.encode(w)
19 }
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25 use bytes::BytesMut;
26
27 #[test]
28 fn encode_decode() {
29 let mut buf = BytesMut::new();
30
31 let msg = GoAway {
32 uri: SessionUri("moq://example.com:1234".to_string()),
33 };
34 msg.encode(&mut buf).unwrap();
35 let decoded = GoAway::decode(&mut buf).unwrap();
36 assert_eq!(decoded, msg);
37 }
38}