Skip to main content

Opcode

Struct Opcode 

Source
#[repr(C, packed(1))]
pub struct Opcode { pub category: u8, pub command: u8, pub flags: u16, pub a: u32, pub b: u32, pub c: u32, }
Expand description

A fixed-size 16-byte opcode.

This struct intentionally mirrors the wire layout and is #[repr(C, packed)] per the specification. Because it is packed, fields may be unaligned; always read fields through the accessor methods (which use unaligned reads) rather than by value.

Fields§

§category: u8

Opcode category (see constants::Category).

§command: u8

Command within the category (see constants::Command*).

§flags: u16

Category/command-specific flags.

§a: u32

Primary payload.

§b: u32

Secondary payload.

§c: u32

Tertiary payload.

Implementations§

Source§

impl Opcode

Source

pub const SIZE: usize = OPCODE_SIZE

Byte size of an opcode (16).

Source

pub const fn new( category: u8, command: u8, flags: u16, a: u32, b: u32, c: u32, ) -> Self

Construct an opcode from raw fields.

Source

pub fn category(&self) -> u8

The opcode category.

Source

pub fn command(&self) -> u8

The command within the category.

Source

pub fn flags(&self) -> u16

The 16-bit flags word.

Source

pub fn a(&self) -> u32

Primary payload (little-endian u32).

Source

pub fn b(&self) -> u32

Secondary payload (little-endian u32).

Source

pub fn c(&self) -> u32

Tertiary payload (little-endian u32).

Source

pub fn a_f32(&self) -> f32

Interpret A as an f32 (bit-preserving).

Source

pub fn b_f32(&self) -> f32

Interpret B as an f32 (bit-preserving).

Source

pub fn c_f32(&self) -> f32

Interpret C as an f32 (bit-preserving).

Source

pub fn to_bytes(&self) -> [u8; 16]

Serialize to the 16-byte wire representation (little-endian).

Source

pub fn from_bytes(bytes: &[u8; 16]) -> Self

Deserialize from the 16-byte wire representation (little-endian).

Trait Implementations§

Source§

impl Clone for Opcode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Opcode

Source§

impl Debug for Opcode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Opcode

Source§

impl PartialEq for Opcode

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Opcode

Source§

impl TryFrom<Opcode> for Event

Source§

type Error = EventError

The type returned in the event of a conversion error.
Source§

fn try_from(op: Opcode) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Forget for Opcode

§

impl Freeze for Opcode

§

impl Move for Opcode

§

impl RefUnwindSafe for Opcode

§

impl Send for Opcode

§

impl Sync for Opcode

§

impl Unpin for Opcode

§

impl UnsafeUnpin for Opcode

§

impl UnwindSafe for Opcode

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.