rippled
Loading...
Searching...
No Matches
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 <xrpl/basics/StringUtilities.h>
21#include <xrpl/protocol/STBlob.h>
22
23namespace ripple {
24
26 : STBase(name), value_(st.getVLBuffer())
27{
28}
29
30STBase*
31STBlob::copy(std::size_t n, void* buf) const
32{
33 return emplace(n, buf, *this);
34}
35
36STBase*
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
54void
56{
57 XRPL_ASSERT(getFName().isBinary(), "ripple::STBlob::add : field is binary");
58 XRPL_ASSERT(
59 (getFName().fieldType == STI_VL) ||
60 (getFName().fieldType == STI_ACCOUNT),
61 "ripple::STBlob::add : valid field type");
62 s.addVL(value_.data(), value_.size());
63}
64
65bool
67{
68 const STBlob* v = dynamic_cast<const STBlob*>(&t);
69 return v && (value_ == v->value_);
70}
71
72bool
74{
75 return value_.empty();
76}
77
78} // namespace ripple
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
Definition: Buffer.h:127
bool empty() const noexcept
Definition: Buffer.h:133
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Definition: Buffer.h:151
Identifies fields.
Definition: SField.h:144
A type which can be exported to a well known binary format.
Definition: STBase.h:124
SField const & getFName() const
Definition: STBase.cpp:134
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:222
SerializedTypeID getSType() const override
Definition: STBlob.cpp:43
bool isEquivalent(const STBase &t) const override
Definition: STBlob.cpp:66
STBase * move(std::size_t n, void *buf) override
Definition: STBlob.cpp:37
STBlob()=default
void add(Serializer &s) const override
Definition: STBlob.cpp:55
Buffer value_
Definition: STBlob.h:37
STBase * copy(std::size_t n, void *buf) const override
Definition: STBlob.cpp:31
bool isDefault() const override
Definition: STBlob.cpp:73
std::string getText() const override
Definition: STBlob.cpp:49
int addVL(Blob const &vector)
Definition: Serializer.cpp:177
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
SerializedTypeID
Definition: SField.h:108
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30