rippled
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 <ripple/basics/Log.h>
21 #include <ripple/basics/StringUtilities.h>
22 #include <ripple/protocol/STVector256.h>
23 #include <ripple/protocol/jss.h>
24 
25 namespace 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 
44 STBase*
45 STVector256::copy(std::size_t n, void* buf) const
46 {
47  return emplace(n, buf, *this);
48 }
49 
50 STBase*
52 {
53  return emplace(n, buf, std::move(*this));
54 }
55 
58 {
59  return STI_VECTOR256;
60 }
61 
62 bool
64 {
65  return mValue.empty();
66 }
67 
68 void
70 {
71  assert(getFName().isBinary());
72  assert(getFName().fieldType == STI_VECTOR256);
73  s.addVL(mValue.begin(), mValue.end(), mValue.size() * (256 / 8));
74 }
75 
76 bool
78 {
79  const STVector256* v = dynamic_cast<const STVector256*>(&t);
80  return v && (mValue == v->mValue);
81 }
82 
84 {
86 
87  for (auto const& vEntry : mValue)
88  ret.append(to_string(vEntry));
89 
90  return ret;
91 }
92 
93 } // namespace ripple
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:104
ripple::STVector256::move
STBase * move(std::size_t n, void *buf) override
Definition: STVector256.cpp:51
ripple::STVector256::isDefault
bool isDefault() const override
Definition: STVector256.cpp:63
ripple::base_uint< 256 >::size
constexpr static std::size_t size()
Definition: base_uint.h:519
ripple::STVector256::getSType
SerializedTypeID getSType() const override
Definition: STVector256.cpp:57
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:882
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:220
ripple::STVector256::add
void add(Serializer &s) const override
Definition: STVector256.cpp:69
ripple::STVector256::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STVector256.cpp:77
std::to_string
T to_string(T... args)
ripple::SerialIter
Definition: Serializer.h:311
ripple::STVector256::mValue
std::vector< uint256 > mValue
Definition: STVector256.h:31
ripple::STBase::getFName
SField const & getFName() const
Definition: STBase.cpp:132
ripple::Serializer
Definition: Serializer.h:40
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JsonOptions
Note, should be treated as flags that can be | and &.
Definition: STBase.h:35
ripple::STVector256::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STVector256.cpp:45
ripple::STVector256::STVector256
STVector256()=default
ripple::SField
Identifies fields.
Definition: SField.h:139
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:121
ripple::SerialIter::getVLDataLength
int getVLDataLength()
Definition: Serializer.cpp:470
ripple::STVector256
Definition: STVector256.h:29
ripple::Serializer::addVL
int addVL(Blob const &vector)
Definition: Serializer.cpp:200
std::size_t
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:41
ripple::STVector256::getJson
Json::Value getJson(JsonOptions) const override
Definition: STVector256.cpp:83
ripple::SerialIter::getSlice
Slice getSlice(std::size_t bytes)
Definition: Serializer.cpp:495
Json::Value
Represents a JSON value.
Definition: json_value.h:145