rippled
Loading...
Searching...
No Matches
STVector256.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/basics/base_uint.h>
21#include <xrpl/basics/contract.h>
22#include <xrpl/beast/utility/instrumentation.h>
23#include <xrpl/json/json_value.h>
24#include <xrpl/protocol/SField.h>
25#include <xrpl/protocol/STBase.h>
26#include <xrpl/protocol/STVector256.h>
27#include <xrpl/protocol/Serializer.h>
28
29#include <cstddef>
30#include <stdexcept>
31#include <string>
32#include <utility>
33
34namespace ripple {
35
37{
38 auto const slice = sit.getSlice(sit.getVLDataLength());
39
40 if (slice.size() % uint256::size() != 0)
41 Throw<std::runtime_error>(
42 "Bad serialization for STVector256: " +
43 std::to_string(slice.size()));
44
45 auto const cnt = slice.size() / uint256::size();
46
47 mValue.reserve(cnt);
48
49 for (std::size_t i = 0; i != cnt; ++i)
50 mValue.emplace_back(slice.substr(i * uint256::size(), uint256::size()));
51}
52
53STBase*
54STVector256::copy(std::size_t n, void* buf) const
55{
56 return emplace(n, buf, *this);
57}
58
59STBase*
61{
62 return emplace(n, buf, std::move(*this));
63}
64
67{
68 return STI_VECTOR256;
69}
70
71bool
73{
74 return mValue.empty();
75}
76
77void
79{
80 XRPL_ASSERT(
81 getFName().isBinary(), "ripple::STVector256::add : field is binary");
82 XRPL_ASSERT(
83 getFName().fieldType == STI_VECTOR256,
84 "ripple::STVector256::add : valid field type");
85 s.addVL(mValue.begin(), mValue.end(), mValue.size() * (256 / 8));
86}
87
88bool
90{
91 STVector256 const* v = dynamic_cast<STVector256 const*>(&t);
92 return v && (mValue == v->mValue);
93}
94
97{
99
100 for (auto const& vEntry : mValue)
101 ret.append(to_string(vEntry));
102
103 return ret;
104}
105
106} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
Value & append(Value const &value)
Append value to array at the end.
Identifies fields.
Definition SField.h:146
A type which can be exported to a well known binary format.
Definition STBase.h:135
SField const & getFName() const
Definition STBase.cpp:143
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:233
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:32
Slice getSlice(std::size_t bytes)
int addVL(Blob const &vector)
static constexpr std::size_t size()
Definition base_uint.h:526
@ arrayValue
array value (ordered list)
Definition json_value.h:44
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
SerializedTypeID
Definition SField.h:110
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
Note, should be treated as flags that can be | and &.
Definition STBase.h:37
T to_string(T... args)