pub struct GraalWriter<W: Write> { /* private fields */ }
Expand description
A writer that writes Graal-encoded data.
Implementations§
Source§impl<W: Write> GraalWriter<W>
impl<W: Write> GraalWriter<W>
Sourcepub fn encode_bits(value: u64, buffer: &mut Vec<u8>, byte_count: usize)
pub fn encode_bits(value: u64, buffer: &mut Vec<u8>, byte_count: usize)
Encodes a value as a sequence of bytes using the Graal encoding.
§Arguments
value
: The value to encode.buffer
: The buffer to write the encoded bytes to.byte_count
: The number of bytes to encode.
§Returns
- The encoded bytes.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut buffer = vec![0, 0, 0, 0];
GraalWriter::<Cursor<Vec<u8>>>::encode_bits(1, &mut buffer, 4);
assert_eq!(buffer, vec![32, 32, 32, 33]);
Sourcepub fn write(&mut self, vec: &[u8]) -> Result<(), GraalIoError>
pub fn write(&mut self, vec: &[u8]) -> Result<(), GraalIoError>
Writes the given bytes to the writer.
§Arguments
vec
: The bytes to write.
§Errors
GraalIoError::Io
: If there is an I/O error.
§Examples
use std::io::Cursor;
use gbf_core::graal_io::GraalWriter;
let mut buffer = Cursor::new(Vec::new());
let mut writer = GraalWriter::new(buffer);
writer.write(&[1, 2, 3, 4]).unwrap();
Sourcepub fn write_string(&mut self, s: &str) -> Result<(), GraalIoError>
pub fn write_string(&mut self, s: &str) -> Result<(), GraalIoError>
Sourcepub fn write_gstring(&mut self, s: &str) -> Result<(), GraalIoError>
pub fn write_gstring(&mut self, s: &str) -> Result<(), GraalIoError>
Writes a Graal-encoded string.
§Arguments
s
: The string to write.
§Errors
GraalIoError::ValueExceedsMaximum
: If the string is too long to be represented by a Graal encoded 8 bit integer.GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_gstring("hello").unwrap();
Sourcepub fn write_u8(&mut self, c: u8) -> Result<(), GraalIoError>
pub fn write_u8(&mut self, c: u8) -> Result<(), GraalIoError>
Writes an unsigned 8-bit integer to the writer.
§Arguments
c
: The unsigned char to write.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_u8(1);
writer.write_u8(2);
writer.write_u8(3);
writer.write_u8(4);
Sourcepub fn write_u32(&mut self, i: u32) -> Result<(), GraalIoError>
pub fn write_u32(&mut self, i: u32) -> Result<(), GraalIoError>
Write an unsigned 32-bit integer to the writer.
§Arguments
i
: The unsigned int to write.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_u32(1).unwrap();
Sourcepub fn write_gu8(&mut self, v: u64) -> Result<(), GraalIoError>
pub fn write_gu8(&mut self, v: u64) -> Result<(), GraalIoError>
Writes an encoded Graal unsigned 8-bit integer.
§Arguments
v
: The value to write.
§Errors
GraalIoError::ValueExceedsMaximum
: If the value exceeds the maximum for a Graal-encoded integer.GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_gu8(1).unwrap();
Sourcepub fn write_gu16(&mut self, v: u64) -> Result<(), GraalIoError>
pub fn write_gu16(&mut self, v: u64) -> Result<(), GraalIoError>
Writes an encoded Graal unsigned 16-bit integer.
§Arguments
v
: The value to write.
§Errors
GraalIoError::ValueExceedsMaximum
: If the value exceeds the maximum for a Graal-encoded integer.GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_gu16(1).unwrap();
Sourcepub fn write_gu24(&mut self, v: u64) -> Result<(), GraalIoError>
pub fn write_gu24(&mut self, v: u64) -> Result<(), GraalIoError>
Writes an encoded Graal unsigned 24-bit integer.
§Arguments
v
: The value to write.
§Errors
GraalIoError::ValueExceedsMaximum
: If the value exceeds the maximum for a Graal-encoded integer.GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_gu24(1).unwrap();
Sourcepub fn write_gu32(&mut self, v: u64) -> Result<(), GraalIoError>
pub fn write_gu32(&mut self, v: u64) -> Result<(), GraalIoError>
Writes an encoded Graal unsigned 32-bit integer.
§Arguments
v
: The value to write.
§Errors
GraalIoError::ValueExceedsMaximum
: If the value exceeds the maximum for a Graal-encoded integer.GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_gu32(1).unwrap();
Sourcepub fn write_gu40(&mut self, v: u64) -> Result<(), GraalIoError>
pub fn write_gu40(&mut self, v: u64) -> Result<(), GraalIoError>
Writes an encoded Graal unsigned 40-bit integer.
§Arguments
v
: The value to write.
§Errors
GraalIoError::ValueExceedsMaximum
: If the value exceeds the maximum for a Graal-encoded integer.GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;
let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_gu40(1).unwrap();
Auto Trait Implementations§
impl<W> Freeze for GraalWriter<W>where
W: Freeze,
impl<W> RefUnwindSafe for GraalWriter<W>where
W: RefUnwindSafe,
impl<W> Send for GraalWriter<W>where
W: Send,
impl<W> Sync for GraalWriter<W>where
W: Sync,
impl<W> Unpin for GraalWriter<W>where
W: Unpin,
impl<W> UnwindSafe for GraalWriter<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more