rippled
Loading...
Searching...
No Matches
EncodedBlob.h
1#ifndef XRPL_NODESTORE_ENCODEDBLOB_H_INCLUDED
2#define XRPL_NODESTORE_ENCODEDBLOB_H_INCLUDED
3
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/nodestore/NodeObject.h>
6
7#include <boost/align/align_up.hpp>
8
9#include <algorithm>
10#include <array>
11#include <cstdint>
12
13namespace ripple {
14namespace NodeStore {
15
37{
40
49 boost::alignment::align_up(9 + 1024, alignof(std::uint32_t))>
51
54
61
62public:
64 : size_([&obj]() {
65 XRPL_ASSERT(
66 obj,
67 "ripple::NodeStore::EncodedBlob::EncodedBlob : non-null input");
68
69 if (!obj)
71 "EncodedBlob: unseated std::shared_ptr used.");
72
73 return obj->getData().size() + 9;
74 }())
75 , ptr_(
77 : new std::uint8_t[size_])
78 {
80 ptr_[8] = static_cast<std::uint8_t>(obj->getType());
81 std::copy_n(obj->getData().data(), obj->getData().size(), ptr_ + 9);
82 std::copy_n(obj->getHash().data(), obj->getHash().size(), key_.data());
83 }
84
86 {
87 XRPL_ASSERT(
88 ((ptr_ == payload_.data()) && (size_ <= payload_.size())) ||
89 ((ptr_ != payload_.data()) && (size_ > payload_.size())),
90 "ripple::NodeStore::EncodedBlob::~EncodedBlob : valid payload "
91 "pointer");
92
93 if (ptr_ != payload_.data())
94 delete[] ptr_;
95 }
96
97 [[nodiscard]] void const*
98 getKey() const noexcept
99 {
100 return static_cast<void const*>(key_.data());
101 }
102
103 [[nodiscard]] std::size_t
104 getSize() const noexcept
105 {
106 return size_;
107 }
108
109 [[nodiscard]] void const*
110 getData() const noexcept
111 {
112 return static_cast<void const*>(ptr_);
113 }
114};
115
116} // namespace NodeStore
117} // namespace ripple
118
119#endif
Convert a NodeObject from in-memory to database format.
Definition EncodedBlob.h:37
std::uint8_t *const ptr_
A pointer to the serialized data.
Definition EncodedBlob.h:60
EncodedBlob(std::shared_ptr< NodeObject > const &obj)
Definition EncodedBlob.h:63
std::array< std::uint8_t, boost::alignment::align_up(9+1024, alignof(std::uint32_t))> payload_
A pre-allocated buffer for the serialized object.
Definition EncodedBlob.h:50
std::uint32_t size_
The size of the serialized data.
Definition EncodedBlob.h:53
void const * getKey() const noexcept
Definition EncodedBlob.h:98
std::array< std::uint8_t, 32 > key_
The 32-byte key of the serialized object.
Definition EncodedBlob.h:39
std::size_t getSize() const noexcept
void const * getData() const noexcept
T copy_n(T... args)
T data(T... args)
T fill_n(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
STL namespace.
T size(T... args)