rippled
Loading...
Searching...
No Matches
DecodedBlob.cpp
1#include <xrpl/basics/safe_cast.h>
2#include <xrpl/beast/utility/instrumentation.h>
3#include <xrpl/nodestore/detail/DecodedBlob.h>
4
5#include <algorithm>
6
7namespace ripple {
8namespace NodeStore {
9
10DecodedBlob::DecodedBlob(void const* key, void const* value, int valueBytes)
11{
12 /* Data format:
13
14 Bytes
15
16 0...7 Unused
17 8 char One of NodeObjectType
18 9...end The body of the object data
19 */
20
21 m_success = false;
22 m_key = key;
24 m_objectData = nullptr;
25 m_dataBytes = std::max(0, valueBytes - 9);
26
27 // VFALCO NOTE What about bytes 4 through 7 inclusive?
28
29 if (valueBytes > 8)
30 {
31 unsigned char const* byte = static_cast<unsigned char const*>(value);
32 m_objectType = safe_cast<NodeObjectType>(byte[8]);
33 }
34
35 if (valueBytes > 9)
36 {
37 m_objectData = static_cast<unsigned char const*>(value) + 9;
38
39 switch (m_objectType)
40 {
41 default:
42 break;
43
44 case hotUNKNOWN:
45 case hotLEDGER:
46 case hotACCOUNT_NODE:
48 m_success = true;
49 break;
50 }
51 }
52}
53
56{
57 XRPL_ASSERT(
59 "ripple::NodeStore::DecodedBlob::createObject : valid object type");
60
62
63 if (m_success)
64 {
66
68 m_objectType, std::move(data), uint256::fromVoid(m_key));
69 }
70
71 return object;
72}
73
74} // namespace NodeStore
75} // namespace ripple
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
std::shared_ptr< NodeObject > createObject()
Create a NodeObject from this data.
unsigned char const * m_objectData
Definition DecodedBlob.h:41
DecodedBlob(void const *key, void const *value, int valueBytes)
Construct the decoded blob from raw data.
static base_uint fromVoid(void const *data)
Definition base_uint.h:300
T max(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ hotACCOUNT_NODE
Definition NodeObject.h:16
@ hotTRANSACTION_NODE
Definition NodeObject.h:17
@ hotUNKNOWN
Definition NodeObject.h:14
@ hotLEDGER
Definition NodeObject.h:15