1#ifndef LIBFILEZILLA_BUFFER_HEADER
2#define LIBFILEZILLA_BUFFER_HEADER
27class FZ_PUBLIC_SYMBOL buffer final
30 typedef unsigned char value_type;
32 buffer()
noexcept =
default;
37 buffer(buffer
const& buf);
38 buffer(buffer && buf)
noexcept;
40 ~buffer() {
delete[] data_; }
46 unsigned char const*
get()
const {
return pos_; }
47 unsigned char* get() {
return pos_; }
50 unsigned char*
data() {
return pos_; }
51 unsigned char const* data()
const {
return pos_; }
71 unsigned char*
get(
size_t write_size);
74 void add(
size_t added);
82 template<
typename T, std::enable_if_t<std::is_
signed_v<T>,
int> = 0>
85 add(
static_cast<size_t>(added));
95 size_t size()
const {
return size_; }
107 void append(std::string_view
const& str);
108 void append(std::basic_string_view<uint8_t>
const&
data);
109 void append(std::vector<uint8_t>
const&
data);
111 void append(
unsigned char v);
112 void append(
size_t len,
unsigned char c);
114 buffer& operator+=(
unsigned char v) {
118 buffer& operator+=(std::string_view
const& str) {
122 buffer& operator+=(std::vector<uint8_t>
const& data) {
126 buffer& operator+=(fz::buffer
const& b) {
131 bool empty()
const {
return size_ == 0; }
132 explicit operator bool()
const {
136 size_t capacity()
const {
return capacity_; }
137 void reserve(
size_t capacity);
139 void resize(
size_t size);
143 unsigned char & operator[](
size_t i) {
return pos_[i]; }
145 bool operator==(buffer
const& rhs)
const;
147 bool operator!=(buffer
const& rhs)
const {
148 return !(*
this == rhs);
151 std::string_view to_view()
const;
163 unsigned char* data_{};
164 unsigned char* pos_{};
169inline void FZ_PUBLIC_SYMBOL wipe(
buffer & b) {
173inline void FZ_PUBLIC_SYMBOL wipe_unused(
buffer & b) {
The buffer class is a simple buffer where data can be appended at the end and consumed at the front....
Definition buffer.hpp:28
void add(T added)
Overload of add for signed types, only adds if value is positive.
Definition buffer.hpp:83
buffer(size_t capacity)
Initially reserves the passed capacity.
unsigned char * data()
Same as get()
Definition buffer.hpp:50
void consume(size_t consumed)
Removes consumed bytes from the beginning of the buffer.
unsigned char * get(size_t write_size)
Returns a writable buffer guaranteed to be large enough for write_size bytes, call add when done.
unsigned char const * get() const
Undefined if buffer is empty.
Definition buffer.hpp:46
void append(unsigned char const *data, size_t len)
Appends the passed data to the buffer.
unsigned char operator[](size_t i) const
Gets element at offset i. Does not do bounds checking.
Definition buffer.hpp:142
void add(size_t added)
Increase size by the passed amount. Call this after having obtained a writable buffer with get(size_t...
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition apply.hpp:17