Function git_packetline::encode::text_to_write
source · Available on crate feature
blocking-io
only.Expand description
Write a text
message to out
, which is assured to end in a newline.
Examples found in repository?
More examples
src/write/blocking_io.rs (line 59)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn write(&mut self, mut buf: &[u8]) -> io::Result<usize> {
if buf.is_empty() {
return Err(io::Error::new(
io::ErrorKind::Other,
"empty packet lines are not permitted as '0004' is invalid",
));
}
let mut written = 0;
while !buf.is_empty() {
let (data, rest) = buf.split_at(buf.len().min(MAX_DATA_LEN));
written += if self.binary {
crate::encode::data_to_write(data, &mut self.inner)
} else {
crate::encode::text_to_write(data, &mut self.inner)
}?;
// subtract header (and trailng NL) because write-all can't handle writing more than it passes in
written -= U16_HEX_BYTES + usize::from(!self.binary);
buf = rest;
}
Ok(written)
}