[−][src]Function msb128::write_positive
pub fn write_positive<W, I>(writer: W, input: I) -> Result<usize, WriteError> where
W: Write,
I: PrimInt,
Write val
to the std::io::Write
stream w
as an MSB128-encoded
integer.
Errors
Only positive integers are supported. A negative input causes the
function to return with a WriteError::Negative
.
Returns
After a successful write, the number of bytes written to w
is returned.
Examples
Writing a u8 and an i128 into three bytes.
use msb128::{write_positive, read_positive}; let mut buffer = [0u8; 3]; let mut writeable = &mut buffer[..]; let bytes_written = write_positive(&mut writeable, 127u8)?; assert_eq!(bytes_written, 1); let bytes_written = write_positive(&mut writeable, 256i128)?; assert_eq!(bytes_written, 2); let mut readable = &buffer[..]; assert_eq!(127u8, read_positive(&mut readable)?); assert_eq!(256u16, read_positive(&mut readable)?); }