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 void
46 {
47  assert(fName->isBinary());
48  assert(fName->fieldType == STI_VECTOR256);
49  s.addVL(mValue.begin(), mValue.end(), mValue.size() * (256 / 8));
50 }
51 
52 bool
54 {
55  const STVector256* v = dynamic_cast<const STVector256*>(&t);
56  return v && (mValue == v->mValue);
57 }
58 
60 {
62 
63  for (auto const& vEntry : mValue)
64  ret.append(to_string(vEntry));
65 
66  return ret;
67 }
68 
69 } // 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
ripple::SField::isBinary
bool isBinary() const
Definition: SField.h:210
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
ripple::STVector256::begin
std::vector< uint256 >::iterator begin()
Definition: STVector256.h:164
std::vector< unsigned char >
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:529
ripple::SField::fieldType
const SerializedTypeID fieldType
Definition: SField.h:127
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:882
ripple::STVector256::add
void add(Serializer &s) const override
Definition: STVector256.cpp:45
ripple::STVector256::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STVector256.cpp:53
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:200
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::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:62
ripple::STVector256
Definition: STVector256.h:29
ripple::Serializer::addVL
int addVL(Blob const &vector)
Definition: Serializer.cpp:200
ripple::STBase::fName
SField const * fName
Definition: STBase.h:145
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:59
Json::Value
Represents a JSON value.
Definition: json_value.h:145