MySQL 8.4.0
Source Code Documentation
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_ARCHIVE_BINARY_H
25#define MYSQL_SERIALIZATION_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 archive implementation based on vector of bytes
44class Archive_binary : public Archive<Archive_binary> {
45 public:
46 /// @copydoc Archive::operator<<
47 template <typename Field_type>
49
50 /// @copydoc Archive::operator>>
51 template <typename Field_type>
53
54 /// @copydoc Archive::get_max_size
55 template <typename Field_type, Field_size defined_field_size>
56 static constexpr std::size_t get_max_size() {
58 Field_type, defined_field_size>::get_max_size();
59 }
60
61 /// @copydoc Archive::get_size
62 template <typename Field_type>
63 static std::size_t get_size(Field_type &&arg) {
64 static constexpr auto value_size = Field_type::value_size;
66 return Primitive_type_codec<value_type>::template count_write_bytes<
67 value_size>(arg.get());
68 }
69
70 /// @copydoc Archive::get_raw_data
71 std::vector<unsigned char> &get_raw_data();
72
73 /// @copydoc Archive::peek
74 template <class Field_type>
75 void peek(Field_type &&field);
76
77 /// @copydoc Archive::seek_to
78 void seek_to(std::size_t num_pos) { read_pos += num_pos; }
79
80 /// @copydoc Archive::get_read_pos
81 inline std::size_t get_read_pos() const { return read_pos; }
82
83 private:
84 std::vector<unsigned char> m_stream; ///< Internal data stream
85 std::size_t read_pos{0}; ///< Read position
86};
87
88} // namespace mysql::serialization
89
90/// @}
91
93
94#endif // MYSQL_SERIALIZATION_ARCHIVE_BINARY_H
Experimental API header.
Experimental API header.
Binary archive implementation based on vector of bytes.
Definition: archive_binary.h:44
static std::size_t get_size(Field_type &&arg)
Function returns size of serialized argument.
Definition: archive_binary.h:63
std::size_t read_pos
Read position.
Definition: archive_binary.h:85
void peek(Field_type &&field)
Peeks selected field wrapper (reads data without updating read stream position)
Definition: archive_binary_impl.hpp:78
void seek_to(std::size_t num_pos)
Moves the current read position to current position + size.
Definition: archive_binary.h:78
std::size_t get_read_pos() const
Gets current read pos.
Definition: archive_binary.h:81
static constexpr std::size_t get_max_size()
Function returns maximum size of the Type.
Definition: archive_binary.h:56
std::vector< unsigned char > & get_raw_data()
Function for the API user to access data in the archive.
Definition: archive_binary.cpp:30
Archive_binary & operator>>(Field_type &&arg)
Reads argument from this archive.
Definition: archive_binary_impl.hpp:57
std::vector< unsigned char > m_stream
Internal data stream.
Definition: archive_binary.h:84
Archive_binary & operator<<(Field_type &&arg)
Ingests argument into this archive.
Definition: archive_binary_impl.hpp:30
Interface for archives (file archive, byte vector archive, string archive etc.), available only to in...
Definition: archive.h:50
uint16_t value_type
Definition: vt100.h:184
Definition: archive.h:37
Experimental API header.
Experimental API header.
Experimental API header.
Definition: sql_resultset.h:36
helper structure created for partial specialization of get_max_size function of Archive_binary,...
Definition: archive_binary_field_max_size_calculator.h:44
This class is to provide functionality to encode/decode the primitive types into/out of defined strea...
Definition: primitive_type_codec.h:113