rippled
Loading...
Searching...
No Matches
STBlob.h
1#ifndef XRPL_PROTOCOL_STBLOB_H_INCLUDED
2#define XRPL_PROTOCOL_STBLOB_H_INCLUDED
3
4#include <xrpl/basics/Buffer.h>
5#include <xrpl/basics/CountedObject.h>
6#include <xrpl/basics/Slice.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/protocol/STBase.h>
9
10#include <cstring>
11
12namespace ripple {
13
14// variable length byte string
15class STBlob : public STBase, public CountedObject<STBlob>
16{
18
19public:
21
22 STBlob() = default;
23 STBlob(STBlob const& rhs);
24
25 STBlob(SField const& f, void const* data, std::size_t size);
26 STBlob(SField const& f, Buffer&& b);
27 STBlob(SField const& n);
28 STBlob(SerialIter&, SField const& name = sfGeneric);
29
31 size() const;
32
33 std::uint8_t const*
34 data() const;
35
37 getSType() const override;
38
40 getText() const override;
41
42 void
43 add(Serializer& s) const override;
44
45 bool
46 isEquivalent(STBase const& t) const override;
47
48 bool
49 isDefault() const override;
50
51 STBlob&
52 operator=(Slice const& slice);
53
55 value() const noexcept;
56
57 STBlob&
58 operator=(Buffer&& buffer);
59
60 void
61 setValue(Buffer&& b);
62
63private:
64 STBase*
65 copy(std::size_t n, void* buf) const override;
66 STBase*
67 move(std::size_t n, void* buf) override;
68
69 friend class detail::STVar;
70};
71
72inline STBlob::STBlob(STBlob const& rhs)
73 : STBase(rhs), CountedObject<STBlob>(rhs), value_(rhs.data(), rhs.size())
74{
75}
76
77inline STBlob::STBlob(SField const& f, void const* data, std::size_t size)
78 : STBase(f), value_(data, size)
79{
80}
81
82inline STBlob::STBlob(SField const& f, Buffer&& b)
83 : STBase(f), value_(std::move(b))
84{
85}
86
87inline STBlob::STBlob(SField const& n) : STBase(n)
88{
89}
90
91inline std::size_t
93{
94 return value_.size();
95}
96
97inline std::uint8_t const*
99{
100 return reinterpret_cast<std::uint8_t const*>(value_.data());
101}
102
103inline STBlob&
105{
106 value_ = Buffer(slice.data(), slice.size());
107 return *this;
108}
109
111STBlob::value() const noexcept
112{
113 return value_;
114}
115
116inline STBlob&
118{
119 value_ = std::move(buffer);
120 return *this;
121}
122
123inline void
125{
126 value_ = std::move(b);
127}
128
129} // namespace ripple
130
131#endif
Like std::vector<char> but better.
Definition Buffer.h:17
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
Definition Buffer.h:108
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Definition Buffer.h:132
Tracks the number of instances of an object.
Identifies fields.
Definition SField.h:127
A type which can be exported to a well known binary format.
Definition STBase.h:116
SerializedTypeID getSType() const override
Definition STBlob.cpp:32
STBlob & operator=(Slice const &slice)
Definition STBlob.h:104
value_type value() const noexcept
Definition STBlob.h:111
std::uint8_t const * data() const
Definition STBlob.h:98
void setValue(Buffer &&b)
Definition STBlob.h:124
friend class detail::STVar
Definition STBlob.h:69
bool isEquivalent(STBase const &t) const override
Definition STBlob.cpp:55
std::size_t size() const
Definition STBlob.h:92
STBase * move(std::size_t n, void *buf) override
Definition STBlob.cpp:26
STBlob()=default
void add(Serializer &s) const override
Definition STBlob.cpp:44
Buffer value_
Definition STBlob.h:17
STBase * copy(std::size_t n, void *buf) const override
Definition STBlob.cpp:20
bool isDefault() const override
Definition STBlob.cpp:62
std::string getText() const override
Definition STBlob.cpp:38
An immutable linear range of bytes.
Definition Slice.h:27
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Definition Slice.h:79
std::size_t size() const noexcept
Returns the number of bytes in the storage.
Definition Slice.h:62
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
SerializedTypeID
Definition SField.h:91
SField const sfGeneric
STL namespace.