pub struct GraalReader<R: Read> { /* private fields */ }
Expand description
A reader that reads Graal-encoded data.
Implementations§
Source§impl<R: Read> GraalReader<R>
impl<R: Read> GraalReader<R>
Sourcepub fn decode_bits(slice: &[u8]) -> u64
pub fn decode_bits(slice: &[u8]) -> u64
Sourcepub fn read_string(&mut self) -> Result<String, GraalIoError>
pub fn read_string(&mut self) -> Result<String, GraalIoError>
Reads a null-terminated string from the reader.
§Returns
- The string read from the reader.
§Errors
GraalIoError::NoNullTerminator
: If the null terminator (0x00
) is not found.GraalIoError::Utf8ConversionFailed
: If the bytes cannot be converted to a UTF-8 string.GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![104, 101, 108, 108, 111, 0, 119, 111, 114, 108, 100, 0]));
assert_eq!(reader.read_string().unwrap(), "hello");
Sourcepub fn read_gstring(&mut self) -> Result<String, GraalIoError>
pub fn read_gstring(&mut self) -> Result<String, GraalIoError>
Reads a string with a graal-encoded integer at the beginning.
§Returns
- The string read from the reader.
§Errors
GraalIoError::Utf8ConversionFailed
: If the bytes cannot be converted to a UTF-8 string.GraalIoError::Io
: If there is an underlying I/O error.GraalIoError::ValueExceedsMaximum
: If the value exceeds the maximum for a Graal-encoded integer.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![32 + 5, 104, 101, 108, 108, 111, 32 + 5, 119, 111, 114, 108, 100]));
assert_eq!(reader.read_gstring().unwrap(), "hello");
assert_eq!(reader.read_gstring().unwrap(), "world");
Sourcepub fn read_u8(&mut self) -> Result<u8, GraalIoError>
pub fn read_u8(&mut self) -> Result<u8, GraalIoError>
Reads an unsigned char from the reader.
§Returns
- The unsigned char read from the reader.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![1, 2]));
assert_eq!(reader.read_u8().unwrap(), 1);
assert_eq!(reader.read_u8().unwrap(), 2);
Sourcepub fn read_u16(&mut self) -> Result<u16, GraalIoError>
pub fn read_u16(&mut self) -> Result<u16, GraalIoError>
Read an unsigned short from the reader.
§Returns
- The unsigned short read from the reader.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![0, 1, 0, 2]));
assert_eq!(reader.read_u16().unwrap(), 1);
assert_eq!(reader.read_u16().unwrap(), 2);
Sourcepub fn read_u32(&mut self) -> Result<u32, GraalIoError>
pub fn read_u32(&mut self) -> Result<u32, GraalIoError>
Read an unsigned int from the reader.
§Returns
- The unsigned int read from the reader.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![0, 0, 0, 1, 0, 0, 0, 2]));
assert_eq!(reader.read_u32().unwrap(), 1);
assert_eq!(reader.read_u32().unwrap(), 2);
Sourcepub fn read_gu8(&mut self) -> Result<u64, GraalIoError>
pub fn read_gu8(&mut self) -> Result<u64, GraalIoError>
Reads a Graal encoded unsigned 8-bit integer from the reader.
§Returns
- The decoded unsigned char.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![32 + 1]));
assert_eq!(reader.read_gu8().unwrap(), 1);
Sourcepub fn read_gu16(&mut self) -> Result<u64, GraalIoError>
pub fn read_gu16(&mut self) -> Result<u64, GraalIoError>
Reads a Graal encoded unsigned 16-bit integer from the reader.
§Returns
- The decoded unsigned short.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![32 + 1, 32 + 1]));
assert_eq!(reader.read_gu16().unwrap(), 129);
Sourcepub fn read_gu24(&mut self) -> Result<u64, GraalIoError>
pub fn read_gu24(&mut self) -> Result<u64, GraalIoError>
Reads a Graal encoded unsigned 24-bit integer from the reader.
§Returns
- The decoded unsigned int.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![32 + 1, 32 + 1, 32 + 1]));
assert_eq!(reader.read_gu24().unwrap(), 16513);
Sourcepub fn read_gu32(&mut self) -> Result<u64, GraalIoError>
pub fn read_gu32(&mut self) -> Result<u64, GraalIoError>
Reads a Graal encoded unsigned 32-bit integer from the reader.
§Returns
- The decoded unsigned int.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![32 + 1, 32 + 1, 32 + 1, 32 + 1]));
assert_eq!(reader.read_gu32().unwrap(), 2113665);
Sourcepub fn read_gu40(&mut self) -> Result<u64, GraalIoError>
pub fn read_gu40(&mut self) -> Result<u64, GraalIoError>
Reads a Graal encoded unsigned 40-bit integer from the reader.
§Returns
- The decoded unsigned int.
§Errors
GraalIoError::Io
: If there is an underlying I/O error.
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![32 + 1, 32 + 1, 32 + 1, 32 + 1, 32 + 1]));
assert_eq!(reader.read_gu40().unwrap(), 270549121);
Sourcepub fn read_gu(&mut self, n: usize) -> Result<u64, GraalIoError>
pub fn read_gu(&mut self, n: usize) -> Result<u64, GraalIoError>
Reads n
bytes from the reader and decodes them as a Graal unsigned integer.
§Arguments
n
: The number of bytes to read.
§Returns
- The decoded Graal unsigned integer.
§Errors
GraalIoError::Io
: If an I/O error occurs
§Examples
use gbf_core::graal_io::GraalReader;
use std::io::Cursor;
let mut reader = GraalReader::new(Cursor::new(vec![32 + 1, 32 + 1, 32 + 1, 32 + 1, 32 + 1]));
assert_eq!(reader.read_gu(5).unwrap(), 270549121);
Auto Trait Implementations§
impl<R> Freeze for GraalReader<R>where
R: Freeze,
impl<R> RefUnwindSafe for GraalReader<R>where
R: RefUnwindSafe,
impl<R> Send for GraalReader<R>where
R: Send,
impl<R> Sync for GraalReader<R>where
R: Sync,
impl<R> Unpin for GraalReader<R>where
R: Unpin,
impl<R> UnwindSafe for GraalReader<R>where
R: 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