pub struct DataUnescaper { /* private fields */ }Expand description
Helper struct to unescape a data stream.
Note that one unescaper should be used for a single data stream. Creating a
DataUnescaper is basically free, and not creating a new one would probably
lead to initial \r\n being handled incorrectly.
Implementations§
Source§impl DataUnescaper
impl DataUnescaper
Sourcepub fn new(is_preceded_by_crlf: bool) -> DataUnescaper
pub fn new(is_preceded_by_crlf: bool) -> DataUnescaper
Creates a DataUnescaper.
The is_preceded_by_crlf argument is used to indicate whether, before
the first buffer that is fed into unescape, the unescaper should
assume that a \r\n was present.
Usually, one will want to set true as an argument, as starting a
DataUnescaper mid-line is a rare use case.
Sourcepub fn unescape(&mut self, data: &mut [u8]) -> DataUnescapeRes
pub fn unescape(&mut self, data: &mut [u8]) -> DataUnescapeRes
Unescapes data coming from an EscapedDataReader.
This takes a data argument. It will modify the data argument,
removing the escaping that could happen with it, and then returns a
DataUnescapeRes.
It is possible that the end of data does not land on a boundary that
allows yet to know whether data should be output or not. This is the
reason why this returns a DataUnescapeRes. The
returned value will contain:
.written, which is the number of unescaped bytes that have been written indata— that is,data[..res.written]is the unescaped data, and.unhandled_idx, which is the number of bytes at the end ofdatathat could not be handled yet for lack of more information — that is,data[res.unhandled_idx..]is data that should be at the beginning of the next call todata_unescape.
Note that the unhandled data’s length is never going to be longer than 4 bytes long (“\r\n.\r”, the longest sequence that can’t be interpreted yet), so it should not be an issue to just copy it to the next buffer’s start.