pub struct MemoryAccessManager<Ext> { /* private fields */ }Expand description
Memory access manager. Allows to pre-register memory accesses, and pre-process, them together. For example:
ⓘ
let manager = MemoryAccessManager::default();
let read1 = manager.new_read(10, 20);
let read2 = manager.new_read_as::<u128>(100);
let write1 = manager.new_write_as::<usize>(190);
// First call of read or write interface leads to pre-processing of
// all already registered memory accesses, and clear `self.reads` and `self.writes`.
let value_u128 = manager.read_as(read2).unwrap();
// Next calls do not lead to access pre-processing.
let value1 = manager.read().unwrap();
manager.write_as(write1, 111).unwrap();Implementations§
Source§impl<Ext: BackendExternalities> MemoryAccessManager<Ext>
impl<Ext: BackendExternalities> MemoryAccessManager<Ext>
Sourcepub fn read<M: Memory>(
&mut self,
memory: &M,
read: WasmMemoryRead,
gas_counter: &mut u64,
) -> Result<Vec<u8>, MemoryAccessError>
pub fn read<M: Memory>( &mut self, memory: &M, read: WasmMemoryRead, gas_counter: &mut u64, ) -> Result<Vec<u8>, MemoryAccessError>
Pre-process registered accesses if need and read data from memory into new vector.
Sourcepub fn read_decoded<M: Memory, T: Decode + MaxEncodedLen>(
&mut self,
memory: &M,
read: WasmMemoryReadDecoded<T>,
gas_counter: &mut u64,
) -> Result<T, MemoryAccessError>
pub fn read_decoded<M: Memory, T: Decode + MaxEncodedLen>( &mut self, memory: &M, read: WasmMemoryReadDecoded<T>, gas_counter: &mut u64, ) -> Result<T, MemoryAccessError>
Pre-process registered accesses if need and read and decode data as T from memory.
Sourcepub fn read_as<M: Memory, T: Sized>(
&mut self,
memory: &M,
read: WasmMemoryReadAs<T>,
gas_counter: &mut u64,
) -> Result<T, MemoryAccessError>
pub fn read_as<M: Memory, T: Sized>( &mut self, memory: &M, read: WasmMemoryReadAs<T>, gas_counter: &mut u64, ) -> Result<T, MemoryAccessError>
Pre-process registered accesses if need and read data as T from memory.
Sourcepub fn write<M: Memory>(
&mut self,
memory: &mut M,
write: WasmMemoryWrite,
buff: &[u8],
gas_counter: &mut u64,
) -> Result<(), MemoryAccessError>
pub fn write<M: Memory>( &mut self, memory: &mut M, write: WasmMemoryWrite, buff: &[u8], gas_counter: &mut u64, ) -> Result<(), MemoryAccessError>
Pre-process registered accesses if need and write data from buff to memory.
Sourcepub fn write_as<M: Memory, T: Sized>(
&mut self,
memory: &mut M,
write: WasmMemoryWriteAs<T>,
obj: T,
gas_counter: &mut u64,
) -> Result<(), MemoryAccessError>
pub fn write_as<M: Memory, T: Sized>( &mut self, memory: &mut M, write: WasmMemoryWriteAs<T>, obj: T, gas_counter: &mut u64, ) -> Result<(), MemoryAccessError>
Pre-process registered accesses if need and write obj data to memory.
Trait Implementations§
Source§impl<Ext: Debug> Debug for MemoryAccessManager<Ext>
impl<Ext: Debug> Debug for MemoryAccessManager<Ext>
Source§impl<Ext> Default for MemoryAccessManager<Ext>
impl<Ext> Default for MemoryAccessManager<Ext>
Source§impl<Ext> MemoryAccessRecorder for MemoryAccessManager<Ext>
impl<Ext> MemoryAccessRecorder for MemoryAccessManager<Ext>
Source§fn register_read(&mut self, ptr: u32, size: u32) -> WasmMemoryRead
fn register_read(&mut self, ptr: u32, size: u32) -> WasmMemoryRead
Register new read access.
Source§fn register_read_as<T: Sized>(&mut self, ptr: u32) -> WasmMemoryReadAs<T>
fn register_read_as<T: Sized>(&mut self, ptr: u32) -> WasmMemoryReadAs<T>
Register new read static size type access.
Source§fn register_read_decoded<T: Decode + MaxEncodedLen>(
&mut self,
ptr: u32,
) -> WasmMemoryReadDecoded<T>
fn register_read_decoded<T: Decode + MaxEncodedLen>( &mut self, ptr: u32, ) -> WasmMemoryReadDecoded<T>
Register new read decoded type access.
Source§fn register_write(&mut self, ptr: u32, size: u32) -> WasmMemoryWrite
fn register_write(&mut self, ptr: u32, size: u32) -> WasmMemoryWrite
Register new write access.
Source§fn register_write_as<T: Sized>(&mut self, ptr: u32) -> WasmMemoryWriteAs<T>
fn register_write_as<T: Sized>(&mut self, ptr: u32) -> WasmMemoryWriteAs<T>
Register new write static size access.
Auto Trait Implementations§
impl<Ext> Freeze for MemoryAccessManager<Ext>
impl<Ext> RefUnwindSafe for MemoryAccessManager<Ext>where
Ext: RefUnwindSafe,
impl<Ext> Send for MemoryAccessManager<Ext>where
Ext: Send,
impl<Ext> Sync for MemoryAccessManager<Ext>where
Ext: Sync,
impl<Ext> Unpin for MemoryAccessManager<Ext>where
Ext: Unpin,
impl<Ext> UnwindSafe for MemoryAccessManager<Ext>where
Ext: 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