xrpld
Loading...
Searching...
No Matches
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 <stdexcept>
13#include <string>
14#include <utility>
15
16namespace xrpl {
17
19{
20 auto const slice = sit.getSlice(sit.getVLDataLength());
21
22 if (slice.size() % uint256::size() != 0)
23 {
24 Throw<std::runtime_error>(
25 "Bad serialization for STVector256: " + std::to_string(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
36STBase*
37STVector256::copy(std::size_t n, void* buf) const
38{
39 return emplace(n, buf, *this);
40}
41
42STBase*
44{
45 return emplace(n, buf, std::move(*this));
46}
47
50{
51 return STI_VECTOR256;
52}
53
54bool
56{
57 return value_.empty();
58}
59
60void
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
68bool
70{
71 STVector256 const* v = dynamic_cast<STVector256 const*>(&t);
72 return (v != nullptr) && (value_ == v->value_);
73}
74
77{
79
80 for (auto const& vEntry : value_)
81 ret.append(to_string(vEntry));
82
83 return ret;
84}
85
86} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
Value & append(Value const &value)
Append value to array at the end.
static BaseUInt fromRaw(Container const &c)
Definition base_uint.h:294
static constexpr std::size_t size()
Definition base_uint.h:530
Identifies fields.
Definition SField.h:130
A type which can be exported to a well known binary format.
Definition STBase.h:117
SField const & getFName() const
Definition STBase.cpp:126
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:215
json::Value getJson(JsonOptions) const override
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 > value_
Definition STVector256.h:12
SerializedTypeID getSType() const override
STVector256()=default
bool isDefault() const override
STBase * copy(std::size_t n, void *buf) const override
Slice getSlice(std::size_t bytes)
int addVL(Blob const &vector)
std::size_t size() const noexcept
Returns the number of bytes in the storage.
Definition Slice.h:61
@ Array
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(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
SerializedTypeID
Definition SField.h:93
Note, should be treated as flags that can be | and &.
Definition STBase.h:17