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