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 ripple {
16
18{
19 auto const slice = sit.getSlice(sit.getVLDataLength());
20
21 if (slice.size() % uint256::size() != 0)
22 Throw<std::runtime_error>(
23 "Bad serialization for STVector256: " +
24 std::to_string(slice.size()));
25
26 auto const cnt = slice.size() / uint256::size();
27
28 mValue.reserve(cnt);
29
30 for (std::size_t i = 0; i != cnt; ++i)
31 mValue.emplace_back(slice.substr(i * uint256::size(), uint256::size()));
32}
33
34STBase*
35STVector256::copy(std::size_t n, void* buf) const
36{
37 return emplace(n, buf, *this);
38}
39
40STBase*
42{
43 return emplace(n, buf, std::move(*this));
44}
45
48{
49 return STI_VECTOR256;
50}
51
52bool
54{
55 return mValue.empty();
56}
57
58void
60{
61 XRPL_ASSERT(
62 getFName().isBinary(), "ripple::STVector256::add : field is binary");
63 XRPL_ASSERT(
64 getFName().fieldType == STI_VECTOR256,
65 "ripple::STVector256::add : valid field type");
66 s.addVL(mValue.begin(), mValue.end(), mValue.size() * (256 / 8));
67}
68
69bool
71{
72 STVector256 const* v = dynamic_cast<STVector256 const*>(&t);
73 return v && (mValue == v->mValue);
74}
75
78{
80
81 for (auto const& vEntry : mValue)
82 ret.append(to_string(vEntry));
83
84 return ret;
85}
86
87} // namespace ripple
Represents a JSON value.
Definition json_value.h:131
Value & append(Value const &value)
Append value to array at the end.
Identifies fields.
Definition SField.h:127
A type which can be exported to a well known binary format.
Definition STBase.h:116
SField const & getFName() const
Definition STBase.cpp:124
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:214
void add(Serializer &s) const override
SerializedTypeID getSType() const override
Json::Value getJson(JsonOptions) const override
STBase * copy(std::size_t n, void *buf) const override
bool isDefault() 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:13
Slice getSlice(std::size_t bytes)
int addVL(Blob const &vector)
static constexpr std::size_t size()
Definition base_uint.h:507
@ arrayValue
array value (ordered list)
Definition json_value.h:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
SerializedTypeID
Definition SField.h:91
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
Note, should be treated as flags that can be | and &.
Definition STBase.h:18
T to_string(T... args)