gbf_core::graal_io

Struct GraalWriter

Source
pub struct GraalWriter<W: Write> { /* private fields */ }
Expand description

A writer that writes Graal-encoded data.

Implementations§

Source§

impl<W: Write> GraalWriter<W>

Source

pub fn new(inner: W) -> Self

Creates a new GraalWriter

§Arguments
  • inner: The writer to wrap.
§Returns
  • A new GraalWriter with the given bytes.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;

let data = vec![0];
let writer = GraalWriter::new(Cursor::new(data));
Source

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]);
Source

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();
Source

pub fn write_string(&mut self, s: &str) -> Result<(), GraalIoError>

Write a string to the writer, followed by a null terminator.

§Arguments
  • s: The string to write.
§Examples
use gbf_core::graal_io::GraalWriter;
use std::io::Cursor;

let mut writer = GraalWriter::new(Cursor::new(vec![]));
writer.write_string("hello").unwrap();
writer.write_string("world").unwrap();
Source

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();
Source

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);
Source

pub fn write_u16(&mut self, s: u16) -> Result<(), GraalIoError>

Write an unsigned 16-bit integer to the writer.

§Arguments
  • s: The unsigned short 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_u16(1);
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.