MySQL 9.1.0
Source Code Documentation
write_archive_binary.h
Go to the documentation of this file.
1// Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
24#ifndef MYSQL_SERIALIZATION_WRITE_ARCHIVE_BINARY_H
25#define MYSQL_SERIALIZATION_WRITE_ARCHIVE_BINARY_H
26
27#include <sstream>
28
34
35/// @file
36/// Experimental API header
37
38/// @addtogroup GroupLibsMysqlSerialization
39/// @{
40
41namespace mysql::serialization {
42
43/// @brief Binary, write only archive implementation based on vector of bytes
44class Write_archive_binary : public Archive<Write_archive_binary> {
45 public:
46 using Internal_type = unsigned char *;
47
48 /// @copydoc Archive::operator<<
49 template <typename Field_type>
51
52 /// @copydoc Archive::get_size
53 template <typename Field_type>
54 static std::size_t get_size(Field_type &&arg) {
55 static constexpr auto value_size = Field_type::value_size;
57 return Primitive_type_codec<value_type>::template count_write_bytes<
58 value_size>(arg.get());
59 }
60
61 /// @copydoc Archive::get_max_size
62 template <typename T, Field_size S>
63 static constexpr std::size_t get_max_size() {
65 }
66
67 /// @copydoc Archive::get_size_written
68 std::size_t get_size_written() const;
69
70 /// @brief Set up internal stream, this implementation of Archive does not
71 /// own memory, it just reads it
72 /// @param[in] stream Captured stream
73 /// @param[in] stream_size Size of stream
74 void set_stream(unsigned char *stream, std::size_t stream_size) {
75 m_stream = stream;
76 m_stream_size = stream_size;
77 }
78
79 // internal
80
81 /// @copydoc Archive::get_raw_data
83
84 /// @copydoc Archive::peek_type_field_id
86
87 private:
88 /// @brief Internal function used to check whether writing is possible
89 /// @param bytes Requested number of bytes
90 /// @retval true Writing of requested number of bytes is possible
91 /// @retval false Cannot write requested number of bytes
92 bool can_write(size_t bytes) const;
93
94 Internal_type m_stream; ///< Internal data stream
95 std::size_t m_stream_size{0}; ///< Internal data stream size
96 std::size_t m_write_pos{0}; ///< Write position
97};
98
99} // namespace mysql::serialization
100
101/// @}
102
104
105#endif // MYSQL_SERIALIZATION_WRITE_ARCHIVE_BINARY_H
Experimental API header.
Experimental API header.
Interface for archives (file archive, byte vector archive, string archive etc.), available only to in...
Definition: archive.h:50
Binary, write only archive implementation based on vector of bytes.
Definition: write_archive_binary.h:44
Field_id_type peek_type_field_id()
This method decodes field id, without moving stream positions.
Internal_type m_stream
Internal data stream.
Definition: write_archive_binary.h:94
Write_archive_binary & operator<<(Field_type &&arg)
Ingests argument into this archive.
Definition: write_archive_binary_impl.hpp:30
static std::size_t get_size(Field_type &&arg)
Function returns size of serialized argument.
Definition: write_archive_binary.h:54
std::size_t m_write_pos
Write position.
Definition: write_archive_binary.h:96
unsigned char * Internal_type
Definition: write_archive_binary.h:46
std::size_t get_size_written() const
Returns archive size - size of data written to the archive.
Definition: write_archive_binary.cpp:39
static constexpr std::size_t get_max_size()
Function returns maximum size of the Type.
Definition: write_archive_binary.h:63
void set_stream(unsigned char *stream, std::size_t stream_size)
Set up internal stream, this implementation of Archive does not own memory, it just reads it.
Definition: write_archive_binary.h:74
Internal_type & get_raw_data()
Function for the API user to access data in the archive.
Definition: write_archive_binary.cpp:30
std::size_t m_stream_size
Internal data stream size.
Definition: write_archive_binary.h:95
bool can_write(size_t bytes) const
Internal function used to check whether writing is possible.
Definition: write_archive_binary.cpp:34
uint16_t value_type
Definition: vt100.h:184
Definition: archive.h:37
uint64_t Field_id_type
Type for field_id assigned to each field in the.
Definition: serialization_types.h:42
Experimental API header.
Experimental API header.
Definition: sql_resultset.h:36
static constexpr std::size_t get_max_size()
Calculates maximum encoded size of the fixed-length integer and floating point fields.
Definition: archive_binary_field_max_size_calculator.h:48
This class is to provide functionality to encode/decode the primitive types into/out of defined strea...
Definition: primitive_type_codec.h:113
Experimental API header.