[−][src]Trait exonum::storage::StorageKey
A type that can be (de)serialized as a key in the blockchain storage.
Since keys are sorted in the serialized form, the big-endian encoding should be used with unsigned integer types. Note, however, that the big-endian encoding will not sort signed integer types in the natural order; therefore, they are mapped to the corresponding unsigned type by adding a constant to the source value.
Examples
use std::mem; use exonum::storage::StorageKey; #[derive(Clone)] struct Key { a: i16, b: u32, } impl StorageKey for Key { fn size(&self) -> usize { mem::size_of_val(&self.a) + mem::size_of_val(&self.b) } fn write(&self, buffer: &mut [u8]) { self.a.write(&mut buffer[0..2]); self.b.write(&mut buffer[2..6]); } fn read(buffer: &[u8]) -> Self { let a = i16::read(&buffer[0..2]); let b = u32::read(&buffer[2..6]); Key { a, b } } }
Required methods
fn size(&self) -> usize
Returns the size of the serialized key in bytes.
fn write(&self, buffer: &mut [u8])
Serializes the key into the specified buffer of bytes.
The caller must guarantee that the size of the buffer is equal to the precalculated size of the serialized key.
fn read(buffer: &[u8]) -> Self::Owned
Deserializes the key from the specified buffer of bytes.
Implementations on Foreign Types
impl StorageKey for ()
[src]
impl StorageKey for ()
No-op implementation.
fn size(&self) -> usize | [src] |
fn write(&self, _buffer: &mut [u8]) | [src] |
fn read(_buffer: &[u8]) -> Self::Owned | [src] |
impl StorageKey for u8
[src]
impl StorageKey for u8
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self::Owned | [src] |
impl StorageKey for i8
[src]
impl StorageKey for i8
Uses encoding with the values mapped to u8
by adding the corresponding constant (128
) to the value.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self::Owned | [src] |
impl StorageKey for u16
[src]
impl StorageKey for u16
Uses big-endian encoding.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for i16
[src]
impl StorageKey for i16
Uses big-endian encoding with the values mapped to the unsigned format by adding the corresponding constant to the value.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for u32
[src]
impl StorageKey for u32
Uses big-endian encoding.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for i32
[src]
impl StorageKey for i32
Uses big-endian encoding with the values mapped to the unsigned format by adding the corresponding constant to the value.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for u64
[src]
impl StorageKey for u64
Uses big-endian encoding.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for i64
[src]
impl StorageKey for i64
Uses big-endian encoding with the values mapped to the unsigned format by adding the corresponding constant to the value.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for Vec<u8>
[src]
impl StorageKey for Vec<u8>
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for [u8]
[src]
impl StorageKey for [u8]
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self::Owned | [src] |
impl StorageKey for String
[src]
impl StorageKey for String
Uses UTF-8 string serialization.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self::Owned | [src] |
impl StorageKey for str
[src]
impl StorageKey for str
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self::Owned | [src] |
impl StorageKey for DateTime<Utc>
[src]
impl StorageKey for DateTime<Utc>
chrono::DateTime
uses only 12 bytes in the storage. It is represented by number of seconds
since 1970-01-01 00:00:00 UTC
, which are stored in the first 8 bytes as per the StorageKey
implementation for i64
, and nanoseconds, which are stored in the remaining 4 bytes as per
the StorageKey
implementation for u32
.
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self::Owned | [src] |
impl StorageKey for Uuid
[src]
impl StorageKey for Uuid
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self::Owned | [src] |
impl StorageKey for Decimal
[src]
impl StorageKey for Decimal
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self::Owned | [src] |
Implementors
impl StorageKey for Hash
[src]
impl StorageKey for Hash
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for PublicKey
[src]
impl StorageKey for PublicKey
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for Signature
[src]
impl StorageKey for Signature
fn size(&self) -> usize | [src] |
fn write(&self, buffer: &mut [u8]) | [src] |
fn read(buffer: &[u8]) -> Self | [src] |
impl StorageKey for ProofPath
[src]
impl StorageKey for ProofPath