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/jss.h>
23 #include <ripple/protocol/STVector256.h>
24 
25 namespace ripple {
26 
28  : STBase(name)
29 {
30  Blob data = sit.getVL ();
31  auto const count = data.size () / (256 / 8);
32  mValue.reserve (count);
33  Blob::iterator begin = data.begin ();
34  unsigned int uStart = 0;
35  for (unsigned int i = 0; i != count; i++)
36  {
37  unsigned int uEnd = uStart + (256 / 8);
38  // This next line could be optimized to construct a default
39  // uint256 in the vector and then copy into it
40  mValue.push_back (uint256 (Blob (begin + uStart, begin + uEnd)));
41  uStart = uEnd;
42  }
43 }
44 
45 void
47 {
48  assert (fName->isBinary ());
49  assert (fName->fieldType == STI_VECTOR256);
50  s.addVL (mValue.begin(), mValue.end(), mValue.size () * (256 / 8));
51 }
52 
53 bool
55 {
56  const STVector256* v = dynamic_cast<const STVector256*> (&t);
57  return v && (mValue == v->mValue);
58 }
59 
62 {
64 
65  for (auto const& vEntry : mValue)
66  ret.append (to_string (vEntry));
67 
68  return ret;
69 }
70 
71 } // ripple
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::SField::isBinary
bool isBinary() const
Definition: SField.h:199
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:44
ripple::STVector256::begin
std::vector< uint256 >::iterator begin()
Definition: STVector256.h:166
std::vector< unsigned char >
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:41
ripple::SField::fieldType
const SerializedTypeID fieldType
Definition: SField.h:134
ripple::base_uint
Definition: base_uint.h:65
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:907
ripple::STVector256::add
void add(Serializer &s) const override
Definition: STVector256.cpp:46
ripple::STVector256::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STVector256.cpp:54
ripple::SerialIter
Definition: Serializer.h:311
ripple::SerialIter::getVL
Blob getVL()
Definition: Serializer.cpp:592
ripple::STI_VECTOR256
@ STI_VECTOR256
Definition: SField.h:76
ripple::STVector256::mValue
std::vector< uint256 > mValue
Definition: STVector256.h:202
ripple::Serializer
Definition: Serializer.h:43
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:112
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:65
ripple::STVector256
Definition: STVector256.h:29
ripple::Serializer::addVL
int addVL(Blob const &vector)
Definition: Serializer.cpp:208
ripple::STBase::fName
SField const * fName
Definition: STBase.h:156
ripple::STVector256::getJson
Json::Value getJson(JsonOptions) const override
Definition: STVector256.cpp:61
Json::Value
Represents a JSON value.
Definition: json_value.h:141