Back to Site
Loading...
Searching...
No Matches
librats::StorageEntry Struct Reference

Storage entry - represents a single key-value pair in the database. More...

#include <storage.h>

Collaboration diagram for librats::StorageEntry:
[legend]

Public Member Functions

 StorageEntry ()
 
 StorageEntry (const std::string &k, StorageValueType t, const std::vector< uint8_t > &d, uint64_t ts, const std::string &peer_id)
 
void calculate_checksum ()
 
bool verify_checksum () const
 
std::vector< uint8_t > serialize () const
 
void serialize_into (std::vector< uint8_t > &out) const
 Append the serialized entry to out.
 
size_t serialized_size () const
 Serialized size in bytes, without serializing.
 
bool wins_over (const StorageEntry &other) const
 

Static Public Member Functions

static bool deserialize (const uint8_t *data, size_t size, size_t offset, StorageEntry &entry, size_t &bytes_read)
 Deserialize one entry from data[offset..], setting bytes_read to the bytes it consumed.
 
static bool deserialize (const std::vector< uint8_t > &data, size_t offset, StorageEntry &entry, size_t &bytes_read)
 Vector overload of the above; the wire path uses the pointer form to parse straight out of the receive buffer without copying it first.
 

Public Attributes

std::string key
 
StorageValueType type
 
std::vector< uint8_t > data
 
uint64_t timestamp_ms
 
std::string origin_peer_id
 
uint32_t checksum
 
bool deleted
 

Detailed Description

Storage entry - represents a single key-value pair in the database.

Definition at line 107 of file storage.h.

Constructor & Destructor Documentation

◆ StorageEntry() [1/2]

librats::StorageEntry::StorageEntry ( )
inline

Definition at line 116 of file storage.h.

References librats::BINARY.

◆ StorageEntry() [2/2]

librats::StorageEntry::StorageEntry ( const std::string &  k,
StorageValueType  t,
const std::vector< uint8_t > &  d,
uint64_t  ts,
const std::string &  peer_id 
)
inline

Definition at line 122 of file storage.h.

Member Function Documentation

◆ calculate_checksum()

void librats::StorageEntry::calculate_checksum ( )

◆ deserialize() [1/2]

static bool librats::StorageEntry::deserialize ( const std::vector< uint8_t > &  data,
size_t  offset,
StorageEntry entry,
size_t &  bytes_read 
)
static

Vector overload of the above; the wire path uses the pointer form to parse straight out of the receive buffer without copying it first.

◆ deserialize() [2/2]

static bool librats::StorageEntry::deserialize ( const uint8_t *  data,
size_t  size,
size_t  offset,
StorageEntry entry,
size_t &  bytes_read 
)
static

Deserialize one entry from data[offset..], setting bytes_read to the bytes it consumed.

Every field is bounds-checked against the entry's own declared length as well as the buffer, so a hostile length can neither read past the buffer nor reach into the entry that follows.

◆ serialize()

std::vector< uint8_t > librats::StorageEntry::serialize ( ) const

◆ serialize_into()

void librats::StorageEntry::serialize_into ( std::vector< uint8_t > &  out) const

Append the serialized entry to out.

What serialize() is built on: a batch appends entry after entry into one buffer instead of allocating a vector per entry only to copy it away again.

◆ serialized_size()

size_t librats::StorageEntry::serialized_size ( ) const

Serialized size in bytes, without serializing.

◆ verify_checksum()

bool librats::StorageEntry::verify_checksum ( ) const

◆ wins_over()

bool librats::StorageEntry::wins_over ( const StorageEntry other) const

Member Data Documentation

◆ checksum

uint32_t librats::StorageEntry::checksum

Definition at line 113 of file storage.h.

◆ data

std::vector<uint8_t> librats::StorageEntry::data

Definition at line 110 of file storage.h.

◆ deleted

bool librats::StorageEntry::deleted

Definition at line 114 of file storage.h.

◆ key

std::string librats::StorageEntry::key

Definition at line 108 of file storage.h.

◆ origin_peer_id

std::string librats::StorageEntry::origin_peer_id

Definition at line 112 of file storage.h.

◆ timestamp_ms

uint64_t librats::StorageEntry::timestamp_ms

Definition at line 111 of file storage.h.

◆ type

StorageValueType librats::StorageEntry::type

Definition at line 109 of file storage.h.


The documentation for this struct was generated from the following file: