MySQL 9.1.0
Source Code Documentation
io_buffer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_HTTP_INCLUDE_HTTP_BASE_IO_BUFFER_H_
27#define ROUTER_SRC_HTTP_INCLUDE_HTTP_BASE_IO_BUFFER_H_
28
29#include <my_inttypes.h>
30
31#include <algorithm>
32#include <string>
33#include <utility>
34#include <vector>
35
37
38namespace http {
39namespace base {
40
42 public:
43 using CIterator = std::string::const_iterator;
44 IOBuffer() = default;
45 IOBuffer(const char *data, size_t length) : content_{data, length} {}
46
47 IOBuffer(std::string value) : content_{std::move(value)} {}
48
49 virtual ~IOBuffer();
50
51 virtual void clear() { content_.clear(); }
52 virtual size_t length() const { return content_.length(); }
53 virtual CIterator begin() const { return content_.begin(); }
54 virtual CIterator end() const { return content_.end(); }
55
56 virtual std::vector<uint8_t> pop_front(size_t size) {
57 std::vector<uint8_t> result;
58
59 if (size > content_.length()) size = content_.length();
60
61 result.assign(content_.begin(), content_.begin() + size);
62
63 content_.erase(0, size);
64
65 return result;
66 }
67
68 virtual std::vector<uint8_t> copy(size_t size) const {
69 std::vector<uint8_t> result;
70
71 if (size > content_.length()) size = content_.length();
72
73 result.assign(content_.begin(), content_.begin() + size);
74
75 return result;
76 }
77
78 virtual void add(const char *data, size_t length) {
79 content_.append(data, length);
80 }
81
82 virtual const std::string &get() const { return content_; }
83 virtual std::string &get() { return content_; }
84
85 private:
86 std::string content_;
87};
88
89} // namespace base
90} // namespace http
91
92#endif // ROUTER_SRC_HTTP_INCLUDE_HTTP_BASE_IO_BUFFER_H_
Definition: io_buffer.h:41
virtual const std::string & get() const
Definition: io_buffer.h:82
virtual size_t length() const
Definition: io_buffer.h:52
virtual CIterator begin() const
Definition: io_buffer.h:53
virtual CIterator end() const
Definition: io_buffer.h:54
virtual std::vector< uint8_t > pop_front(size_t size)
Definition: io_buffer.h:56
virtual void add(const char *data, size_t length)
Definition: io_buffer.h:78
std::string::const_iterator CIterator
Definition: io_buffer.h:43
IOBuffer(std::string value)
Definition: io_buffer.h:47
virtual std::vector< uint8_t > copy(size_t size) const
Definition: io_buffer.h:68
std::string content_
Definition: io_buffer.h:86
IOBuffer(const char *data, size_t length)
Definition: io_buffer.h:45
virtual void clear()
Definition: io_buffer.h:51
virtual std::string & get()
Definition: io_buffer.h:83
#define HTTP_COMMON_EXPORT
Definition: http_common_export.h:15
Some integer typedefs for easier portability.
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Definition: connection.h:56
size_t size(const char *const c)
Definition: base64.h:46
Definition: gcs_xcom_synode.h:64
struct result result
Definition: result.h:34
Definition: result.h:30