pub struct BinaryReader<'a> { /* private fields */ }Expand description
Binary reader for Unity file formats
Implementations§
Source§impl<'a> BinaryReader<'a>
impl<'a> BinaryReader<'a>
Sourcepub const DEFAULT_MAX_STRING_LEN: usize = 16_777_216usize
pub const DEFAULT_MAX_STRING_LEN: usize = 16_777_216usize
Default maximum length for length-prefixed strings.
Unity files can contain large text blobs (e.g. TextAsset), but unbounded allocations are a DoS risk when parsing hostile input.
Sourcepub fn new(data: &'a [u8], byte_order: ByteOrder) -> BinaryReader<'a>
pub fn new(data: &'a [u8], byte_order: ByteOrder) -> BinaryReader<'a>
Create a new binary reader from byte slice
Sourcepub fn set_position(&mut self, pos: u64) -> Result<(), BinaryError>
pub fn set_position(&mut self, pos: u64) -> Result<(), BinaryError>
Set position in the stream
Sourcepub fn seek(&mut self, offset: i64) -> Result<u64, BinaryError>
pub fn seek(&mut self, offset: i64) -> Result<u64, BinaryError>
Seek to a position relative to the current position
Sourcepub fn align(&mut self) -> Result<(), BinaryError>
pub fn align(&mut self) -> Result<(), BinaryError>
Align to the next 4-byte boundary
Sourcepub fn align_to(&mut self, alignment: u64) -> Result<(), BinaryError>
pub fn align_to(&mut self, alignment: u64) -> Result<(), BinaryError>
Align to the specified byte boundary
Sourcepub fn read_u8(&mut self) -> Result<u8, BinaryError>
pub fn read_u8(&mut self) -> Result<u8, BinaryError>
Read a single byte
Sourcepub fn read_bool(&mut self) -> Result<bool, BinaryError>
pub fn read_bool(&mut self) -> Result<bool, BinaryError>
Read a boolean (as u8, 0 = false, non-zero = true)
Sourcepub fn read_i8(&mut self) -> Result<i8, BinaryError>
pub fn read_i8(&mut self) -> Result<i8, BinaryError>
Read a signed 8-bit integer
Sourcepub fn read_u16(&mut self) -> Result<u16, BinaryError>
pub fn read_u16(&mut self) -> Result<u16, BinaryError>
Read an unsigned 16-bit integer
Sourcepub fn read_i16(&mut self) -> Result<i16, BinaryError>
pub fn read_i16(&mut self) -> Result<i16, BinaryError>
Read a signed 16-bit integer
Sourcepub fn read_u32(&mut self) -> Result<u32, BinaryError>
pub fn read_u32(&mut self) -> Result<u32, BinaryError>
Read an unsigned 32-bit integer
Sourcepub fn read_i32(&mut self) -> Result<i32, BinaryError>
pub fn read_i32(&mut self) -> Result<i32, BinaryError>
Read a signed 32-bit integer
Sourcepub fn read_u64(&mut self) -> Result<u64, BinaryError>
pub fn read_u64(&mut self) -> Result<u64, BinaryError>
Read an unsigned 64-bit integer
Sourcepub fn read_i64(&mut self) -> Result<i64, BinaryError>
pub fn read_i64(&mut self) -> Result<i64, BinaryError>
Read a signed 64-bit integer
Sourcepub fn read_f32(&mut self) -> Result<f32, BinaryError>
pub fn read_f32(&mut self) -> Result<f32, BinaryError>
Read a 32-bit floating point number
Sourcepub fn read_f64(&mut self) -> Result<f64, BinaryError>
pub fn read_f64(&mut self) -> Result<f64, BinaryError>
Read a 64-bit floating point number
Sourcepub fn read_bytes(&mut self, count: usize) -> Result<Vec<u8>, BinaryError>
pub fn read_bytes(&mut self, count: usize) -> Result<Vec<u8>, BinaryError>
Read a fixed number of bytes
Sourcepub fn skip_bytes(&mut self, count: usize) -> Result<(), BinaryError>
pub fn skip_bytes(&mut self, count: usize) -> Result<(), BinaryError>
Skip a fixed number of bytes without allocating.
Sourcepub fn read_remaining(&mut self) -> &[u8] ⓘ
pub fn read_remaining(&mut self) -> &[u8] ⓘ
Read all remaining bytes
Sourcepub fn read_cstring(&mut self) -> Result<String, BinaryError>
pub fn read_cstring(&mut self) -> Result<String, BinaryError>
Read a null-terminated string
Sourcepub fn read_string(&mut self) -> Result<String, BinaryError>
pub fn read_string(&mut self) -> Result<String, BinaryError>
Read a string with a length prefix (32-bit)
Sourcepub fn read_string_limited(
&mut self,
max_len: usize,
) -> Result<String, BinaryError>
pub fn read_string_limited( &mut self, max_len: usize, ) -> Result<String, BinaryError>
Read a string with a length prefix and an explicit maximum size.
Unity typically encodes these lengths as signed 32-bit integers.
Sourcepub fn read_string_fixed(
&mut self,
length: usize,
) -> Result<String, BinaryError>
pub fn read_string_fixed( &mut self, length: usize, ) -> Result<String, BinaryError>
Read a string with a specific length
Sourcepub fn read_aligned_string(&mut self) -> Result<String, BinaryError>
pub fn read_aligned_string(&mut self) -> Result<String, BinaryError>
Read an aligned string (Unity format)
Sourcepub fn byte_order(&self) -> ByteOrder
pub fn byte_order(&self) -> ByteOrder
Get the current byte order
Sourcepub fn set_byte_order(&mut self, byte_order: ByteOrder)
pub fn set_byte_order(&mut self, byte_order: ByteOrder)
Set the byte order
Sourcepub fn remaining_slice(&self) -> &[u8] ⓘ
pub fn remaining_slice(&self) -> &[u8] ⓘ
Get a slice of the remaining data
Sourcepub fn sub_reader(
&self,
offset: usize,
length: usize,
) -> Result<BinaryReader<'a>, BinaryError>
pub fn sub_reader( &self, offset: usize, length: usize, ) -> Result<BinaryReader<'a>, BinaryError>
Create a new reader for a subset of the data
Auto Trait Implementations§
impl<'a> Freeze for BinaryReader<'a>
impl<'a> RefUnwindSafe for BinaryReader<'a>
impl<'a> Send for BinaryReader<'a>
impl<'a> Sync for BinaryReader<'a>
impl<'a> Unpin for BinaryReader<'a>
impl<'a> UnwindSafe for BinaryReader<'a>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more