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§
Implementations§
Source§impl VerificationType
impl VerificationType
Sourcepub fn tag(&self) -> u8
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);Sourcepub fn from_bytes(bytes: &mut ByteReader<'_>) -> Result<VerificationType>
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 });Sourcepub fn to_bytes(&self, bytes: &mut Vec<u8>) -> Result<()>
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
impl Clone for VerificationType
Source§fn clone(&self) -> VerificationType
fn clone(&self) -> VerificationType
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VerificationType
impl Debug for VerificationType
Source§impl Display for VerificationType
impl Display for VerificationType
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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");impl Eq for VerificationType
Source§impl PartialEq for VerificationType
impl PartialEq for VerificationType
impl StructuralPartialEq for VerificationType
Auto Trait Implementations§
impl Freeze for VerificationType
impl RefUnwindSafe for VerificationType
impl Send for VerificationType
impl Sync for VerificationType
impl Unpin for VerificationType
impl UnsafeUnpin for VerificationType
impl UnwindSafe for VerificationType
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.