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