Skip to main content

VerificationType

Enum VerificationType 

Source
pub enum VerificationType {
    Top,
    Integer,
    Float,
    Double,
    Long,
    Null,
    UninitializedThis,
    Object {
        cpool_index: u16,
    },
    Uninitialized {
        offset: u16,
    },
}
Expand description

Represents a verification type used in the Java Virtual Machine’s type checking system.

Verification types are used during bytecode verification to track the types of values on the operand stack and in local variables. They are primarily used in the StackMapTable attribute, which helps the JVM perform type checking during class loading.

§Examples

use ristretto_classfile::attributes::VerificationType;

// Create primitive verification types
let top_type = VerificationType::Top;
let int_type = VerificationType::Integer;
let float_type = VerificationType::Float;
let double_type = VerificationType::Double;
let long_type = VerificationType::Long;
let null_type = VerificationType::Null;
let uninit_this = VerificationType::UninitializedThis;

// Create reference verification types
let object_type = VerificationType::Object { cpool_index: 15 };
let uninit_type = VerificationType::Uninitialized { offset: 42 };

Serializing and deserializing verification types:

use ristretto_classfile::attributes::VerificationType;
use ristretto_classfile::byte_reader::ByteReader;

// Serialize an Object verification type
let object_type = VerificationType::Object { cpool_index: 15 };
let mut bytes = Vec::new();
object_type.to_bytes(&mut bytes)?;
assert_eq!(bytes, vec![0x07, 0x00, 0x0F]); // Tag 7 + index 15 (big-endian)

// Deserialize back from bytes
let mut reader = ByteReader::new(&bytes);
let deserialized = VerificationType::from_bytes(&mut reader)?;
assert_eq!(deserialized, object_type);

§References

Variants§

§

Top

§

Integer

§

Float

§

Double

§

Long

§

Null

§

UninitializedThis

§

Object

Fields

§cpool_index: u16
§

Uninitialized

Fields

§offset: u16

Implementations§

Source§

impl VerificationType

Source

pub fn tag(&self) -> u8

Return the tag for the verification type.

See: https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-VerificationTypeInfo

§Examples
use ristretto_classfile::attributes::VerificationType;

let top_type = VerificationType::Top;
assert_eq!(top_type.tag(), 0);

let int_type = VerificationType::Integer;
assert_eq!(int_type.tag(), 1);
Source

pub fn from_bytes(bytes: &mut ByteReader<'_>) -> Result<VerificationType>

Deserialize the verification type from bytes.

§Errors

Returns an error if the tag is invalid.

§Examples
use ristretto_classfile::attributes::VerificationType;
use ristretto_classfile::byte_reader::ByteReader;

let bytes = vec![0x07, 0x00, 0x0A]; // Object type with cpool_index 10
let mut reader = ByteReader::new(&bytes);
let verification_type = VerificationType::from_bytes(&mut reader)?;
assert_eq!(verification_type, VerificationType::Object { cpool_index: 10 });
Source

pub fn to_bytes(&self, bytes: &mut Vec<u8>) -> Result<()>

Serialize the verification type to bytes.

§Errors

Should not occur; reserved for future use.

§Examples
use ristretto_classfile::attributes::VerificationType;

let object_type = VerificationType::Object { cpool_index: 10 };
let mut bytes = Vec::new();
object_type.to_bytes(&mut bytes)?;
assert_eq!(bytes, vec![0x07, 0x00, 0x0A]);

Trait Implementations§

Source§

impl Clone for VerificationType

Source§

fn clone(&self) -> VerificationType

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 Debug for VerificationType

Source§

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

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

impl Display for VerificationType

Source§

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

Implements the Display trait for VerificationType, providing a human-readable string representation of each verification type.

§Examples

Using the Display trait to format verification types as strings:

use ristretto_classfile::attributes::VerificationType;

let output = VerificationType::Top.to_string();
assert_eq!(output, "top");
Source§

impl Eq for VerificationType

Source§

impl PartialEq for VerificationType

Source§

fn eq(&self, other: &VerificationType) -> 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 VerificationType

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.