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  Blob data = sit.getVL();
30  auto const count = data.size() / (256 / 8);
31  mValue.reserve(count);
32  Blob::iterator begin = data.begin();
33  unsigned int uStart = 0;
34  for (unsigned int i = 0; i != count; i++)
35  {
36  unsigned int uEnd = uStart + (256 / 8);
37  // This next line could be optimized to construct a default
38  // uint256 in the vector and then copy into it
39  mValue.push_back(uint256(Blob(begin + uStart, begin + uEnd)));
40  uStart = uEnd;
41  }
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
ripple::Blob
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition: Blob.h:30
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
std::vector< unsigned char >
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
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::STVector256::begin
std::vector< uint256 >::iterator begin()
Definition: STVector256.h:222
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:529
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:165
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
ripple::SerialIter
Definition: Serializer.h:310
ripple::SerialIter::getVL
Blob getVL()
Definition: Serializer.cpp:508
ripple::STI_VECTOR256
@ STI_VECTOR256
Definition: SField.h:75
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:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
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:109
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
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:38
ripple::STVector256::getJson
Json::Value getJson(JsonOptions) const override
Definition: STVector256.cpp:83
Json::Value
Represents a JSON value.
Definition: json_value.h:145