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 {
23 Throw<std::runtime_error>(
24 "Bad serialization for STVector256: " + std::to_string(slice.size()));
25 }
26
27 auto const cnt = slice.size() / uint256::size();
28
29 mValue.reserve(cnt);
30
31 for (std::size_t i = 0; i != cnt; ++i)
32 mValue.emplace_back(slice.substr(i * uint256::size(), uint256::size()));
33}
34
35STBase*
36STVector256::copy(std::size_t n, void* buf) const
37{
38 return emplace(n, buf, *this);
39}
40
41STBase*
43{
44 return emplace(n, buf, std::move(*this));
45}
46
49{
50 return STI_VECTOR256;
51}
52
53bool
55{
56 return mValue.empty();
57}
58
59void
61{
62 XRPL_ASSERT(getFName().isBinary(), "xrpl::STVector256::add : field is binary");
63 XRPL_ASSERT(getFName().fieldType == STI_VECTOR256, "xrpl::STVector256::add : valid field type");
64 s.addVL(mValue.begin(), mValue.end(), mValue.size() * (256 / 8));
65}
66
67bool
69{
70 STVector256 const* v = dynamic_cast<STVector256 const*>(&t);
71 return (v != nullptr) && (mValue == v->mValue);
72}
73
76{
78
79 for (auto const& vEntry : mValue)
80 ret.append(to_string(vEntry));
81
82 return ret;
83}
84
85} // 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:125
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:499
@ 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:602
SerializedTypeID
Definition SField.h:90
Note, should be treated as flags that can be | and &.
Definition STBase.h:17
T to_string(T... args)