xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
nodestore
DecodedBlob.cpp
1
#include <xrpl/nodestore/detail/DecodedBlob.h>
2
3
#include <xrpl/basics/Blob.h>
4
#include <xrpl/basics/base_uint.h>
5
#include <xrpl/basics/safe_cast.h>
6
#include <xrpl/beast/utility/instrumentation.h>
7
#include <xrpl/nodestore/NodeObject.h>
8
9
#include <
algorithm
>
10
#include <
memory
>
11
#include <
utility
>
12
13
namespace
xrpl::node_store
{
14
15
DecodedBlob::DecodedBlob
(
void
const
* key,
void
const
* value,
int
valueBytes) :
key_
(key)
16
{
17
/* Data format:
18
19
Bytes
20
21
0...7 Unused
22
8 char One of NodeObjectType
23
9...end The body of the object data
24
*/
25
26
dataBytes_
=
std::max
(0, valueBytes - 9);
27
28
// VFALCO NOTE What about bytes 4 through 7 inclusive?
29
30
if
(valueBytes > 8)
31
{
32
auto
const
*
byte
=
static_cast<
unsigned
char
const*
>
(value);
33
objectType_
=
safeCast<NodeObjectType>
(
byte
[8]);
34
}
35
36
if
(valueBytes > 9)
37
{
38
objectData_
=
static_cast<
unsigned
char
const*
>
(value) + 9;
39
40
switch
(
objectType_
)
41
{
42
default
:
43
break
;
44
45
case
NodeObjectType::Unknown
:
46
case
NodeObjectType::Ledger
:
47
case
NodeObjectType::AccountNode
:
48
case
NodeObjectType::TransactionNode
:
49
success_
=
true
;
50
break
;
51
}
52
}
53
}
54
55
std::shared_ptr<NodeObject>
56
DecodedBlob::createObject
()
57
{
58
XRPL_ASSERT(
success_
,
"xrpl::node_store::DecodedBlob::createObject : valid object type"
);
59
60
std::shared_ptr<NodeObject>
object;
61
62
if
(
success_
)
63
{
64
Blob
data(
objectData_
,
objectData_
+
dataBytes_
);
65
66
object
=
NodeObject::createObject
(
objectType_
, std::move(data),
UInt256::fromVoid
(
key_
));
67
}
68
69
return
object;
70
}
71
72
}
// namespace xrpl::node_store
algorithm
xrpl::BaseUInt< 256 >::fromVoid
static BaseUInt fromVoid(void const *data)
Definition
base_uint.h:339
xrpl::NodeObject::createObject
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, UInt256 const &hash)
Create an object from fields.
Definition
NodeObject.cpp:19
xrpl::node_store::DecodedBlob::objectType_
NodeObjectType objectType_
Definition
DecodedBlob.h:47
xrpl::node_store::DecodedBlob::key_
void const * key_
Definition
DecodedBlob.h:46
xrpl::node_store::DecodedBlob::DecodedBlob
DecodedBlob(void const *key, void const *value, int valueBytes)
Construct the decoded blob from raw data.
Definition
DecodedBlob.cpp:15
xrpl::node_store::DecodedBlob::objectData_
unsigned char const * objectData_
Definition
DecodedBlob.h:48
xrpl::node_store::DecodedBlob::dataBytes_
int dataBytes_
Definition
DecodedBlob.h:49
xrpl::node_store::DecodedBlob::success_
bool success_
Definition
DecodedBlob.h:44
xrpl::node_store::DecodedBlob::createObject
std::shared_ptr< NodeObject > createObject()
Create a NodeObject from this data.
Definition
DecodedBlob.cpp:56
std::max
T max(T... args)
memory
xrpl::node_store
Definition
ServiceRegistry.h:18
xrpl::NodeObjectType::Ledger
@ Ledger
Definition
NodeObject.h:20
xrpl::NodeObjectType::Unknown
@ Unknown
Definition
NodeObject.h:19
xrpl::NodeObjectType::AccountNode
@ AccountNode
Definition
NodeObject.h:21
xrpl::NodeObjectType::TransactionNode
@ TransactionNode
Definition
NodeObject.h:22
xrpl::safeCast
constexpr Dest safeCast(Src s) noexcept
Definition
safe_cast.h:21
xrpl::Blob
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition
Blob.h:11
std::shared_ptr
utility
Generated by
1.17.0