rippled
STBlob.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/StringUtilities.h>
21 #include <ripple/protocol/STBlob.h>
22 
23 namespace ripple {
24 
25 STBlob::STBlob(SerialIter& st, SField const& name)
26  : STBase(name), value_(st.getVLBuffer())
27 {
28 }
29 
30 STBase*
31 STBlob::copy(std::size_t n, void* buf) const
32 {
33  return emplace(n, buf, *this);
34 }
35 
36 STBase*
38 {
39  return emplace(n, buf, std::move(*this));
40 }
41 
44 {
45  return STI_VL;
46 }
47 
50 {
51  return strHex(value_);
52 }
53 
54 void
56 {
57  assert(getFName().isBinary());
58  assert(
59  (getFName().fieldType == STI_VL) ||
60  (getFName().fieldType == STI_ACCOUNT));
61  s.addVL(value_.data(), value_.size());
62 }
63 
64 bool
66 {
67  const STBlob* v = dynamic_cast<const STBlob*>(&t);
68  return v && (value_ == v->value_);
69 }
70 
71 bool
73 {
74  return value_.empty();
75 }
76 
77 } // namespace ripple
ripple::STBlob::STBlob
STBlob()=default
std::string
STL class.
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::Buffer::empty
bool empty() const noexcept
Definition: Buffer.h:132
ripple::STI_ACCOUNT
@ STI_ACCOUNT
Definition: SField.h:65
ripple::STBlob::value_
Buffer value_
Definition: STBlob.h:35
ripple::STBlob::getText
std::string getText() const override
Definition: STBlob.cpp:49
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:165
ripple::STBlob::getSType
SerializedTypeID getSType() const override
Definition: STBlob.cpp:43
ripple::STBlob::add
void add(Serializer &s) const override
Definition: STBlob.cpp:55
ripple::STBlob::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STBlob.cpp:31
ripple::STI_VL
@ STI_VL
Definition: SField.h:64
ripple::Buffer::size
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
Definition: Buffer.h:126
ripple::SerialIter
Definition: Serializer.h:310
ripple::Buffer::data
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Definition: Buffer.h:150
ripple::STBlob::isDefault
bool isDefault() const override
Definition: STBlob.cpp:72
ripple::STBase::getFName
SField const & getFName() const
Definition: STBase.cpp:132
ripple::STBlob::move
STBase * move(std::size_t n, void *buf) override
Definition: STBlob.cpp:37
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::SField
Identifies fields.
Definition: SField.h:112
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
ripple::STBlob::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STBlob.cpp:65
ripple::Serializer::addVL
int addVL(Blob const &vector)
Definition: Serializer.cpp:200
std::size_t
ripple::strHex
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30
ripple::STBlob
Definition: STBlob.h:33