Splitting db_val implementation for blocks in to its own template implementation file.

This commit is contained in:
Colin LeMahieu 2024-03-07 02:16:01 +00:00
commit 6f36c9790b
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
5 changed files with 44 additions and 25 deletions

View file

@ -5,6 +5,7 @@ add_library(
component.hpp component.hpp
confirmation_height.hpp confirmation_height.hpp
db_val.hpp db_val.hpp
db_val_impl.hpp
iterator.hpp iterator.hpp
iterator_impl.hpp iterator_impl.hpp
final.hpp final.hpp

View file

@ -9,6 +9,11 @@
#include <cstddef> #include <cstddef>
namespace nano
{
class block;
}
namespace nano::store namespace nano::store
{ {
/** /**
@ -92,15 +97,7 @@ public:
static_assert (std::is_standard_layout<nano::endpoint_key>::value, "Standard layout is required"); static_assert (std::is_standard_layout<nano::endpoint_key>::value, "Standard layout is required");
} }
db_val (std::shared_ptr<nano::block> const & val_a) : db_val (std::shared_ptr<nano::block> const & val_a);
buffer (std::make_shared<std::vector<uint8_t>> ())
{
{
nano::vectorstream stream (*buffer);
nano::serialize_block (stream, *val_a);
}
convert_buffer_to_value ();
}
db_val (uint64_t val_a) : db_val (uint64_t val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ()) buffer (std::make_shared<std::vector<uint8_t>> ())
@ -209,16 +206,7 @@ public:
return result; return result;
} }
explicit operator block_w_sideband () const explicit operator block_w_sideband () const;
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
nano::store::block_w_sideband block_w_sideband;
block_w_sideband.block = (nano::deserialize_block (stream));
auto error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ());
release_assert (!error);
block_w_sideband.block->sideband_set (block_w_sideband.sideband);
return block_w_sideband;
}
explicit operator std::nullptr_t () const explicit operator std::nullptr_t () const
{ {
@ -230,12 +218,7 @@ public:
return no_value::dummy; return no_value::dummy;
} }
explicit operator std::shared_ptr<nano::block> () const explicit operator std::shared_ptr<nano::block> () const;
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
std::shared_ptr<nano::block> result (nano::deserialize_block (stream));
return result;
}
template <typename Block> template <typename Block>
std::shared_ptr<Block> convert_to_block () const std::shared_ptr<Block> convert_to_block () const

View file

@ -0,0 +1,33 @@
#include <nano/lib/blocks.hpp>
#include <nano/store/db_val.hpp>
template <typename T>
nano::store::db_val<T>::db_val (std::shared_ptr<nano::block> const & val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ())
{
{
nano::vectorstream stream (*buffer);
nano::serialize_block (stream, *val_a);
}
convert_buffer_to_value ();
}
template <typename T>
nano::store::db_val<T>::operator std::shared_ptr<nano::block> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
std::shared_ptr<nano::block> result (nano::deserialize_block (stream));
return result;
}
template <typename T>
nano::store::db_val<T>::operator nano::store::block_w_sideband () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
nano::store::block_w_sideband block_w_sideband;
block_w_sideband.block = (nano::deserialize_block (stream));
auto error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ());
release_assert (!error);
block_w_sideband.block->sideband_set (block_w_sideband.sideband);
return block_w_sideband;
}

View file

@ -1,4 +1,5 @@
#include <nano/secure/parallel_traversal.hpp> #include <nano/secure/parallel_traversal.hpp>
#include <nano/store/db_val_impl.hpp>
#include <nano/store/lmdb/block.hpp> #include <nano/store/lmdb/block.hpp>
#include <nano/store/lmdb/lmdb.hpp> #include <nano/store/lmdb/lmdb.hpp>

View file

@ -1,4 +1,5 @@
#include <nano/secure/parallel_traversal.hpp> #include <nano/secure/parallel_traversal.hpp>
#include <nano/store/db_val_impl.hpp>
#include <nano/store/rocksdb/block.hpp> #include <nano/store/rocksdb/block.hpp>
#include <nano/store/rocksdb/rocksdb.hpp> #include <nano/store/rocksdb/rocksdb.hpp>