rippled
Loading...
Searching...
No Matches
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 <xrpld/nodestore/detail/DecodedBlob.h>
21
22#include <xrpl/basics/safe_cast.h>
23#include <xrpl/beast/utility/instrumentation.h>
24
25#include <algorithm>
26
27namespace ripple {
28namespace NodeStore {
29
30DecodedBlob::DecodedBlob(void const* key, void const* value, int valueBytes)
31{
32 /* Data format:
33
34 Bytes
35
36 0...7 Unused
37 8 char One of NodeObjectType
38 9...end The body of the object data
39 */
40
41 m_success = false;
42 m_key = key;
44 m_objectData = nullptr;
45 m_dataBytes = std::max(0, valueBytes - 9);
46
47 // VFALCO NOTE What about bytes 4 through 7 inclusive?
48
49 if (valueBytes > 8)
50 {
51 unsigned char const* byte = static_cast<unsigned char const*>(value);
52 m_objectType = safe_cast<NodeObjectType>(byte[8]);
53 }
54
55 if (valueBytes > 9)
56 {
57 m_objectData = static_cast<unsigned char const*>(value) + 9;
58
59 switch (m_objectType)
60 {
61 default:
62 break;
63
64 case hotUNKNOWN:
65 case hotLEDGER:
66 case hotACCOUNT_NODE:
68 m_success = true;
69 break;
70 }
71 }
72}
73
76{
77 XRPL_ASSERT(
79 "ripple::NodeStore::DecodedBlob::createObject : valid object type");
80
82
83 if (m_success)
84 {
86
88 m_objectType, std::move(data), uint256::fromVoid(m_key));
89 }
90
91 return object;
92}
93
94} // namespace NodeStore
95} // 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:60
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:319
T max(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ hotACCOUNT_NODE
Definition NodeObject.h:35
@ hotTRANSACTION_NODE
Definition NodeObject.h:36
@ hotUNKNOWN
Definition NodeObject.h:33
@ hotLEDGER
Definition NodeObject.h:34