rippled
Public Member Functions | Private Attributes | List of all members
ripple::NodeStore::EncodedBlob Class Reference

Convert a NodeObject from in-memory to database format. More...

Collaboration diagram for ripple::NodeStore::EncodedBlob:
Collaboration graph
[legend]

Public Member Functions

 EncodedBlob (std::shared_ptr< NodeObject > const &obj)
 
 ~EncodedBlob ()
 
void const * getKey () const noexcept
 
std::size_t getSize () const noexcept
 
void const * getData () const noexcept
 

Private Attributes

std::array< std::uint8_t, 32 > key_
 The 32-byte key of the serialized object. More...
 
std::array< std::uint8_t, boost::alignment::align_up(9+1024, alignof(std::uint32_t))> payload_
 A pre-allocated buffer for the serialized object. More...
 
std::uint32_t size_
 The size of the serialized data. More...
 
std::uint8_t *const ptr_
 A pointer to the serialized data. More...
 

Detailed Description

Convert a NodeObject from in-memory to database format.

The (suboptimal) database format consists of:

Note
This class is typically instantiated on the stack, so the size of the object does not matter as much as it normally would since the allocation is, effectively, free.

We leverage that fact to preallocate enough memory to handle most payloads as part of this object, eliminating the need for dynamic allocation. As of this writing ~94% of objects require fewer than 1024 payload bytes.

Definition at line 54 of file EncodedBlob.h.

Constructor & Destructor Documentation

◆ EncodedBlob()

ripple::NodeStore::EncodedBlob::EncodedBlob ( std::shared_ptr< NodeObject > const &  obj)
explicit

Definition at line 81 of file EncodedBlob.h.

◆ ~EncodedBlob()

ripple::NodeStore::EncodedBlob::~EncodedBlob ( )

Definition at line 101 of file EncodedBlob.h.

Member Function Documentation

◆ getKey()

void const* ripple::NodeStore::EncodedBlob::getKey ( ) const
noexcept

Definition at line 112 of file EncodedBlob.h.

◆ getSize()

std::size_t ripple::NodeStore::EncodedBlob::getSize ( ) const
noexcept

Definition at line 118 of file EncodedBlob.h.

◆ getData()

void const* ripple::NodeStore::EncodedBlob::getData ( ) const
noexcept

Definition at line 124 of file EncodedBlob.h.

Member Data Documentation

◆ key_

std::array<std::uint8_t, 32> ripple::NodeStore::EncodedBlob::key_
private

The 32-byte key of the serialized object.

Definition at line 57 of file EncodedBlob.h.

◆ payload_

std::array< std::uint8_t, boost::alignment::align_up(9 + 1024, alignof(std::uint32_t))> ripple::NodeStore::EncodedBlob::payload_
private

A pre-allocated buffer for the serialized object.

The buffer is large enough for the 9 byte prefix and at least 1024 more bytes. The precise size is calculated automatically at compile time so as to avoid wasting space on padding bytes.

Definition at line 68 of file EncodedBlob.h.

◆ size_

std::uint32_t ripple::NodeStore::EncodedBlob::size_
private

The size of the serialized data.

Definition at line 71 of file EncodedBlob.h.

◆ ptr_

std::uint8_t* const ripple::NodeStore::EncodedBlob::ptr_
private

A pointer to the serialized data.

This may point to the pre-allocated buffer (if it is sufficiently large) or to a dynamically allocated buffer.

Definition at line 78 of file EncodedBlob.h.