fn read(
        &mut self,
        key_ptr: u32,
        key_size: u32,
        output_size_ptr: u32,
    ) -> Result<Result<(), ApiError>, Trap> {
        if !self.can_write_to_host_buffer() {
            // Exit early if the host buffer is already occupied
            return Ok(Err(ApiError::HostBufferFull));
        }

        let key = self.key_from_mem(key_ptr, key_size)?;
        let cl_value = match self.context.read_gs(&key)? {
            Some(stored_value) => CLValue::try_from(stored_value).map_err(Error::TypeMismatch)?,
            None => return Ok(Err(ApiError::ValueNotFound)),
        };

        let value_size = cl_value.inner_bytes().len() as u32;
        if let Err(error) = self.write_host_buffer(cl_value) {
            return Ok(Err(error));
        }

        let value_bytes = value_size.to_le_bytes(); // Wasm is little-endian
        if let Err(error) = self.memory.set(output_size_ptr, &value_bytes) {
            return Err(Error::Interpreter(error.into()).into());
        }

        Ok(Ok(()))
    }
/// Reads value from the GS living under key specified by `key_ptr` and
/// `key_size`. Wasm and host communicate through memory that Wasm
/// module exports. If contract wants to pass data to the host, it has
/// to tell it [the host] where this data lives in the exported memory
/// (pass its pointer and length).
Reads value from the GS living under key specified by `key_ptr` and
`key_size`. Wasm and host communicate through memory that Wasm
module exports. If contract wants to pass data to the host, it has
to tell it [the host] where this data lives in the exported memory
(pass its pointer and length).
Reads value from the GS living under key specified by ` key_ptr ` and ` key_size ` . Wasm and host communicate through memory that Wasm module exports . If contract wants to pass data to the host it has to tell it [ the host ] where this data lives in the exported memory ( pass its pointer and length ) .
fn read(
        &mut self,
        key_ptr: u32,
        key_size: u32,
        output_size_ptr: u32,
    ) -> Result<Result<(), ApiError>, Trap> {
        if !self.can_write_to_host_buffer() {
            // Exit early if the host buffer is already occupied
            return Ok(Err(ApiError::HostBufferFull));
        }
        let key = self.key_from_mem(key_ptr, key_size)?;
        let cl_value = match self.context.read_gs(&key)? {
            Some(stored_value) => CLValue::try_from(stored_value).map_err(Error::TypeMismatch)?,
            None => return Ok(Err(ApiError::ValueNotFound)),
        };
        let value_size = cl_value.inner_bytes().len() as u32;
        if let Err(error) = self.write_host_buffer(cl_value) {
            return Ok(Err(error));
        }
        let value_bytes = value_size.to_le_bytes(); // Wasm is little-endian
        if let Err(error) = self.memory.set(output_size_ptr, &value_bytes) {
            return Err(Error::Interpreter(error.into()).into());
        }
        Ok(Ok(()))
    }
fn read ( & mut self , key_ptr : u32 , key_size : u32 , output_size_ptr : u32 , ) -> Result < Result < ( ) , ApiError > , Trap > { if ! self . can_write_to_host_buffer ( ) { // Exit early if the host buffer is already occupied return Ok ( Err ( ApiError :: HostBufferFull ) ) ; } let key = self . key_from_mem ( key_ptr , key_size ) ? ; let cl_value = match self . context . read_gs ( & key ) ? { Some ( stored_value ) => CLValue :: try_from ( stored_value ) . map_err ( Error :: TypeMismatch ) ? , None => return Ok ( Err ( ApiError :: ValueNotFound ) ) , } ; let value_size = cl_value . inner_bytes ( ) . len ( ) as u32 ; if let Err ( error ) = self . write_host_buffer ( cl_value ) { return Ok ( Err ( error ) ) ; } let value_bytes = value_size . to_le_bytes ( ) ; // Wasm is little-endian if let Err ( error ) = self . memory . set ( output_size_ptr , & value_bytes ) { return Err ( Error :: Interpreter ( error . into ( ) ) . into ( ) ) ; } Ok ( Ok ( ( ) ) ) }
Reads value from the GS living under key specified by `key_ptr` and
`key_size`.
Reads value from the GS living under key specified by ` key_ptr ` and ` key_size ` .
&mut self
key_ptr
u32
key_size
u32
output_size_ptr
u32
&mut self
key_ptr
u32
key_size
u32
output_size_ptr
u32