rippled
Loading...
Searching...
No Matches
STVector256.cpp
1#include <xrpl/basics/base_uint.h>
2#include <xrpl/basics/contract.h>
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/json/json_value.h>
5#include <xrpl/protocol/SField.h>
6#include <xrpl/protocol/STBase.h>
7#include <xrpl/protocol/STVector256.h>
8#include <xrpl/protocol/Serializer.h>
9
10#include <cstddef>
11#include <stdexcept>
12#include <string>
13#include <utility>
14
15namespace xrpl {
16
18{
19 auto const slice = sit.getSlice(sit.getVLDataLength());
20
21 if (slice.size() % uint256::size() != 0)
22 Throw<std::runtime_error>("Bad serialization for STVector256: " + std::to_string(slice.size()));
23
24 auto const cnt = slice.size() / uint256::size();
25
26 mValue.reserve(cnt);
27
28 for (std::size_t i = 0; i != cnt; ++i)
29 mValue.emplace_back(slice.substr(i * uint256::size(), uint256::size()));
30}
31
32STBase*
33STVector256::copy(std::size_t n, void* buf) const
34{
35 return emplace(n, buf, *this);
36}
37
38STBase*
40{
41 return emplace(n, buf, std::move(*this));
42}
43
46{
47 return STI_VECTOR256;
48}
49
50bool
52{
53 return mValue.empty();
54}
55
56void
58{
59 XRPL_ASSERT(getFName().isBinary(), "xrpl::STVector256::add : field is binary");
60 XRPL_ASSERT(getFName().fieldType == STI_VECTOR256, "xrpl::STVector256::add : valid field type");
61 s.addVL(mValue.begin(), mValue.end(), mValue.size() * (256 / 8));
62}
63
64bool
66{
67 STVector256 const* v = dynamic_cast<STVector256 const*>(&t);
68 return v && (mValue == v->mValue);
69}
70
73{
75
76 for (auto const& vEntry : mValue)
77 ret.append(to_string(vEntry));
78
79 return ret;
80}
81
82} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
Value & append(Value const &value)
Append value to array at the end.
Identifies fields.
Definition SField.h:126
A type which can be exported to a well known binary format.
Definition STBase.h:115
SField const & getFName() const
Definition STBase.cpp:122
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:213
void add(Serializer &s) const override
bool isEquivalent(STBase const &t) const override
STBase * move(std::size_t n, void *buf) override
std::vector< uint256 > mValue
Definition STVector256.h:12
SerializedTypeID getSType() const override
STVector256()=default
bool isDefault() const override
STBase * copy(std::size_t n, void *buf) const override
Json::Value getJson(JsonOptions) const override
Slice getSlice(std::size_t bytes)
int addVL(Blob const &vector)
static constexpr std::size_t size()
Definition base_uint.h:494
@ arrayValue
array value (ordered list)
Definition json_value.h:25
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:597
SerializedTypeID
Definition SField.h:90
Note, should be treated as flags that can be | and &.
Definition STBase.h:17
T to_string(T... args)