pub trait ReadBytes: Read + Seek {
Show 45 methods
// Provided methods
fn len(&mut self) -> Result<u64> { ... }
fn is_empty(&mut self) -> Result<bool> { ... }
fn read_slice(&mut self, size: usize, rewind: bool) -> Result<Vec<u8>> { ... }
fn read_bool(&mut self) -> Result<bool> { ... }
fn read_u8(&mut self) -> Result<u8> { ... }
fn read_u16(&mut self) -> Result<u16> { ... }
fn read_u24(&mut self) -> Result<u32> { ... }
fn read_u32(&mut self) -> Result<u32> { ... }
fn read_u64(&mut self) -> Result<u64> { ... }
fn read_cauleb128(&mut self) -> Result<u32> { ... }
fn read_i8(&mut self) -> Result<i8> { ... }
fn read_i16(&mut self) -> Result<i16> { ... }
fn read_i24(&mut self) -> Result<i32> { ... }
fn read_i32(&mut self) -> Result<i32> { ... }
fn read_i64(&mut self) -> Result<i64> { ... }
fn read_optional_i16(&mut self) -> Result<i16> { ... }
fn read_optional_i32(&mut self) -> Result<i32> { ... }
fn read_optional_i64(&mut self) -> Result<i64> { ... }
fn read_f16(&mut self) -> Result<f16> { ... }
fn read_f32(&mut self) -> Result<f32> { ... }
fn read_f32_normal_from_u8(&mut self) -> Result<f32> { ... }
fn read_f64(&mut self) -> Result<f64> { ... }
fn read_string_u8(&mut self, size: usize) -> Result<String> { ... }
fn read_string_u8_iso_8859_15(&mut self, size: usize) -> Result<String> { ... }
fn read_string_u8_0padded(&mut self, size: usize) -> Result<String> { ... }
fn read_string_u8_0terminated(&mut self) -> Result<String> { ... }
fn read_sized_string_u8(&mut self) -> Result<String> { ... }
fn read_sized_string_u8_u32(&mut self) -> Result<String> { ... }
fn read_optional_string_u8(&mut self) -> Result<String> { ... }
fn read_string_u16(&mut self, size: usize) -> Result<String> { ... }
fn read_string_u16_0padded(&mut self, size: usize) -> Result<String> { ... }
fn read_string_u16_0terminated(&mut self) -> Result<String> { ... }
fn read_sized_string_u16(&mut self) -> Result<String> { ... }
fn read_sized_string_u16_u32(&mut self) -> Result<String> { ... }
fn read_optional_string_u16(&mut self) -> Result<String> { ... }
fn read_string_colour_rgb(&mut self) -> Result<String> { ... }
fn read_vector_2_u8(&mut self) -> Result<Vector2<u8>> { ... }
fn read_vector_2_f32_pct_from_vector_2_u8(&mut self) -> Result<Vector2<f32>> { ... }
fn read_vector_2_f32_from_vector_2_f16(&mut self) -> Result<Vector2<f32>> { ... }
fn read_vector_4_u8(&mut self) -> Result<Vector4<u8>> { ... }
fn read_vector_4_f32(&mut self) -> Result<Vector4<f32>> { ... }
fn read_vector_4_f32_from_vec_3_f32(&mut self) -> Result<Vector4<f32>> { ... }
fn read_vector_4_f32_normal_from_vector_4_u8(
&mut self,
) -> Result<Vector4<f32>> { ... }
fn read_vector_4_f32_pct_from_vector_4_u8(&mut self) -> Result<Vector4<f32>> { ... }
fn read_vector_4_f32_normal_from_vector_4_f16(
&mut self,
) -> Result<Vector4<f32>> { ... }
}Expand description
Provided Methods§
Sourcefn len(&mut self) -> Result<u64>
fn len(&mut self) -> Result<u64>
This function returns the length of the data we’re reading.
Extracted from the nightly std.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![1, 2, 3, 4];
let mut cursor = Cursor::new(data);
let len = cursor.len().unwrap();
assert_eq!(len, 4);Sourcefn is_empty(&mut self) -> Result<bool>
fn is_empty(&mut self) -> Result<bool>
This function returns if the data is empty.
It’s slightly faster than checking for len == 0.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![];
let mut cursor = Cursor::new(data);
assert!(ReadBytes::is_empty(&mut cursor).unwrap());Sourcefn read_slice(&mut self, size: usize, rewind: bool) -> Result<Vec<u8>>
fn read_slice(&mut self, size: usize, rewind: bool) -> Result<Vec<u8>>
This function returns the amount of bytes specified in the size argument as a Vec<u8>.
If rewind is true, the cursor will be reset to its original position once the data is returned.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![1, 2, 3, 4];
let mut cursor = Cursor::new(data.to_vec());
let data_read = cursor.read_slice(4, false).unwrap();
assert_eq!(data, data_read);
Sourcefn read_bool(&mut self) -> Result<bool>
fn read_bool(&mut self) -> Result<bool>
This function tries to read a bool value from self.
This is simple: 0 is false, 1 is true. Anything else is an error.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0, 1, 2];
let mut cursor = Cursor::new(data);
let first = cursor.read_bool();
let second = cursor.read_bool();
let third = cursor.read_bool();
assert_eq!(first.unwrap(), false);
assert_eq!(second.unwrap(), true);
assert!(third.is_err());Sourcefn read_u8(&mut self) -> Result<u8>
fn read_u8(&mut self) -> Result<u8>
This function tries to read an unsigned byte value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![10];
let mut cursor = Cursor::new(data);
let data = cursor.read_u8().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_u8().is_err(), true);Sourcefn read_u16(&mut self) -> Result<u16>
fn read_u16(&mut self) -> Result<u16>
This function tries to read an u16 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![10, 0, 10];
let mut cursor = Cursor::new(data);
let data = cursor.read_u16().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_u16().is_err(), true);Sourcefn read_u24(&mut self) -> Result<u32>
fn read_u24(&mut self) -> Result<u32>
This function tries to read an u24 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![152, 150, 129, 152, 150];
let mut cursor = Cursor::new(data);
let data = cursor.read_u24().unwrap();
assert_eq!(data, 84_926_96);
assert_eq!(cursor.read_u24().is_err(), true);Sourcefn read_u32(&mut self) -> Result<u32>
fn read_u32(&mut self) -> Result<u32>
This function tries to read an u32 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![10, 0, 0, 0, 10, 0, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_u32().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_u32().is_err(), true);Sourcefn read_u64(&mut self) -> Result<u64>
fn read_u64(&mut self) -> Result<u64>
This function tries to read an u64 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![10, 0, 0, 0, 0, 0, 0, 0, 10, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_u64().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_u64().is_err(), true);Sourcefn read_cauleb128(&mut self) -> Result<u32>
fn read_cauleb128(&mut self) -> Result<u32>
This function tries to read CA’s own take (or I greatly misunderstood this) on ULEB_128 values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0x80, 10];
let mut cursor = Cursor::new(data);
let data = cursor.read_cauleb128().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_cauleb128().is_err(), true);Sourcefn read_i8(&mut self) -> Result<i8>
fn read_i8(&mut self) -> Result<i8>
This function tries to read a signed byte value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![254];
let mut cursor = Cursor::new(data);
let data = cursor.read_i8().unwrap();
assert_eq!(data, -2);
assert_eq!(cursor.read_i8().is_err(), true);Sourcefn read_i16(&mut self) -> Result<i16>
fn read_i16(&mut self) -> Result<i16>
This function tries to read an i16 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![254, 254, 10];
let mut cursor = Cursor::new(data);
let data = cursor.read_i16().unwrap();
assert_eq!(data, -258);
assert_eq!(cursor.read_i16().is_err(), true);Sourcefn read_i24(&mut self) -> Result<i32>
fn read_i24(&mut self) -> Result<i32>
This function tries to read an i24 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![152, 150, 129, 152, 150];
let mut cursor = Cursor::new(data);
let data = cursor.read_i24().unwrap();
assert_eq!(data, -8_284_520);
assert_eq!(cursor.read_i24().is_err(), true);Sourcefn read_i32(&mut self) -> Result<i32>
fn read_i32(&mut self) -> Result<i32>
This function tries to read an i32 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![10, 0, 0, 0, 10, 0, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_i32().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_i32().is_err(), true);Sourcefn read_i64(&mut self) -> Result<i64>
fn read_i64(&mut self) -> Result<i64>
This function tries to read an i64 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![10, 0, 0, 0, 0, 0, 0, 0, 10, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_i64().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_i64().is_err(), true);Sourcefn read_optional_i16(&mut self) -> Result<i16>
fn read_optional_i16(&mut self) -> Result<i16>
This function tries to read an optional i16 value from self.
The value is preceeded by a bool. If the bool is true, we expect a value after it. If its false, we expect a sentinel value (0) after it.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![1, 254, 254, 2];
let mut cursor = Cursor::new(data);
let data = cursor.read_optional_i16().unwrap();
assert_eq!(data, -258);
assert_eq!(cursor.read_optional_i16().is_err(), true);
Sourcefn read_optional_i32(&mut self) -> Result<i32>
fn read_optional_i32(&mut self) -> Result<i32>
This function tries to read an optional i32 value from self.
The value is preceeded by a bool. If the bool is true, we expect a value after it. If its false, we expect a sentinel value (0) after it.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![1, 10, 0, 0, 0, 2];
let mut cursor = Cursor::new(data);
let data = cursor.read_optional_i32().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_optional_i32().is_err(), true);
Sourcefn read_optional_i64(&mut self) -> Result<i64>
fn read_optional_i64(&mut self) -> Result<i64>
This function tries to read an optional i64 value from self.
The value is preceeded by a bool. If the bool is true, we expect a value after it. If its false, we expect a sentinel value (0) after it.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![1, 10, 0, 0, 0, 0, 0, 0, 0, 2];
let mut cursor = Cursor::new(data);
let data = cursor.read_optional_i64().unwrap();
assert_eq!(data, 10);
assert_eq!(cursor.read_optional_i64().is_err(), true);
Sourcefn read_f16(&mut self) -> Result<f16>
fn read_f16(&mut self) -> Result<f16>
This function tries to read an f16 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![32, 65];
let mut cursor = Cursor::new(data);
let data = cursor.read_f16().unwrap();
assert_eq!(data, half::f16::from_f32(2.5625));
assert_eq!(cursor.read_f16().is_err(), true);Sourcefn read_f32(&mut self) -> Result<f32>
fn read_f32(&mut self) -> Result<f32>
This function tries to read an f32 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0, 0, 32, 65];
let mut cursor = Cursor::new(data);
let data = cursor.read_f32().unwrap();
assert_eq!(data, 10.0);
assert_eq!(cursor.read_f32().is_err(), true);Sourcefn read_f32_normal_from_u8(&mut self) -> Result<f32>
fn read_f32_normal_from_u8(&mut self) -> Result<f32>
This function tries to read an f32 value encoded in a single byte from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![32];
let mut cursor = Cursor::new(data);
let data = cursor.read_f32_normal_from_u8().unwrap();
assert_eq!(data, -0.7490196);
assert_eq!(cursor.read_f32_normal_from_u8().is_err(), true);Sourcefn read_f64(&mut self) -> Result<f64>
fn read_f64(&mut self) -> Result<f64>
This function tries to read an f64 value from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0, 0, 0, 0, 0, 0, 36, 64];
let mut cursor = Cursor::new(data);
let data = cursor.read_f64().unwrap();
assert_eq!(data, 10.0);
assert_eq!(cursor.read_f64().is_err(), true);Sourcefn read_string_u8(&mut self, size: usize) -> Result<String>
fn read_string_u8(&mut self, size: usize) -> Result<String>
This function tries to read an UTF-8 String value of the provided size from self.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-8 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![87, 97, 104, 97, 104, 97, 104, 97, 104, 97];
let mut cursor = Cursor::new(data);
let data = cursor.read_string_u8(10).unwrap();
assert_eq!(data, "Wahahahaha");
assert_eq!(cursor.read_string_u8(10).is_err(), true);Sourcefn read_string_u8_iso_8859_15(&mut self, size: usize) -> Result<String>
fn read_string_u8_iso_8859_15(&mut self, size: usize) -> Result<String>
This function tries to read an ISO-8859-15 String value of the provided size from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![87, 97, 104, 97, 255, 104, 97, 104, 97, 104, 97];
let mut cursor = Cursor::new(data);
let data = cursor.read_string_u8_iso_8859_15(11).unwrap();
assert_eq!(data, "Wahaÿhahaha");
assert_eq!(cursor.read_string_u8_iso_8859_15(10).is_err(), true);Sourcefn read_string_u8_0padded(&mut self, size: usize) -> Result<String>
fn read_string_u8_0padded(&mut self, size: usize) -> Result<String>
This function tries to read a 00-Padded UTF-8 String value of the provided size from self.
Note that size here is the full length of the String, including the 00 bytes that act as padding.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-8 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![87, 97, 104, 97, 104, 97, 0, 0, 0, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_string_u8_0padded(10).unwrap();
assert_eq!(data, "Wahaha");
assert_eq!(cursor.read_string_u8_0padded(10).is_err(), true);Sourcefn read_string_u8_0terminated(&mut self) -> Result<String>
fn read_string_u8_0terminated(&mut self) -> Result<String>
This function tries to read a 00-Terminated (or NULL-Terminated) UTF-8 String value from self.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-8 String, the last value is not 00 or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![87, 97, 104, 97, 104, 97, 104, 97, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_string_u8_0terminated().unwrap();
assert_eq!(data, "Wahahaha");
assert_eq!(cursor.read_string_u8_0terminated().is_err(), true);Sourcefn read_sized_string_u8(&mut self) -> Result<String>
fn read_sized_string_u8(&mut self) -> Result<String>
This function tries to read a Sized UTF-8 String value from self.
In Sized Strings, the first two values of the data are the size in Characters of the string, followed by the String itself.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-8 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![10, 0, 87, 97, 104, 97, 104, 97, 104, 97, 104, 97];
let mut cursor = Cursor::new(data);
let data = cursor.read_sized_string_u8().unwrap();
assert_eq!(data, "Wahahahaha");
assert_eq!(cursor.read_sized_string_u8().is_err(), true);Sourcefn read_sized_string_u8_u32(&mut self) -> Result<String>
fn read_sized_string_u8_u32(&mut self) -> Result<String>
This function tries to read a Sized UTF-8 String value from self.
In these particular Sized Strings, the first four values of the data are the size in Characters of the string, followed by the String itself.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-8 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![10, 0, 0, 0, 87, 97, 104, 97, 104, 97, 104, 97, 104, 97];
let mut cursor = Cursor::new(data);
let data = cursor.read_sized_string_u8_u32().unwrap();
assert_eq!(data, "Wahahahaha");
assert_eq!(cursor.read_sized_string_u8_u32().is_err(), true);Sourcefn read_optional_string_u8(&mut self) -> Result<String>
fn read_optional_string_u8(&mut self) -> Result<String>
This function tries to read an Optional UTF-8 String value from self.
In Optional Strings, the first byte is a boolean. If true, it’s followed by a Sized String. If false, then there is no more data after the boolean.
It may fail if there are not enough bytes to read the value, the first value is not a boolean,
the value contains invalid, characters for an UTF-8 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![1, 10, 0, 87, 97, 104, 97, 104, 97, 104, 97, 104, 97];
let mut cursor = Cursor::new(data);
let data = cursor.read_optional_string_u8().unwrap();
assert_eq!(data, "Wahahahaha");
assert_eq!(cursor.read_optional_string_u8().is_err(), true);Sourcefn read_string_u16(&mut self, size: usize) -> Result<String>
fn read_string_u16(&mut self, size: usize) -> Result<String>
This function tries to read an UTF-16 String value of the provided size (in bytes) from self.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-16 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![87, 0, 97, 0, 104, 0, 97, 0, 104, 0, 97, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_string_u16(12).unwrap();
assert_eq!(data, "Wahaha");
assert_eq!(cursor.read_string_u16(12).is_err(), true);Sourcefn read_string_u16_0padded(&mut self, size: usize) -> Result<String>
fn read_string_u16_0padded(&mut self, size: usize) -> Result<String>
This function tries to read a 00-Padded UTF-16 String value of the provided size from self.
Note that size here is the full length of the String in bytes, including the 00 bytes that act as padding.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-16 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![87, 0, 97, 0, 104, 0, 97, 0, 104, 0, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_string_u16_0padded(20).unwrap();
assert_eq!(data, "Wahaha");
assert_eq!(cursor.read_string_u16_0padded(20).is_err(), true);Sourcefn read_string_u16_0terminated(&mut self) -> Result<String>
fn read_string_u16_0terminated(&mut self) -> Result<String>
This function tries to read a 00-Terminated (or NULL-Terminated) UTF-16 String value from self.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-16 String, the last value is not 00 or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![87, 00, 97, 00, 104, 00, 97, 00, 104, 00, 97, 00, 104, 00, 97, 00, 00, 00];
let mut cursor = Cursor::new(data);
let data = cursor.read_string_u16_0terminated().unwrap();
assert_eq!(data, "Wahahaha");
assert_eq!(cursor.read_string_u16_0terminated().is_err(), true);Sourcefn read_sized_string_u16(&mut self) -> Result<String>
fn read_sized_string_u16(&mut self) -> Result<String>
This function tries to read a Sized UTF-16 String value from self.
In Sized Strings, the first two values of the data are the size in Characters of the string, followed by the String itself.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-16 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![4, 0, 87, 0, 97, 0, 104, 0, 97, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_sized_string_u16().unwrap();
assert_eq!(data, "Waha");
assert_eq!(cursor.read_sized_string_u16().is_err(), true);Sourcefn read_sized_string_u16_u32(&mut self) -> Result<String>
fn read_sized_string_u16_u32(&mut self) -> Result<String>
This function tries to read a Sized UTF-16 String value from self.
In these particular Sized Strings, the first four values of the data are the size in Characters of the string, followed by the String itself.
It may fail if there are not enough bytes to read the value, the value contains invalid
characters for an UTF-16 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![4, 0, 0, 0, 87, 0, 97, 0, 104, 0, 97, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_sized_string_u16_u32().unwrap();
assert_eq!(data, "Waha");
assert_eq!(cursor.read_sized_string_u16_u32().is_err(), true);Sourcefn read_optional_string_u16(&mut self) -> Result<String>
fn read_optional_string_u16(&mut self) -> Result<String>
This function tries to read an Optional UTF-16 String value from self.
In Optional Strings, the first byte is a boolean. If true, it’s followed by a Sized String. If false, then there is no more data after the boolean.
It may fail if there are not enough bytes to read the value, the first value is not a boolean,
the value contains invalid, characters for an UTF-16 String, or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![1, 4, 0, 87, 0, 97, 0, 104, 0, 97, 0];
let mut cursor = Cursor::new(data);
let data = cursor.read_optional_string_u16().unwrap();
assert_eq!(data, "Waha");
assert_eq!(cursor.read_optional_string_u16().is_err(), true);Sourcefn read_string_colour_rgb(&mut self) -> Result<String>
fn read_string_colour_rgb(&mut self) -> Result<String>
This function tries to read a Hex-Encoded RGB Colour from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0xFF, 0x04, 0x05, 0x00];
let mut cursor = Cursor::new(data);
let data = cursor.read_string_colour_rgb().unwrap();
assert_eq!(data, "0504FF");
assert_eq!(cursor.read_string_colour_rgb().is_err(), true);Sourcefn read_vector_2_u8(&mut self) -> Result<Vector2<u8>>
fn read_vector_2_u8(&mut self) -> Result<Vector2<u8>>
This function tries to read a Vector of 2 u8 values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector2;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0x0A, 0x0A];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_2_u8().unwrap();
assert_eq!(data, Vector2::new(10, 10));
assert_eq!(cursor.read_vector_2_u8().is_err(), true);Sourcefn read_vector_2_f32_pct_from_vector_2_u8(&mut self) -> Result<Vector2<f32>>
fn read_vector_2_f32_pct_from_vector_2_u8(&mut self) -> Result<Vector2<f32>>
This function tries to read a Vector of 2 f32 percentage values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector2;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0x0A, 0x0A];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_2_f32_pct_from_vector_2_u8().unwrap();
assert_eq!(data, Vector2::new(0.039215688, 0.039215688));
assert_eq!(cursor.read_vector_2_f32_pct_from_vector_2_u8().is_err(), true);Sourcefn read_vector_2_f32_from_vector_2_f16(&mut self) -> Result<Vector2<f32>>
fn read_vector_2_f32_from_vector_2_f16(&mut self) -> Result<Vector2<f32>>
This function tries to read a Vector of 2 f32 values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector2;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0x0A, 0x0A, 0x0A, 0x0A];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_2_f32_from_vector_2_f16().unwrap();
assert_eq!(data, Vector2::new(0.00018429756, 0.00018429756));
assert_eq!(cursor.read_vector_2_f32_from_vector_2_f16().is_err(), true);Sourcefn read_vector_4_u8(&mut self) -> Result<Vector4<u8>>
fn read_vector_4_u8(&mut self) -> Result<Vector4<u8>>
This function tries to read a Vector of 4 u8 values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector4;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0x0A, 0x0A, 0x0A, 0x0A];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_4_u8().unwrap();
assert_eq!(data, Vector4::new(10, 10, 10, 10));
assert_eq!(cursor.read_vector_4_u8().is_err(), true);Sourcefn read_vector_4_f32(&mut self) -> Result<Vector4<f32>>
fn read_vector_4_f32(&mut self) -> Result<Vector4<f32>>
This function tries to read a Vector of 4 f32 values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector4;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![
0x00, 0x00, 0xFF, 0x3F,
0x00, 0x00, 0xFF, 0x3F,
0x00, 0x00, 0xFF, 0x3F,
0x00, 0x00, 0xFF, 0x3F
];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_4_f32().unwrap();
assert_eq!(data, Vector4::new(1.9921875, 1.9921875, 1.9921875, 1.9921875));
assert_eq!(cursor.read_vector_4_f32().is_err(), true);Sourcefn read_vector_4_f32_from_vec_3_f32(&mut self) -> Result<Vector4<f32>>
fn read_vector_4_f32_from_vec_3_f32(&mut self) -> Result<Vector4<f32>>
This function tries to read a Vector of 4 f32 values from a Vector of 3 f32 values fromself.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector4;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![
0x00, 0x00, 0xFF, 0x3F,
0x00, 0x00, 0xFF, 0x3F,
0x00, 0x00, 0xFF, 0x3F
];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_4_f32_from_vec_3_f32().unwrap();
assert_eq!(data, Vector4::new(1.9921875, 1.9921875, 1.9921875, 0.0));
assert_eq!(cursor.read_vector_4_f32_from_vec_3_f32().is_err(), true);Sourcefn read_vector_4_f32_normal_from_vector_4_u8(&mut self) -> Result<Vector4<f32>>
fn read_vector_4_f32_normal_from_vector_4_u8(&mut self) -> Result<Vector4<f32>>
This function tries to read a Vector of 4 f32 normalized values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector4;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0x0A, 0x0A, 0x0A, 0x0A];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_4_f32_normal_from_vector_4_u8().unwrap();
assert_eq!(data, Vector4::new(-0.92156863, -0.92156863, -0.92156863, -0.92156863));
assert_eq!(cursor.read_vector_4_f32_normal_from_vector_4_u8().is_err(), true);Sourcefn read_vector_4_f32_pct_from_vector_4_u8(&mut self) -> Result<Vector4<f32>>
fn read_vector_4_f32_pct_from_vector_4_u8(&mut self) -> Result<Vector4<f32>>
This function tries to read a Vector of 4 f32 percentage values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector4;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![0x0A, 0x0A, 0x0A, 0x0A];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_4_f32_pct_from_vector_4_u8().unwrap();
assert_eq!(data, Vector4::new(0.039215688, 0.039215688, 0.039215688, 0.039215688));
assert_eq!(cursor.read_vector_4_f32_pct_from_vector_4_u8().is_err(), true);Sourcefn read_vector_4_f32_normal_from_vector_4_f16(&mut self) -> Result<Vector4<f32>>
fn read_vector_4_f32_normal_from_vector_4_f16(&mut self) -> Result<Vector4<f32>>
This function tries to read a Vector of 4 f32 normalized values from self.
It may fail if there are not enough bytes to read the value or self cannot be read.
use nalgebra::Vector4;
use std::io::Cursor;
use rpfm_lib::binary::ReadBytes;
let data = vec![
0x0A, 0x3F,
0x0A, 0x3F,
0x0A, 0x3F,
0x0A, 0x3F
];
let mut cursor = Cursor::new(data);
let data = cursor.read_vector_4_f32_normal_from_vector_4_f16().unwrap();
assert_eq!(data, Vector4::new(3.096775, 3.096775, 3.096775, 1.7597656));
assert_eq!(cursor.read_vector_4_f32_normal_from_vector_4_f16().is_err(), true);