Struct ssbh_lib::SsbhEnum64
source · pub struct SsbhEnum64<T: DataType> {
pub data: RelPtr64<T>,
}
Expand description
Reads a struct with a relative offset to a structure of type T with some data type.
Reading will fail if there is no matching variant for data_type
.
#[derive(Debug, BinRead, SsbhWrite)]
struct EnumData {
data_relative_offset: u64,
data_type: u64
}
This can instead be expressed as the following struct.
The T
type should have line to specify that it takes the data type as an argument.
data_type
is automatically passed as an argument when reading T
.
#[derive(Debug, BinRead, SsbhWrite)]
#[br(import(data_type: u64))]
pub enum Data {
#[br(pre_assert(data_type == 1u64))]
Float(f32),
#[br(pre_assert(data_type == 2u64))]
Boolean(u32),
}
impl ssbh_lib::DataType for Data {
fn data_type(&self) -> u64 {
match self {
Data::Float(_) => 1,
Data::Boolean(_) => 2
}
}
}
#[derive(Debug, BinRead, SsbhWrite)]
pub struct EnumData {
data: SsbhEnum64<Data>,
}
Fields§
§data: RelPtr64<T>
Trait Implementations§
source§impl<T> BinRead for SsbhEnum64<T>
impl<T> BinRead for SsbhEnum64<T>
source§fn read_options<R: Read + Seek>(
reader: &mut R,
endian: Endian,
_args: Self::Args<'_>
) -> BinResult<Self>
fn read_options<R: Read + Seek>( reader: &mut R, endian: Endian, _args: Self::Args<'_> ) -> BinResult<Self>
source§fn read_be<R>(reader: &mut R) -> Result<Self, Error>
fn read_be<R>(reader: &mut R) -> Result<Self, Error>
Read
Self
from the reader using default arguments and assuming
big-endian byte order. Read moresource§fn read_le<R>(reader: &mut R) -> Result<Self, Error>
fn read_le<R>(reader: &mut R) -> Result<Self, Error>
Read
Self
from the reader using default arguments and assuming
little-endian byte order. Read moresource§fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
Read
T
from the reader assuming native-endian byte order. Read moresource§fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
Read
Self
from the reader, assuming big-endian byte order, using the
given arguments. Read moresource§impl<T: DataType + PartialEq> PartialEq for SsbhEnum64<T>
impl<T: DataType + PartialEq> PartialEq for SsbhEnum64<T>
source§impl<T: DataType + SsbhWrite> SsbhWrite for SsbhEnum64<T>
impl<T: DataType + SsbhWrite> SsbhWrite for SsbhEnum64<T>
source§fn ssbh_write<W: Write + Seek>(
&self,
writer: &mut W,
data_ptr: &mut u64
) -> Result<()>
fn ssbh_write<W: Write + Seek>( &self, writer: &mut W, data_ptr: &mut u64 ) -> Result<()>
Writes the byte representation of
self
to writer
.
data_ptr
is assumed to be the absolute offset where the next data stored behind an offset will be written.
Struct that contains no offsets as fields can skip updating data_ptr
. Read moresource§fn size_in_bytes(&self) -> u64
fn size_in_bytes(&self) -> u64
The offset in bytes between successive elements in an array of this type.
This should include any alignment or padding.
source§fn write<W>(&self, writer: &mut W) -> Result<(), Error>
fn write<W>(&self, writer: &mut W) -> Result<(), Error>
Writes the byte representation of
self
to writer
.
This is a convenience method for ssbh_write that handles initializing the data pointer.source§fn alignment_in_bytes() -> u64
fn alignment_in_bytes() -> u64
The alignment for pointers of this type, which is useful for offset calculations.
Auto Trait Implementations§
impl<T> RefUnwindSafe for SsbhEnum64<T>where
T: RefUnwindSafe,
impl<T> Send for SsbhEnum64<T>where
T: Send,
impl<T> Sync for SsbhEnum64<T>where
T: Sync,
impl<T> Unpin for SsbhEnum64<T>where
T: Unpin,
impl<T> UnwindSafe for SsbhEnum64<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more