gsc_executor_common/util.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
3
4//! Utilities used by all backends
5
6use crate::error::Result;
7use sp_wasm_interface::Pointer;
8
9/// Provides safe memory access interface using an external buffer
10pub trait MemoryTransfer {
11 /// Read data from a slice of memory into a newly allocated buffer.
12 ///
13 /// Returns an error if the read would go out of the memory bounds.
14 fn read(&self, source_addr: Pointer<u8>, size: usize) -> Result<Vec<u8>>;
15
16 /// Read data from a slice of memory into a destination buffer.
17 ///
18 /// Returns an error if the read would go out of the memory bounds.
19 fn read_into(&self, source_addr: Pointer<u8>, destination: &mut [u8]) -> Result<()>;
20
21 /// Write data to a slice of memory.
22 ///
23 /// Returns an error if the write would go out of the memory bounds.
24 fn write_from(&self, dest_addr: Pointer<u8>, source: &[u8]) -> Result<()>;
25}