Trait pw_stream::WriteVarint
source · pub trait WriteVarint {
// Required methods
fn write_varint(&mut self, value: u64) -> Result<()>;
fn write_signed_varint(&mut self, value: i64) -> Result<()>;
}
Expand description
A trait for writing varint integers from a stream.
The API here is explicitly limited to u64
and i64
in order to reduce
code size.
§Example
use pw_stream::{Cursor, WriteVarint};
let mut cursor = Cursor::new(vec![0x0; 16]);
cursor.write_varint(0xffff_fffe).unwrap();
cursor.write_signed_varint(i32::MIN.into()).unwrap();
let buffer = cursor.into_inner();
assert_eq!(buffer,vec![
0xfe, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff,
0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
Required Methods§
sourcefn write_varint(&mut self, value: u64) -> Result<()>
fn write_varint(&mut self, value: u64) -> Result<()>
Write an unsigned varint to the stream.
Errors that may be returned are dependant on the underlying implementation.
sourcefn write_signed_varint(&mut self, value: i64) -> Result<()>
fn write_signed_varint(&mut self, value: i64) -> Result<()>
Write a signed varint to the stream.
Errors that may be returned are dependant on the underlying implementation.