Enum rtsp_types::Message

source ·
pub enum Message<Body> {
    Request(Request<Body>),
    Response(Response<Body>),
    Data(Data<Body>),
}
Expand description

Enum holding all possible RTSP message types.

A Message can be a Request, a Response or Data.

The body of the message is generic and usually a type that implements AsRef<[u8]>. For empty bodies there also exists the Empty type.

Variants§

§

Request(Request<Body>)

Request message

§

Response(Response<Body>)

Response message

§

Data(Data<Body>)

Data message

Implementations§

source§

impl<Body: AsRef<[u8]>> Message<Body>

source

pub fn write<'b, W: Write + 'b>(&self, w: &'b mut W) -> Result<(), WriteError>

Serialize the message to any std::io::Write.

Resuming writing after std::io::ErrorKind::WouldBlock is not supported. Any previously written data will have to be discarded for resuming.

§Serializing an RTSP message
let request = rtsp_types::Request::builder(
        rtsp_types::Method::SetParameter,
        rtsp_types::Version::V2_0
    )
    .request_uri(rtsp_types::Url::parse("rtsp://example.com/test").expect("Invalid URI"))
    .header(rtsp_types::headers::CSEQ, "2")
    .header(rtsp_types::headers::CONTENT_TYPE, "text/parameters")
    .build(Vec::from(&b"barparam: barstuff"[..]));

 let mut data = Vec::new();
 request.write(&mut data).expect("Failed to serialize request");

 assert_eq!(
    data,
    b"SET_PARAMETER rtsp://example.com/test RTSP/2.0\r\n\
      Content-Length: 18\r\n\
      Content-Type: text/parameters\r\n\
      CSeq: 2\r\n\
      \r\n\
      barparam: barstuff",
 );
source

pub fn write_len(&self) -> u64

Calculate the number of bytes needed to serialize the message.

source§

impl<'a, T: From<&'a [u8]>> Message<T>

source

pub fn parse<B: AsRef<[u8]> + 'a + ?Sized>( buf: &'a B, ) -> Result<(Self, usize), ParseError>

Try parse a message from a &[u8] and also return how many bytes were consumed.

The body type of the returned message can be any type that implements From<&[u8]>. This includes Vec<u8> and &[u8] among others.

If parsing the message succeeds, in addition to the message itself also the number of bytes that were consumed from the input data are returned. This allows the caller to advance to the next message.

If parsing the message fails with ParseError::Incomplete then the caller has to provide more data for successfully parsing the message.

Otherwise, if parsing the message fails with ParseError::Error then the message can’t be parsed and the caller can try skipping over some data until parsing succeeds again.

§Parsing an RTSP message
let data = b"OPTIONS * RTSP/2.0\r\n\
             CSeq: 1\r\n\
             Supported: play.basic, play.scale\r\n\
             User-Agent: PhonyClient/1.2\r\n\
             \r\n";

let (message, consumed): (rtsp_types::Message<Vec<u8>>, _) =
    rtsp_types::Message::parse(data).expect("Failed to parse data");

assert_eq!(consumed, data.len());
match message {
    rtsp_types::Message::Request(ref request) => {
        assert_eq!(request.method(), rtsp_types::Method::Options);
    },
    _ => unreachable!(),
}

Trait Implementations§

source§

impl<Body: Clone> Clone for Message<Body>

source§

fn clone(&self) -> Message<Body>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Body: Debug> Debug for Message<Body>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Body> From<Data<Body>> for Message<Body>

source§

fn from(v: Data<Body>) -> Self

Converts to this type from the input type.
source§

impl<Body> From<Request<Body>> for Message<Body>

source§

fn from(v: Request<Body>) -> Self

Converts to this type from the input type.
source§

impl<Body> From<Response<Body>> for Message<Body>

source§

fn from(v: Response<Body>) -> Self

Converts to this type from the input type.
source§

impl<Body: PartialEq> PartialEq for Message<Body>

source§

fn eq(&self, other: &Message<Body>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Body: Eq> Eq for Message<Body>

source§

impl<Body> StructuralPartialEq for Message<Body>

Auto Trait Implementations§

§

impl<Body> Freeze for Message<Body>
where Body: Freeze,

§

impl<Body> RefUnwindSafe for Message<Body>
where Body: RefUnwindSafe,

§

impl<Body> Send for Message<Body>
where Body: Send,

§

impl<Body> Sync for Message<Body>
where Body: Sync,

§

impl<Body> Unpin for Message<Body>
where Body: Unpin,

§

impl<Body> UnwindSafe for Message<Body>
where Body: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T