Skip to main content

moq_transport/message/
go_away.rs

1use crate::coding::{Decode, DecodeError, Encode, EncodeError, SessionUri};
2
3/// Sent by the server to indicate that the client should connect to a different server.
4#[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}