Trait oasis_core_runtime::common::key_format::KeyFormat

source ·
pub trait KeyFormat {
    // Required methods
    fn prefix() -> u8;
    fn size() -> usize;
    fn encode_atoms(self, atoms: &mut Vec<Vec<u8>>);
    fn decode_atoms(data: &[u8]) -> Self
       where Self: Sized;

    // Provided methods
    fn encode_partial(self, count: usize) -> Vec<u8> 
       where Self: Sized { ... }
    fn encode(self) -> Vec<u8> 
       where Self: Sized { ... }
    fn decode(data: &[u8]) -> Option<Self>
       where Self: Sized { ... }
}
Expand description

A key formatting helper trait to be used together with key-value backends for constructing keys.

Required Methods§

source

fn prefix() -> u8

The prefix that identifies the key format.

source

fn size() -> usize

The minimum size of the encoded key.

source

fn encode_atoms(self, atoms: &mut Vec<Vec<u8>>)

Encode the given key format into a set of atoms.

source

fn decode_atoms(data: &[u8]) -> Self
where Self: Sized,

Decode the given key format from data (without prefix).

The caller must ensure that the size of the passed data is at least the minimum size returned by size.

Provided Methods§

source

fn encode_partial(self, count: usize) -> Vec<u8>
where Self: Sized,

Encode the first few atoms in the key format.

This method can be used to construct key prefixes for iteration. Specifying a zero count will only generate the prefix.

source

fn encode(self) -> Vec<u8>
where Self: Sized,

Encode the given key format.

source

fn decode(data: &[u8]) -> Option<Self>
where Self: Sized,

Decode the given key format from data.

The method may return None in case the key is of a different type as indicated by the prefix byte.

Object Safety§

This trait is not object safe.

Implementors§