Trait capsules_extra::tickv::KVSystem

source ·
pub trait KVSystem<'a> {
    type K: KeyType;

    // Required methods
    fn set_client(&self, client: &'a dyn KVSystemClient<Self::K>);
    fn generate_key(
        &self,
        unhashed_key: SubSliceMut<'static, u8>,
        key_buf: &'static mut Self::K,
    ) -> Result<(), (SubSliceMut<'static, u8>, &'static mut Self::K, ErrorCode)>;
    fn append_key(
        &self,
        key: &'static mut Self::K,
        value: SubSliceMut<'static, u8>,
    ) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>;
    fn get_value(
        &self,
        key: &'static mut Self::K,
        ret_buf: SubSliceMut<'static, u8>,
    ) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>;
    fn invalidate_key(
        &self,
        key: &'static mut Self::K,
    ) -> Result<(), (&'static mut Self::K, ErrorCode)>;
    fn garbage_collect(&self) -> Result<(), ErrorCode>;
}

Required Associated Types§

source

type K: KeyType

The type of the hashed key. For example [u8; 8].

Required Methods§

source

fn set_client(&self, client: &'a dyn KVSystemClient<Self::K>)

Set the client.

source

fn generate_key( &self, unhashed_key: SubSliceMut<'static, u8>, key_buf: &'static mut Self::K, ) -> Result<(), (SubSliceMut<'static, u8>, &'static mut Self::K, ErrorCode)>

Generate key.

  • unhashed_key: A unhashed key that should be hashed.
  • key_buf: A buffer to store the hashed key output.

On success returns nothing. On error the unhashed_key, key_buf and Result<(), ErrorCode> will be returned.

source

fn append_key( &self, key: &'static mut Self::K, value: SubSliceMut<'static, u8>, ) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>

Appends the key/value pair.

If the key already exists in the store and has not been invalidated then the append operation will fail. To update an existing key to a new value the key must first be invalidated.

  • key: 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 the key, value and a Result<(), ErrorCode> will be returned.

The possible Result<(), ErrorCode>s are:

  • BUSY: An operation is already in progress
  • INVAL: An invalid parameter was passed
  • NODEVICE: No KV store was setup
  • NOSUPPORT: The key could not be added due to a collision.
  • NOMEM: The key could not be added due to no more space.
source

fn get_value( &self, key: &'static mut Self::K, ret_buf: SubSliceMut<'static, u8>, ) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>

Retrieves the value from a specified key.

  • key: A hashed key. This key will be used to retrieve the value.
  • ret_buf: A buffer to store the value to.

On success nothing will be returned. On error the key, ret_buf and a Result<(), ErrorCode> will be returned.

The possible Result<(), ErrorCode>s are:

  • BUSY: An operation is already in progress
  • INVAL: An invalid parameter was passed
  • NODEVICE: No KV store was setup
  • ENOSUPPORT: The key could not be found.
  • SIZE: The value is longer than the provided buffer.
source

fn invalidate_key( &self, key: &'static mut Self::K, ) -> Result<(), (&'static mut Self::K, ErrorCode)>

Invalidates the key in flash storage.

  • key: A hashed key. This key will be used to remove the value.

On success nothing will be returned. On error the key and a Result<(), ErrorCode> will be returned.

The possible Result<(), ErrorCode>s are:

  • BUSY: An operation is already in progress
  • INVAL: An invalid parameter was passed
  • NODEVICE: No KV store was setup
  • ENOSUPPORT: The key could not be found.
source

fn garbage_collect(&self) -> Result<(), ErrorCode>

Perform a garbage collection on the KV Store.

For implementations that don’t require garbage collecting this should return Err(ErrorCode::ALREADY).

On success nothing will be returned. On error a Result<(), ErrorCode> will be returned.

The possible ErrorCodes are:

  • BUSY: An operation is already in progress.
  • ALREADY: Nothing to be done. Callback will not trigger.
  • INVAL: An invalid parameter was passed.
  • NODEVICE: No KV store was setup.

Implementors§

source§

impl<'a, F: Flash, H: Hasher<'a, 8>, const PAGE_SIZE: usize> KVSystem<'a> for TicKVSystem<'a, F, H, PAGE_SIZE>

§

type K = [u8; 8]