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/strHex.h>
21#include <xrpl/beast/utility/instrumentation.h>
22#include <xrpl/protocol/SField.h>
23#include <xrpl/protocol/STBase.h>
24#include <xrpl/protocol/STBlob.h>
25#include <xrpl/protocol/Serializer.h>
26
27#include <cstddef>
28#include <string>
29#include <utility>
30
31namespace ripple {
32
34 : STBase(name), value_(st.getVLBuffer())
35{
36}
37
38STBase*
39STBlob::copy(std::size_t n, void* buf) const
40{
41 return emplace(n, buf, *this);
42}
43
44STBase*
46{
47 return emplace(n, buf, std::move(*this));
48}
49
52{
53 return STI_VL;
54}
55
58{
59 return strHex(value_);
60}
61
62void
64{
65 XRPL_ASSERT(getFName().isBinary(), "ripple::STBlob::add : field is binary");
66 XRPL_ASSERT(
67 (getFName().fieldType == STI_VL) ||
68 (getFName().fieldType == STI_ACCOUNT),
69 "ripple::STBlob::add : valid field type");
70 s.addVL(value_.data(), value_.size());
71}
72
73bool
75{
76 STBlob const* v = dynamic_cast<STBlob const*>(&t);
77 return v && (value_ == v->value_);
78}
79
80bool
82{
83 return value_.empty();
84}
85
86} // namespace ripple
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
Definition: Buffer.h:126
bool empty() const noexcept
Definition: Buffer.h:132
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Definition: Buffer.h:150
Identifies fields.
Definition: SField.h:143
A type which can be exported to a well known binary format.
Definition: STBase.h:136
SField const & getFName() const
Definition: STBase.cpp:141
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:234
SerializedTypeID getSType() const override
Definition: STBlob.cpp:51
bool isEquivalent(STBase const &t) const override
Definition: STBlob.cpp:74
STBase * move(std::size_t n, void *buf) override
Definition: STBlob.cpp:45
STBlob()=default
void add(Serializer &s) const override
Definition: STBlob.cpp:63
Buffer value_
Definition: STBlob.h:37
STBase * copy(std::size_t n, void *buf) const override
Definition: STBlob.cpp:39
bool isDefault() const override
Definition: STBlob.cpp:81
std::string getText() const override
Definition: STBlob.cpp:57
int addVL(Blob const &vector)
Definition: Serializer.cpp:190
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
SerializedTypeID
Definition: SField.h:107
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30