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)
72 : STBase(rhs), CountedObject<STBlob>(rhs), value_(rhs.data(), rhs.size())
73{
74}
75
76inline STBlob::STBlob(SField const& f, void const* data, std::size_t size)
77 : STBase(f), value_(data, size)
78{
79}
80
81inline STBlob::STBlob(SField const& f, Buffer&& b) : STBase(f), value_(std::move(b))
82{
83}
84
85inline STBlob::STBlob(SField const& n) : STBase(n)
86{
87}
88
89inline std::size_t
91{
92 return value_.size();
93}
94
95inline std::uint8_t const*
97{
98 return reinterpret_cast<std::uint8_t const*>(value_.data());
99}
100
101inline STBlob&
103{
104 value_ = Buffer(slice.data(), slice.size());
105 return *this;
106}
107
109STBlob::value() const noexcept
110{
111 return value_;
112}
113
114inline STBlob&
116{
117 value_ = std::move(buffer);
118 return *this;
119}
120
121inline void
123{
124 value_ = std::move(b);
125}
126
127} // 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:90
bool isEquivalent(STBase const &t) const override
Definition STBlob.cpp:53
std::uint8_t const * data() const
Definition STBlob.h:96
void setValue(Buffer &&b)
Definition STBlob.h:122
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:109
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:102
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:78
std::size_t size() const noexcept
Returns the number of bytes in the storage.
Definition Slice.h:61
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