pub struct DataReaderWriter {
_data_handle: i32,
_block_number: MemoryBlockNumber,
pub memory_block_byte_size: usize,
}
Expand description
Represents a data reader/writer to a caller. Adapts the functions from the Adapter_BackEnd DLL (as wrapped by the functions in adapter_backend.rs).
Fields§
§_data_handle: i32
§_block_number: MemoryBlockNumber
§memory_block_byte_size: usize
Number of bytes in the currently opened memory block.
Implementations§
source§impl DataReaderWriter
impl DataReaderWriter
sourcepub fn new(block_number: MemoryBlockNumber) -> DataReaderWriter
pub fn new(block_number: MemoryBlockNumber) -> DataReaderWriter
Constructor for DataReaderWriter struct.
Parameters
-
blockNumber
A value from the MemoryBlockNumber enumeration indicating the block of memory to open.
sourcepub fn open(&mut self) -> Result<(), String>
pub fn open(&mut self) -> Result<(), String>
Open a memory block for access. Which memory block to open is specified in the constructor. If this is successful, the memory block is open for reading and writing. Call close() to shut down access to the memory block.
sourcepub fn close(&mut self) -> Result<(), String>
pub fn close(&mut self) -> Result<(), String>
Closes a memory block from access. If this is successful, the same memory block can be opened again by a call to open(). Otherwise, instantiate the DataReaderWriter structure again to specify a different memory block.
sourcefn _drop_close(&mut self)
fn _drop_close(&mut self)
Called by Drop::drop() to ensure the memory handle is closed. Does nothing if the handle is already closed (or was never opened). Ignores any errors returned from close() if the memory handle was left opened.
sourcepub fn read(&self, byte_offset: i32, max_bytes: usize) -> Result<Vec<u8>, String>
pub fn read(&self, byte_offset: i32, max_bytes: usize) -> Result<Vec<u8>, String>
Read a requested number of bytes from the currently opened memory block.
Parameters
-
byte_offset
Offset into the memory block to start reading from.
-
maxBytes
The number of bytes to read.
Returns
If successful, returns Ok(Vec<u8>)
containing the bytes that were actually
read; otherwise, returns Err(String)
containing the reason for the failure.
sourcepub fn write(
&self,
byte_offset: i32,
bytes_to_write: &Vec<u8>
) -> Result<usize, String>
pub fn write( &self, byte_offset: i32, bytes_to_write: &Vec<u8> ) -> Result<usize, String>
Write a requested number of bytes to the currently opened memory block.
Parameters
-
byte_offset
Byte offset into the memory block indicating where to start writing.
-
bytes_to_write
Vector of bytes to write to the memory block. All of the bytes will be written – up to the end of the memory block.
Returns
If successful, returns Ok(i32)
containing the number of bytes actually
written; otherwise, returns Err(String)
containing the reason for the
failure.