usecrate::frame::{util, Error, Frame, Head, Kind, StreamId}; use bytes::{Buf, BufMut, Bytes};
use std::fmt;
/// Data frame /// /// Data frames convey arbitrary, variable-length sequences of octets associated /// with a stream. One or more DATA frames are used, for instance, to carry HTTP /// request or response payloads. #[derive(Eq, PartialEq)] pubstruct Data<T = Bytes> {
stream_id: StreamId,
data: T,
flags: DataFlags,
pad_len: Option<u8>,
}
/// Returns the stream identifier that this frame is associated with. /// /// This cannot be a zero stream identifier. pubfn stream_id(&self) -> StreamId { self.stream_id
}
/// Gets the value of the `END_STREAM` flag for this frame. /// /// If true, this frame is the last that the endpoint will send for the /// identified stream. /// /// Setting this flag causes the stream to enter one of the "half-closed" /// states or the "closed" state (Section 5.1). pubfn is_end_stream(&self) -> bool { self.flags.is_end_stream()
}
/// Sets the value for the `END_STREAM` flag on this frame. pubfn set_end_stream(&mutself, val: bool) { if val { self.flags.set_end_stream();
} else { self.flags.unset_end_stream();
}
}
/// Returns whether the `PADDED` flag is set on this frame. #[cfg(feature = "unstable")] pubfn is_padded(&self) -> bool { self.flags.is_padded()
}
/// Sets the value for the `PADDED` flag on this frame. #[cfg(feature = "unstable")] pubfn set_padded(&mutself) { self.flags.set_padded();
}
/// Returns a reference to this frame's payload. /// /// This does **not** include any padding that might have been originally /// included. pubfn payload(&self) -> &T {
&self.data
}
/// Returns a mutable reference to this frame's payload. /// /// This does **not** include any padding that might have been originally /// included. pubfn payload_mut(&mutself) -> &mut T {
&mutself.data
}
/// Consumes `self` and returns the frame's payload. /// /// This does **not** include any padding that might have been originally /// included. pubfn into_payload(self) -> T { self.data
}
pub(crate) fn head(&self) -> Head {
Head::new(Kind::Data, self.flags.into(), self.stream_id)
}
pub(crate) fn map<F, U>(self, f: F) -> Data<U> where
F: FnOnce(T) -> U,
{
Data {
stream_id: self.stream_id,
data: f(self.data),
flags: self.flags,
pad_len: self.pad_len,
}
}
}
impl<T: Buf> Data<T> { /// Encode the data frame into the `dst` buffer. /// /// # Panics /// /// Panics if `dst` cannot contain the data frame. pub(crate) fn encode_chunk<U: BufMut>(&mutself, dst: &mut U) { let len = self.data.remaining();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.