MySQL 8.4.0
Source Code Documentation
flexible_buffer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 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_OPENSSL_INCLUDE_TLS_DETAILS_FLEXIBLE_BUFFER_H_
27#define ROUTER_SRC_OPENSSL_INCLUDE_TLS_DETAILS_FLEXIBLE_BUFFER_H_
28
30
31namespace net {
32namespace tls {
33
35 public:
36 FlexibleBuffer() noexcept {}
37 FlexibleBuffer(void *p, size_t n) noexcept
38 : data_{p}, size_{0}, full_size_{n} {}
40 data_ = fb.data_;
41 size_ = fb.size_;
42 full_size_ = fb.full_size_;
43
44 fb.size_ = fb.full_size_ = 0;
45 fb.data_ = nullptr;
46 }
47 FlexibleBuffer(const FlexibleBuffer &fb) noexcept {
48 data_ = fb.data_;
49 size_ = fb.size_;
50 full_size_ = fb.full_size_;
51 }
52
54 : data_{b.data()}, size_{0}, full_size_{b.size()} {}
55
56 void *data_used() const noexcept { return data_; }
57 void *data_free() const { return reinterpret_cast<uint8_t *>(data_) + size_; }
58 size_t size_free() const { return full_size_ - size_; }
59 size_t size_used() const { return size_; }
60 size_t size_full() const { return full_size_; }
61
62 void reset() { size_ = 0; }
63
64 const FlexibleBuffer *begin() const { return this; }
65 const FlexibleBuffer *end() const { return this + 1; }
66
67 bool pop(size_t v) noexcept {
68 if (size_ >= v) {
69 size_ -= v;
70 memmove(data_, reinterpret_cast<uint8_t *>(data_) + v, size_);
71 return true;
72 }
73
74 size_ = 0;
75 return false;
76 }
77
78 bool push(size_t v) noexcept {
79 size_ += v;
80 if (size_ <= full_size_) return true;
82 return false;
83 }
84
85 protected:
86 void *data_{nullptr};
87 size_t size_{0};
88 size_t full_size_{0};
89};
90
92 public:
94
95 const FlexibleOutputBuffer *begin() const { return this; }
96 const FlexibleOutputBuffer *end() const { return this + 1; }
97
98 void *data() const noexcept { return data_; }
99 size_t size() const noexcept { return size_used(); }
100
101 // Return only the data that were pushed to the buffer
102 operator net::const_buffer() const { return net::buffer(data_, size_); }
103};
104
106 public:
108 const FlexibleInputBuffer *begin() const { return this; }
109 const FlexibleInputBuffer *end() const { return this + 1; }
110
111 void *data() const noexcept { return data_free(); }
112 size_t size() const noexcept { return size_free(); }
113
114 // Return the data that are not used inside the buffer
115 operator net::mutable_buffer() const {
116 return net::buffer(reinterpret_cast<char *>(data_free()), size_free());
117 }
118};
119
120} // namespace tls
121} // namespace net
122
123#endif // ROUTER_SRC_OPENSSL_INCLUDE_TLS_DETAILS_FLEXIBLE_BUFFER_H_
Definition: buffer.h:135
Definition: buffer.h:113
Definition: flexible_buffer.h:34
FlexibleBuffer(const net::mutable_buffer &b) noexcept
Definition: flexible_buffer.h:53
size_t size_used() const
Definition: flexible_buffer.h:59
bool pop(size_t v) noexcept
Definition: flexible_buffer.h:67
const FlexibleBuffer * begin() const
Definition: flexible_buffer.h:64
void * data_
Definition: flexible_buffer.h:86
void * data_free() const
Definition: flexible_buffer.h:57
FlexibleBuffer() noexcept
Definition: flexible_buffer.h:36
FlexibleBuffer(FlexibleBuffer &&fb) noexcept
Definition: flexible_buffer.h:39
size_t full_size_
Definition: flexible_buffer.h:88
void * data_used() const noexcept
Definition: flexible_buffer.h:56
FlexibleBuffer(const FlexibleBuffer &fb) noexcept
Definition: flexible_buffer.h:47
bool push(size_t v) noexcept
Definition: flexible_buffer.h:78
size_t size_
Definition: flexible_buffer.h:87
void reset()
Definition: flexible_buffer.h:62
size_t size_full() const
Definition: flexible_buffer.h:60
const FlexibleBuffer * end() const
Definition: flexible_buffer.h:65
size_t size_free() const
Definition: flexible_buffer.h:58
FlexibleBuffer(void *p, size_t n) noexcept
Definition: flexible_buffer.h:37
Definition: flexible_buffer.h:105
const FlexibleInputBuffer * begin() const
Definition: flexible_buffer.h:108
void * data() const noexcept
Definition: flexible_buffer.h:111
const FlexibleInputBuffer * end() const
Definition: flexible_buffer.h:109
size_t size() const noexcept
Definition: flexible_buffer.h:112
Definition: flexible_buffer.h:91
size_t size() const noexcept
Definition: flexible_buffer.h:99
const FlexibleOutputBuffer * end() const
Definition: flexible_buffer.h:96
const FlexibleOutputBuffer * begin() const
Definition: flexible_buffer.h:95
void * data() const noexcept
Definition: flexible_buffer.h:98
const char * p
Definition: ctype-mb.cc:1235
Definition: buffer.h:45
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Definition: tls_keylog_dumper.h:32
int n
Definition: xcom_base.cc:509