pub fn write_all_counted<W: Write + ?Sized>(
writer: &mut W,
buffer: &[u8],
codec: CodecKind,
bytes_processed: usize,
) -> Result<(), CodecError>Expand description
Writes all of buffer to writer and tracks progress for codec errors.
codec identifies the codec performing the write. bytes_processed is the
number of bytes that codec processed before this buffer; bytes written from
buffer are added to that base when an error is reported.
Operations interrupted with io::ErrorKind::Interrupted are retried. A
successful write of zero bytes while data remains is reported as an
io::ErrorKind::WriteZero source error.
§Example
use mcproto_codec::{
error::CodecKind,
io::write_all_counted,
};
let mut output = Vec::new();
write_all_counted(&mut output, &[0x12, 0x34], CodecKind::Short, 0)?;
assert_eq!(output, [0x12, 0x34]);
§Errors
Returns a CodecError if the writer cannot accept the complete buffer.