xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
protocol
STVector256.cpp
1
#include <xrpl/protocol/STVector256.h>
2
3
#include <xrpl/basics/base_uint.h>
4
#include <xrpl/basics/contract.h>
5
#include <xrpl/beast/utility/instrumentation.h>
6
#include <xrpl/json/json_value.h>
7
#include <xrpl/protocol/SField.h>
8
#include <xrpl/protocol/STBase.h>
9
#include <xrpl/protocol/Serializer.h>
10
11
#include <
cstddef
>
12
#include <format>
13
#include <
stdexcept
>
14
#include <
utility
>
15
16
namespace
xrpl
{
17
18
STVector256::STVector256
(
SerialIter
& sit,
SField
const
& name) :
STBase
(name)
19
{
20
auto
const
slice = sit.
getSlice
(sit.
getVLDataLength
());
21
22
if (slice.size() %
UInt256::size
() != 0)
23
{
24
Throw<std::runtime_error>(
25
std::format(
"Bad serialization for STVector256: {}"
, slice.size()));
26
}
27
28
auto
const
cnt = slice.
size
() /
UInt256::size
();
29
30
value_
.reserve(cnt);
31
32
for (
std::size_t
i = 0; i != cnt; ++i)
33
value_
.push_back(
UInt256::fromRaw
(slice.substr(i *
UInt256::size
(),
UInt256::size
())));
34
}
35
36
STBase
*
37
STVector256::copy
(
std::size_t
n,
void
* buf)
const
38
{
39
return
emplace
(n, buf, *
this
);
40
}
41
42
STBase
*
43
STVector256::move
(
std::size_t
n,
void
* buf)
44
{
45
return
emplace
(n, buf, std::move(*
this
));
46
}
47
48
SerializedTypeID
49
STVector256::getSType
()
const
50
{
51
return
STI_VECTOR256;
52
}
53
54
bool
55
STVector256::isDefault
()
const
56
{
57
return
value_
.empty();
58
}
59
60
void
61
STVector256::add
(
Serializer
& s)
const
62
{
63
XRPL_ASSERT(
getFName
().isBinary(),
"xrpl::STVector256::add : field is binary"
);
64
XRPL_ASSERT(
getFName
().fieldType == STI_VECTOR256,
"xrpl::STVector256::add : valid field type"
);
65
s.
addVL
(
value_
.begin(),
value_
.end(),
value_
.size() * (256 / 8));
66
}
67
68
bool
69
STVector256::isEquivalent
(
STBase
const
& t)
const
70
{
71
auto
const
* v =
dynamic_cast<
STVector256
const*
>
(&t);
72
return
(v !=
nullptr
) && (
value_
== v->value_);
73
}
74
75
json::Value
76
STVector256::getJson
(
JsonOptions
)
const
77
{
78
json::Value
ret(
json::ValueType::Array
);
79
80
for
(
auto
const
& vEntry :
value_
)
81
ret.
append
(
to_string
(vEntry));
82
83
return
ret;
84
}
85
86
}
// namespace xrpl
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::append
Value & append(Value const &value)
Append value to array at the end.
Definition
json_value.cpp:997
xrpl::BaseUInt< 256 >::fromRaw
static BaseUInt fromRaw(Container const &c)
Definition
base_uint.h:302
xrpl::BaseUInt< 256 >::size
static constexpr std::size_t size()
Definition
base_uint.h:548
xrpl::SField
Identifies fields.
Definition
SField.h:132
xrpl::STBase
A type which can be exported to a well known binary format.
Definition
STBase.h:129
xrpl::STBase::getFName
SField const & getFName() const
Definition
STBase.cpp:120
xrpl::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition
STBase.h:226
xrpl::STBase::STBase
STBase()
Definition
STBase.cpp:15
xrpl::STVector256::getJson
json::Value getJson(JsonOptions) const override
Definition
STVector256.cpp:76
xrpl::STVector256::add
void add(Serializer &s) const override
Definition
STVector256.cpp:61
xrpl::STVector256::isEquivalent
bool isEquivalent(STBase const &t) const override
Definition
STVector256.cpp:69
xrpl::STVector256::move
STBase * move(std::size_t n, void *buf) override
Definition
STVector256.cpp:43
xrpl::STVector256::getSType
SerializedTypeID getSType() const override
Definition
STVector256.cpp:49
xrpl::STVector256::value_
std::vector< UInt256 > value_
Definition
STVector256.h:18
xrpl::STVector256::STVector256
STVector256()=default
xrpl::STVector256::isDefault
bool isDefault() const override
Definition
STVector256.cpp:55
xrpl::STVector256::copy
STBase * copy(std::size_t n, void *buf) const override
Definition
STVector256.cpp:37
xrpl::SerialIter
Definition
Serializer.h:478
xrpl::SerialIter::getVLDataLength
int getVLDataLength()
Reads the length header at the read position and steps past it.
Definition
libxrpl/protocol/Serializer.cpp:501
xrpl::SerialIter::getSlice
Slice getSlice(std::size_t bytes)
Definition
libxrpl/protocol/Serializer.cpp:526
xrpl::Serializer
Definition
Serializer.h:23
xrpl::Serializer::addVL
int addVL(Blob const &vector)
Definition
libxrpl/protocol/Serializer.cpp:180
xrpl::Slice::size
std::size_t size() const noexcept
Returns the number of bytes in the storage.
Definition
Slice.h:70
cstddef
json::ValueType::Array
@ Array
array value (ordered list)
Definition
json_value.h:28
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::SerializedTypeID
SerializedTypeID
Definition
SField.h:94
std::size_t
stdexcept
xrpl::JsonOptions
Note, should be treated as flags that can be | and &.
Definition
STBase.h:22
utility
Generated by
1.17.0