Struct tickv::async_ops::AsyncTicKV
source · pub struct AsyncTicKV<'a, C: FlashController<S>, const S: usize> {
pub tickv: TicKV<'a, C, S>,
/* private fields */
}
Expand description
The struct storing all of the TicKV information for the async implementation.
Fields§
§tickv: TicKV<'a, C, S>
The main TicKV struct
Implementations§
source§impl<'a, C: FlashController<S>, const S: usize> AsyncTicKV<'a, C, S>
impl<'a, C: FlashController<S>, const S: usize> AsyncTicKV<'a, C, S>
sourcepub fn new(
controller: C,
read_buffer: &'a mut [u8; S],
flash_size: usize,
) -> Self
pub fn new( controller: C, read_buffer: &'a mut [u8; S], flash_size: usize, ) -> Self
Create a new struct
C
: An implementation of the FlashController
trait
controller
: An new struct implementing FlashController
flash_size
: The total size of the flash used for TicKV
sourcepub fn initialise(&self, hashed_main_key: u64) -> Result<SuccessCode, ErrorCode>
pub fn initialise(&self, hashed_main_key: u64) -> Result<SuccessCode, ErrorCode>
This function setups the flash region to be used as a key-value store. If the region is already initialised this won’t make any changes.
hashed_main_key
: The u64 hash of the const string MAIN_KEY
.
If the specified region has not already been setup for TicKV the entire region will be erased.
On success a SuccessCode
will be returned.
On error a ErrorCode
will be returned.
sourcepub fn append_key(
&self,
hash: u64,
value: &'static mut [u8],
length: usize,
) -> Result<SuccessCode, (&'static mut [u8], ErrorCode)>
pub fn append_key( &self, hash: u64, value: &'static mut [u8], length: usize, ) -> Result<SuccessCode, (&'static mut [u8], ErrorCode)>
Appends the key/value pair to flash storage.
hash
: A hashed key. This key will be used in future to retrieve
or remove the value
.
value
: A buffer containing the data to be stored to flash.
On success nothing will be returned.
On error a ErrorCode
will be returned.
sourcepub fn get_key(
&self,
hash: u64,
buf: &'static mut [u8],
) -> Result<SuccessCode, (&'static mut [u8], ErrorCode)>
pub fn get_key( &self, hash: u64, buf: &'static mut [u8], ) -> Result<SuccessCode, (&'static mut [u8], ErrorCode)>
Retrieves the value from flash storage.
hash
: A hashed key.
buf
: A buffer to store the value to.
On success a SuccessCode
will be returned.
On error a ErrorCode
will be returned.
If a power loss occurs before success is returned the data is assumed to be lost.
sourcepub fn invalidate_key(&self, hash: u64) -> Result<SuccessCode, ErrorCode>
pub fn invalidate_key(&self, hash: u64) -> Result<SuccessCode, ErrorCode>
Invalidates the key in flash storage
hash
: A hashed key.
key
: A unhashed key. This will be hashed internally.
On success a SuccessCode
will be returned.
On error a ErrorCode
will be returned.
If a power loss occurs before success is returned the data is assumed to be lost.
sourcepub fn zeroise_key(&self, hash: u64) -> Result<SuccessCode, ErrorCode>
pub fn zeroise_key(&self, hash: u64) -> Result<SuccessCode, ErrorCode>
Zeroizes the key in flash storage
hash
: A hashed key.
key
: A unhashed key. This will be hashed internally.
On success a SuccessCode
will be returned.
On error a ErrorCode
will be returned.
If a power loss occurs before success is returned the data is assumed to be lost.
sourcepub fn garbage_collect(&self) -> Result<SuccessCode, ErrorCode>
pub fn garbage_collect(&self) -> Result<SuccessCode, ErrorCode>
Perform a garbage collection on TicKV
On success a SuccessCode
will be returned.
On error a ErrorCode
will be returned.
sourcepub fn set_read_buffer(&self, read_buffer: &[u8])
pub fn set_read_buffer(&self, read_buffer: &[u8])
Copy data from read_buffer
argument to the internal read_buffer.
This should be used to copy the data that the implementation wanted
to read when calling read_region
after the async operation has
completed.
sourcepub fn continue_operation(
&self,
) -> (Result<SuccessCode, ErrorCode>, Option<&'static mut [u8]>, usize)
pub fn continue_operation( &self, ) -> (Result<SuccessCode, ErrorCode>, Option<&'static mut [u8]>, usize)
Continue the last operation after the async operation has completed.
This should be called from a read/erase complete callback.
NOTE: If called from a read callback, set_read_buffer
should be
called first to update the data.
hash_function
: Hash function with no previous state. This is
usually a newly created hash.
Returns a tuple of 3 values
Result:
On success a SuccessCode
will be returned.
On error a ErrorCode
will be returned.
Buf Buffer:
An option of the buf buffer used
Length usize:
The number of valid bytes in the buffer. 0 if Buf is None.
The buffers will only be returned on a non async error or on success.