Struct MethodSemanticsRaw

pub struct MethodSemanticsRaw {
    pub rid: u32,
    pub token: Token,
    pub offset: usize,
    pub semantics: u32,
    pub method: u32,
    pub association: CodedIndex,
}
Expand description

Raw representation of a MethodSemantics table entry with unresolved indexes.

This structure represents an unprocessed entry from the MethodSemantics metadata table (ID 0x18), which specifies the relationship between methods and events or properties. It contains raw index values that require resolution to actual metadata objects.

§Purpose

The MethodSemantics table defines which methods serve specific semantic roles for properties and events:

  • Property Accessors: Getters, setters, and other property-related methods
  • Event Handlers: Add, remove, fire, and other event-related methods
  • Runtime Binding: Enables proper method dispatch for property/event operations
  • Language Integration: Supports C#, VB.NET, and other language property/event syntax

§Raw vs Owned

This raw variant is used during initial metadata parsing and contains:

  • Unresolved Indexes: Table indices requiring lookup in related tables
  • Memory Efficiency: Minimal footprint for large-scale parsing operations
  • Binary Compatibility: Direct representation of ECMA-335 file format
  • Batch Processing: Optimized for processing multiple entries sequentially

Use crate::metadata::tables::methodsemantics::MethodSemantics for resolved references and runtime access.

§Usage Patterns

use dotscope::metadata::tables::methodsemantics::raw::MethodSemanticsRaw;
use dotscope::metadata::tables::MethodSemanticsAttributes;

// Check semantic type
match raw_entry.semantics {
    MethodSemanticsAttributes::GETTER => {
        println!("Property getter method: {}", raw_entry.method);
    }
    MethodSemanticsAttributes::ADD_ON => {
        println!("Event add method: {}", raw_entry.method);
    }
    _ => println!("Other semantic type"),
}

// Access coded index for association
println!("Associated with: {:?}", raw_entry.association.tag);

§Thread Safety

MethodSemanticsRaw is std::marker::Send and std::marker::Sync as it contains only primitive data types. Instances can be safely shared across threads and accessed concurrently without synchronization.

§ECMA-335 Reference

Corresponds to ECMA-335 §II.22.28 MethodSemantics table structure.

  • ECMA-335 Standard
  • Table ID: 0x18
  • Purpose: Define semantic relationships between methods and properties/events

Fields§

§rid: u32

Row identifier within the MethodSemantics table.

This 1-based index uniquely identifies this entry within the table. Combined with table ID 0x18, forms the metadata token 0x18XXXXXX.

§token: Token

Metadata token for this MethodSemantics entry.

Format: 0x18XXXXXX where XXXXXX is the row ID. Used for cross-referencing this entry from other metadata structures.

§offset: usize

Byte offset of this entry in the original metadata stream.

Points to the start of this entry’s data in the metadata file. Used for debugging and low-level metadata inspection.

§semantics: u32

Semantic relationship type bitmask.

2-byte value defining the method’s semantic role using MethodSemanticsAttributes:

  • SETTER (0x0001) - Property setter method
  • GETTER (0x0002) - Property getter method
  • OTHER (0x0004) - Other property/event method
  • ADD_ON (0x0008) - Event add method
  • REMOVE_ON (0x0010) - Event remove method
  • FIRE (0x0020) - Event fire method

As specified in ECMA-335 §II.23.1.12.

§method: u32

Raw index into the MethodDef table.

This unresolved index identifies the method that implements the semantic behavior. Must be resolved using the MethodDef table to get the actual Method reference.

Index size depends on table size (2 or 4 bytes).

§association: CodedIndex

Raw HasSemantics coded index.

This coded index identifies the associated property or event that this method provides semantic behavior for. The encoding combines:

  • Low 2 bits: Table tag (0=Event, 1=Property)
  • High bits: Row index in the target table

Must be resolved using the appropriate table to get the actual type reference.

Implementations§

§

impl MethodSemanticsRaw

pub fn apply<F>(&self, get_ref: F, methods: &MethodMap) -> Result<()>

Applies the semantic relationship directly using raw data.

This method resolves the raw indexes and applies the semantic relationship to the associated property or event without creating an owned instance. It’s more memory-efficient than conversion to owned form when only applying relationships is needed.

§Process
  1. Resolves the method index to an actual Method reference
  2. Resolves the association coded index to a property or event
  3. Applies the semantic relationship based on the semantics bitmask
  4. Sets the appropriate method reference on the property/event
§Arguments
  • get_ref - Closure that resolves coded indices to CilTypeReference
  • methods - Map of all parsed MethodDef entries for method resolution
§Errors
  • Method token cannot be resolved (invalid index or missing entry)
  • Association coded index is malformed or points to invalid entry
  • Semantic attributes are invalid or unsupported
  • Method is already assigned for this semantic role (duplicate)
  • Property/event assignment fails due to type constraints

pub fn to_owned<F>( &self, get_ref: F, methods: &MethodMap, ) -> Result<MethodSemanticsRc>

Converts this raw entry to an owned MethodSemantics with resolved references.

This method performs the conversion from raw indexes to resolved object references, creating a fully usable MethodSemantics instance with owned data. The resulting instance contains resolved method and association references for efficient runtime access.

§Arguments
  • get_ref - Closure that resolves coded indices to CilTypeReference
  • methods - Map of all parsed MethodDef entries for method resolution
§Returns

A reference-counted MethodSemanticsRc containing the resolved entry.

§Errors
  • Method token cannot be resolved (0x06XXXXXX format expected)
  • Method index points to non-existent MethodDef entry
  • Association coded index is malformed or invalid
  • Association resolves to CilTypeReference::None
  • Required dependency data is missing or corrupted

Trait Implementations§

§

impl Clone for MethodSemanticsRaw

§

fn clone(&self) -> MethodSemanticsRaw

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for MethodSemanticsRaw

§

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

Formats the value using the given formatter. Read more
§

impl RowReadable for MethodSemanticsRaw

§

fn row_read( data: &[u8], offset: &mut usize, rid: u32, sizes: &TableInfoRef, ) -> Result<Self>

Reads a single MethodSemantics table row from binary data.

Parses the binary representation according to ECMA-335 §II.22.28:

  1. Semantics (2 bytes): Bitmask of semantic attributes
  2. Method (2-4 bytes): Index into MethodDef table
  3. Association (2-4 bytes): HasSemantics coded index
§Arguments
  • data - Binary data containing the table
  • offset - Current read position (updated by this method)
  • rid - Row identifier for this entry (1-based)
  • sizes - Table size information for proper index width calculation
§Returns

Parsed MethodSemanticsRaw instance with populated fields

§Errors
  • Insufficient data remaining at offset
  • Invalid coded index encoding
  • Data corruption or malformed structure
§

impl RowWritable for MethodSemanticsRaw

§

fn row_write( &self, data: &mut [u8], offset: &mut usize, _rid: u32, sizes: &TableInfoRef, ) -> Result<()>

Serialize a MethodSemantics table row to binary format

Writes the row data according to ECMA-335 §II.22.28 specification:

  • semantics: 2-byte bitmask of semantic attributes
  • method: MethodDef table index (method implementing the semantic)
  • association: HasSemantics coded index (property or event)
§Arguments
  • data - Target buffer for writing binary data
  • offset - Current write position (updated after write)
  • rid - Row identifier (unused in this implementation)
  • sizes - Table sizing information for index widths
§Returns

Ok(()) on successful write, error on buffer overflow or encoding failure

§

impl TableRow for MethodSemanticsRaw

§

fn row_size(sizes: &TableInfoRef) -> u32

Calculates the byte size of a MethodSemantics table row.

The row size depends on the metadata table sizes and is calculated as:

  • semantics: 2 bytes (fixed)
  • method: 2 or 4 bytes (depends on MethodDef table size)
  • association: 2 or 4 bytes (depends on HasSemantics coded index size)
§Arguments
  • sizes - Table size information for calculating index widths
§Returns

Total byte size of one table row

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = 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.