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>
impl<'a> TdfReader<'a>
sourcepub fn new(buffer: &'a [u8]) -> Self
pub fn new(buffer: &'a [u8]) -> Self
Creates a new reader over the provided slice of bytes with the default cursor position at zero
sourcepub fn read_byte(&mut self) -> DecodeResult<u8>
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
sourcepub fn read_slice(&mut self, length: usize) -> DecodeResult<&[u8]>
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
sourcepub fn read_f32(&mut self) -> DecodeResult<f32>
pub fn read_f32(&mut self) -> DecodeResult<f32>
Takes a float value from the buffer which moves the cursor over by 4 bytes
sourcepub fn read_u8(&mut self) -> DecodeResult<u8>
pub fn read_u8(&mut self) -> DecodeResult<u8>
Decodes a u8 value using the VarInt encoding
sourcepub fn read_u16(&mut self) -> DecodeResult<u16>
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
sourcepub fn read_u32(&mut self) -> DecodeResult<u32>
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
sourcepub fn read_u64(&mut self) -> DecodeResult<u64>
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
sourcepub fn read_usize(&mut self) -> DecodeResult<usize>
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
sourcepub fn read_blob(&mut self) -> DecodeResult<&[u8]>
pub fn read_blob(&mut self) -> DecodeResult<&[u8]>
Reads a blob from the buffer. The blob is a slice prefixed by a length value
sourcepub fn read_string(&mut self) -> DecodeResult<String>
pub fn read_string(&mut self) -> DecodeResult<String>
Reads a string from the underlying buffer
sourcepub fn read_bool(&mut self) -> DecodeResult<bool>
pub fn read_bool(&mut self) -> DecodeResult<bool>
Reads a boolean value this is encoded using the var int encoding
sourcepub fn read_map<K: Decodable + ValueType, V: Decodable + ValueType>(
&mut self
) -> DecodeResult<TdfMap<K, V>>
pub fn read_map<K: Decodable + ValueType, V: Decodable + ValueType>( &mut self ) -> DecodeResult<TdfMap<K, V>>
Reads a map from the underlying buffer
sourcepub fn read_map_header(
&mut self,
exp_key_type: TdfType,
exp_value_type: TdfType
) -> DecodeResult<usize>
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
sourcepub fn read_map_body<K: Decodable, V: Decodable>(
&mut self,
length: usize
) -> DecodeResult<TdfMap<K, V>>
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)
sourcepub fn until_tag(&mut self, tag: &[u8], ty: TdfType) -> DecodeResult<()>
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
sourcepub fn try_until_tag(&mut self, tag: &[u8], ty: TdfType) -> bool
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
sourcepub fn tag<C: Decodable + ValueType>(&mut self, tag: &[u8]) -> DecodeResult<C>
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
sourcepub fn try_tag<C: Decodable + ValueType>(
&mut self,
tag: &[u8]
) -> DecodeResult<Option<C>>
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
sourcepub fn read_type(&mut self) -> DecodeResult<TdfType>
pub fn read_type(&mut self) -> DecodeResult<TdfType>
Reads the next TdfType value after the cursor
sourcepub fn read_tag(&mut self) -> DecodeResult<Tagged>
pub fn read_tag(&mut self) -> DecodeResult<Tagged>
Reads a tag from the underlying buffer
sourcepub fn skip_f32(&mut self) -> DecodeResult<()>
pub fn skip_f32(&mut self) -> DecodeResult<()>
Skips the 4 bytes required for a 32 bit float value
sourcepub fn skip_blob(&mut self) -> DecodeResult<()>
pub fn skip_blob(&mut self) -> DecodeResult<()>
Skips the next string value
sourcepub fn skip_var_int(&mut self)
pub fn skip_var_int(&mut self)
Skips the next var int value
sourcepub fn skip_group_2(&mut self) -> DecodeResult<()>
pub fn skip_group_2(&mut self) -> DecodeResult<()>
Skips the starting 2 value at the beggining of the group if it exists
sourcepub fn skip_group(&mut self) -> DecodeResult<()>
pub fn skip_group(&mut self) -> DecodeResult<()>
Skips an entire group if one exists
sourcepub fn skip_list(&mut self) -> DecodeResult<()>
pub fn skip_list(&mut self) -> DecodeResult<()>
Skips a list of items
sourcepub fn skip_map(&mut self) -> DecodeResult<()>
pub fn skip_map(&mut self) -> DecodeResult<()>
Skips a map
sourcepub fn skip_union(&mut self) -> DecodeResult<()>
pub fn skip_union(&mut self) -> DecodeResult<()>
Skips a union value
sourcepub fn skip_var_int_list(&mut self) -> DecodeResult<()>
pub fn skip_var_int_list(&mut self) -> DecodeResult<()>
Skips a var int list
sourcepub fn skip(&mut self) -> DecodeResult<()>
pub fn skip(&mut self) -> DecodeResult<()>
Skips the next tag value
sourcepub fn skip_type(&mut self, ty: &TdfType) -> DecodeResult<()>
pub fn skip_type(&mut self, ty: &TdfType) -> DecodeResult<()>
Skips a data type
ty
The type of data to skip
sourcepub fn stringify(&mut self, out: &mut String) -> DecodeResult<()>
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
sourcepub fn stringify_tag(
&mut self,
out: &mut String,
indent: usize
) -> DecodeResult<()>
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
sourcepub fn stringify_type(
&mut self,
out: &mut String,
indent: usize,
ty: &TdfType
) -> DecodeResult<()>
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
sourcepub fn until_list(
&mut self,
tag: &[u8],
value_type: TdfType
) -> DecodeResult<usize>
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
sourcepub fn until_map(
&mut self,
tag: &[u8],
key_type: TdfType,
value_type: TdfType
) -> DecodeResult<usize>
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