rippled
ripple
nodestore
impl
DecodedBlob.cpp
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of rippled: https://github.com/ripple/rippled
4
Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6
Permission to use, copy, modify, and/or distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
//==============================================================================
19
20
#include <ripple/basics/safe_cast.h>
21
#include <ripple/nodestore/impl/DecodedBlob.h>
22
#include <
algorithm
>
23
#include <
cassert
>
24
25
namespace
ripple
{
26
namespace
NodeStore {
27
28
DecodedBlob::DecodedBlob
(
void
const
* key,
void
const
* value,
int
valueBytes)
29
{
30
/* Data format:
31
32
Bytes
33
34
0...7 Unused
35
8 char One of NodeObjectType
36
9...end The body of the object data
37
*/
38
39
m_success
=
false
;
40
m_key
= key;
41
m_objectType
=
hotUNKNOWN
;
42
m_objectData
=
nullptr
;
43
m_dataBytes
=
std::max
(0, valueBytes - 9);
44
45
// VFALCO NOTE What about bytes 4 through 7 inclusive?
46
47
if
(valueBytes > 8)
48
{
49
unsigned
char
const
*
byte
=
static_cast<
unsigned
char
const*
>
(value);
50
m_objectType
= safe_cast<NodeObjectType>(
byte
[8]);
51
}
52
53
if
(valueBytes > 9)
54
{
55
m_objectData
=
static_cast<
unsigned
char
const*
>
(value) + 9;
56
57
switch
(
m_objectType
)
58
{
59
default
:
60
break
;
61
62
case
hotUNKNOWN
:
63
case
hotLEDGER
:
64
case
hotACCOUNT_NODE
:
65
case
hotTRANSACTION_NODE
:
66
m_success
=
true
;
67
break
;
68
}
69
}
70
}
71
72
std::shared_ptr<NodeObject>
73
DecodedBlob::createObject
()
74
{
75
assert(
m_success
);
76
77
std::shared_ptr<NodeObject>
object;
78
79
if
(
m_success
)
80
{
81
Blob
data(
m_objectData
,
m_objectData
+
m_dataBytes
);
82
83
object
=
NodeObject::createObject
(
84
m_objectType
, std::move(data),
uint256::fromVoid
(
m_key
));
85
}
86
87
return
object;
88
}
89
90
}
// namespace NodeStore
91
}
// namespace ripple
ripple::hotUNKNOWN
@ hotUNKNOWN
Definition:
NodeObject.h:33
std::shared_ptr< NodeObject >
ripple::NodeStore::DecodedBlob::m_key
void const * m_key
Definition:
DecodedBlob.h:58
ripple::NodeStore::DecodedBlob::m_success
bool m_success
Definition:
DecodedBlob.h:56
ripple::hotACCOUNT_NODE
@ hotACCOUNT_NODE
Definition:
NodeObject.h:35
std::vector< unsigned char >
ripple::NodeStore::DecodedBlob::m_objectData
unsigned char const * m_objectData
Definition:
DecodedBlob.h:60
ripple::NodeObject::createObject
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
Definition:
NodeObject.cpp:37
ripple::hotTRANSACTION_NODE
@ hotTRANSACTION_NODE
Definition:
NodeObject.h:36
algorithm
ripple::NodeStore::DecodedBlob::createObject
std::shared_ptr< NodeObject > createObject()
Create a NodeObject from this data.
Definition:
DecodedBlob.cpp:73
ripple::NodeStore::DecodedBlob::m_dataBytes
int m_dataBytes
Definition:
DecodedBlob.h:61
ripple::NodeStore::DecodedBlob::m_objectType
NodeObjectType m_objectType
Definition:
DecodedBlob.h:59
ripple::NodeStore::DecodedBlob::DecodedBlob
DecodedBlob(void const *key, void const *value, int valueBytes)
Construct the decoded blob from raw data.
Definition:
DecodedBlob.cpp:28
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::base_uint< 256 >::fromVoid
static base_uint fromVoid(void const *data)
Definition:
base_uint.h:312
cassert
ripple::hotLEDGER
@ hotLEDGER
Definition:
NodeObject.h:34
std::max
T max(T... args)
Generated by
1.8.17