Storage entry - represents a single key-value pair in the database. More...
#include <storage.h>
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 |
Storage entry - represents a single key-value pair in the database.
|
inline |
Definition at line 116 of file storage.h.
References librats::BINARY, checksum, deleted, timestamp_ms, and type.
Referenced by deserialize(), deserialize(), and wins_over().
|
inline |
Definition at line 122 of file storage.h.
References calculate_checksum(), checksum, data, deleted, key, origin_peer_id, timestamp_ms, and type.
| void librats::StorageEntry::calculate_checksum | ( | ) |
Referenced by StorageEntry().
|
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.
References StorageEntry(), and data.
|
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.
References StorageEntry(), and data.
| std::vector< uint8_t > librats::StorageEntry::serialize | ( | ) | const |
| 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.
| size_t librats::StorageEntry::serialized_size | ( | ) | const |
Serialized size in bytes, without serializing.
| bool librats::StorageEntry::verify_checksum | ( | ) | const |
| bool librats::StorageEntry::wins_over | ( | const StorageEntry & | other | ) | const |
References StorageEntry().
| uint32_t librats::StorageEntry::checksum |
Definition at line 113 of file storage.h.
Referenced by StorageEntry(), and StorageEntry().
| std::vector<uint8_t> librats::StorageEntry::data |
Definition at line 110 of file storage.h.
Referenced by StorageEntry(), deserialize(), and deserialize().
| bool librats::StorageEntry::deleted |
Definition at line 114 of file storage.h.
Referenced by StorageEntry(), and StorageEntry().
| std::string librats::StorageEntry::key |
Definition at line 108 of file storage.h.
Referenced by StorageEntry().
| std::string librats::StorageEntry::origin_peer_id |
Definition at line 112 of file storage.h.
Referenced by StorageEntry().
| uint64_t librats::StorageEntry::timestamp_ms |
Definition at line 111 of file storage.h.
Referenced by StorageEntry(), and StorageEntry().
| StorageValueType librats::StorageEntry::type |
Definition at line 109 of file storage.h.
Referenced by StorageEntry(), and StorageEntry().