Struct blaze_pk::reader::TdfReader

source ·
pub struct TdfReader<'a> {
    pub buffer: &'a [u8],
    pub cursor: usize,
}
Expand description

Buffered readable implementation. Allows reading through the underlying slice using a cursor and with a position that can be saved using the marker. Provides functions for reading certain data types in the Blaze format

Fields§

§buffer: &'a [u8]

The underlying buffer to read from

§cursor: usize

The cursor position on the buffer. The cursor should not be set to any arbitry values should only be set to previously know values

Implementations§

source§

impl<'a> TdfReader<'a>

source

pub fn new(buffer: &'a [u8]) -> Self

Creates a new reader over the provided slice of bytes with the default cursor position at zero

source

pub fn read_byte(&mut self) -> DecodeResult<u8>

Takes a single byte from the underlying buffer moving the cursor over by one. Will return UnexpectedEof error if there are no bytes left

source

pub fn read_slice(&mut self, length: usize) -> DecodeResult<&[u8]>

Takes a slice of the provided length from the portion of the buffer that is after the cursor position

length The length of the slice to take

source

pub fn read_f32(&mut self) -> DecodeResult<f32>

Takes a float value from the buffer which moves the cursor over by 4 bytes

source

pub fn len(&self) -> usize

Returns the remaining length left after the cursor

source

pub fn is_empty(&self) -> bool

Returns if there is nothing left after the cursor

source

pub fn read_u8(&mut self) -> DecodeResult<u8>

Decodes a u8 value using the VarInt encoding

source

pub fn read_u16(&mut self) -> DecodeResult<u16>

Decodes a u16 value using hte VarInt encoding. This uses the impl_decode_var macro so its implementation is the same as others

source

pub fn read_u32(&mut self) -> DecodeResult<u32>

Decodes a u32 value using hte VarInt encoding. This uses the impl_decode_var macro so its implementation is the same as others

source

pub fn read_u64(&mut self) -> DecodeResult<u64>

Decodes a u64 value using hte VarInt encoding. This uses the impl_decode_var macro so its implementation is the same as others

source

pub fn read_usize(&mut self) -> DecodeResult<usize>

Decodes a u64 value using hte VarInt encoding. This uses the impl_decode_var macro so its implementation is the same as others

source

pub fn read_blob(&mut self) -> DecodeResult<&[u8]>

Reads a blob from the buffer. The blob is a slice prefixed by a length value

source

pub fn read_string(&mut self) -> DecodeResult<String>

Reads a string from the underlying buffer

source

pub fn read_bool(&mut self) -> DecodeResult<bool>

Reads a boolean value this is encoded using the var int encoding

source

pub fn read_map<K: Decodable + ValueType, V: Decodable + ValueType>( &mut self ) -> DecodeResult<TdfMap<K, V>>

Reads a map from the underlying buffer

source

pub fn read_map_header( &mut self, exp_key_type: TdfType, exp_value_type: TdfType ) -> DecodeResult<usize>

Reads a map header from the underlying buffer ensuring that the key and value types match the provided key and value types. Returns the length of the following content

exp_key_type The type of key to expect exp_value_type The type of value to expect

source

pub fn read_map_body<K: Decodable, V: Decodable>( &mut self, length: usize ) -> DecodeResult<TdfMap<K, V>>

Reads the contents of the map for the provided key value types and for the provided length

length The length of the map (The number of entries)

source

pub fn until_tag(&mut self, tag: &[u8], ty: TdfType) -> DecodeResult<()>

Decodes tags from the reader until the tag with the provided tag name is found. If the tag type doesn’t match the expected_type then an error will be returned.

tag The tag name to read until ty The expected type of the tag

source

pub fn try_until_tag(&mut self, tag: &[u8], ty: TdfType) -> bool

Attempting version of decode_until that returns true if the value was decoded up to otherwise returns false. Marks the reader position before reading and resets the position if the tag was not found

tag The tag name to read until ty The expected type of the tag

source

pub fn tag<C: Decodable + ValueType>(&mut self, tag: &[u8]) -> DecodeResult<C>

Reads the provided tag from the buffer discarding values until it reaches the correct value.

tag The tag name to read

source

pub fn try_tag<C: Decodable + ValueType>( &mut self, tag: &[u8] ) -> DecodeResult<Option<C>>

Reads the provided tag from the buffer discarding values until it reaches the correct value. If the tag is missing the cursor is reset back to where it was

tag The tag name to read

source

pub fn read_type(&mut self) -> DecodeResult<TdfType>

Reads the next TdfType value after the cursor

source

pub fn read_tag(&mut self) -> DecodeResult<Tagged>

Reads a tag from the underlying buffer

source

pub fn skip_f32(&mut self) -> DecodeResult<()>

Skips the 4 bytes required for a 32 bit float value

source

pub fn skip_blob(&mut self) -> DecodeResult<()>

Skips the next string value

source

pub fn skip_var_int(&mut self)

Skips the next var int value

source

pub fn skip_group_2(&mut self) -> DecodeResult<()>

Skips the starting 2 value at the beggining of the group if it exists

source

pub fn skip_group(&mut self) -> DecodeResult<()>

Skips an entire group if one exists

source

pub fn skip_list(&mut self) -> DecodeResult<()>

Skips a list of items

source

pub fn skip_map(&mut self) -> DecodeResult<()>

Skips a map

source

pub fn skip_union(&mut self) -> DecodeResult<()>

Skips a union value

source

pub fn skip_var_int_list(&mut self) -> DecodeResult<()>

Skips a var int list

source

pub fn skip(&mut self) -> DecodeResult<()>

Skips the next tag value

source

pub fn skip_type(&mut self, ty: &TdfType) -> DecodeResult<()>

Skips a data type

ty The type of data to skip

source

pub fn stringify(&mut self, out: &mut String) -> DecodeResult<()>

Decodes all the contents within the reader into a string representation

out The string output to append to

source

pub fn stringify_tag( &mut self, out: &mut String, indent: usize ) -> DecodeResult<()>

Decodes and converts the next tag into a string representation

out The string output to append to indent The current indent level

source

pub fn stringify_type( &mut self, out: &mut String, indent: usize, ty: &TdfType ) -> DecodeResult<()>

Decodes and converts the next value of the provided type into a string representation

out The string output to append to indent The current indent level ty The type

source

pub fn until_list( &mut self, tag: &[u8], value_type: TdfType ) -> DecodeResult<usize>

Reads until the next list values selection for the provided tag. Will read the value type and the length returning the length.

tag The tag to read value_type The expected value type

source

pub fn until_map( &mut self, tag: &[u8], key_type: TdfType, value_type: TdfType ) -> DecodeResult<usize>

Reads until the next map values selection for the provided tag. Will read the key value types and the length returning the length.

tag The tag to read key_type The expected key type value_type The expected value type

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for TdfReader<'a>

§

impl<'a> Send for TdfReader<'a>

§

impl<'a> Sync for TdfReader<'a>

§

impl<'a> Unpin for TdfReader<'a>

§

impl<'a> UnwindSafe for TdfReader<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more