MySQL 8.4.2
Source Code Documentation
archive_text.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_TEXT_H
25#define MYSQL_SERIALIZATION_ARCHIVE_TEXT_H
26
27#include <sstream>
28
31
32/// @file
33/// Experimental API header
34
35/// @addtogroup GroupLibsMysqlSerialization
36/// @{
37
38namespace mysql::serialization {
39
40/// @brief Archive implementation based on stringstream
41/// @note Does not provide backward or forward compatibility, used only
42/// for printing text, debug internally
43class Archive_text : public Archive<Archive_text> {
44 public:
45 /// @copydoc Archive::operator<<
46 template <typename Field_type>
48
49 /// @copydoc Archive::operator>>
50 template <typename Field_type>
52
53 /// @copydoc Archive::get_raw_data
54 std::string get_raw_data();
55
56 /// @copydoc Archive::get_size_written
57 inline std::size_t get_size_written() const {
58 return m_stream.str().length();
59 }
60
61 // available for serializer concrete types
62
63 /// @copydoc Archive::put_field_separator
64 void put_field_separator() override;
65
66 /// @copydoc Archive::put_entry_separator
67 void put_entry_separator() override;
68
69 /// @copydoc Archive::put_level_separator
70 void put_level_separator() override;
71
72 /// @copydoc Archive::peek
73 template <class Field_type>
74 void peek(Field_type &&field);
75
76 /// @copydoc Archive::seek_to
77 void seek_to(std::size_t num_pos) {
78 std::size_t pos = m_stream.tellg();
79 m_stream.seekg(pos + num_pos, std::ios_base::beg);
80 }
81
82 /// @copydoc Archive::get_size
83 template <typename T, Field_size S>
84 static std::size_t get_size([[maybe_unused]] Field_wrapper<T, S> &&arg) {
85 return 0; // size info unused
86 }
87
88 /// @copydoc Archive::get_size
89 template <typename T, Field_size S>
90 static constexpr std::size_t get_max_size() {
91 return 0; // size info unused
92 }
93
94 /// @copydoc Archive::get_read_pos
95 inline std::size_t get_read_pos() const { return 0; }
96
97 private:
98 std::stringstream m_stream; ///< Internal data stream
99};
100
101} // namespace mysql::serialization
102
103/// @}
104
106
107#endif // MYSQL_SERIALIZATION_ARCHIVE_TEXT_H
Experimental API header.
Experimental API header.
Archive implementation based on stringstream.
Definition: archive_text.h:43
std::size_t get_read_pos() const
Gets current read pos.
Definition: archive_text.h:95
void put_entry_separator() override
This method needs to define field entry separator to be inserted after the field entry,...
Definition: archive_text.cpp:43
static constexpr std::size_t get_max_size()
Function returns size of serialized argument.
Definition: archive_text.h:90
std::stringstream m_stream
Internal data stream.
Definition: archive_text.h:98
Archive_text & operator>>(Field_type &&arg)
Reads argument from this archive.
Definition: archive_text_impl.hpp:43
static std::size_t get_size(Field_wrapper< T, S > &&arg)
Function returns size of serialized argument.
Definition: archive_text.h:84
void seek_to(std::size_t num_pos)
Moves the current read position to current position + size.
Definition: archive_text.h:77
std::size_t get_size_written() const
Returns archive size - size of data written to the archive.
Definition: archive_text.h:57
std::string get_raw_data()
Function for the API user to access data in the archive.
Definition: archive_text.cpp:30
void put_field_separator() override
This method needs to define field separator to be inserted after the field, note that some formats wo...
Definition: archive_text.cpp:32
void peek(Field_type &&field)
Peeks selected field wrapper (reads data without updating read stream position)
Definition: archive_text_impl.hpp:56
Archive_text & operator<<(Field_type &&arg)
Ingests argument into this archive.
Definition: archive_text_impl.hpp:30
void put_level_separator() override
This method needs to define level separator to be inserted after the level, note that some formats wo...
Definition: archive_text.cpp:54
Interface for archives (file archive, byte vector archive, string archive etc.), available only to in...
Definition: archive.h:50
Wrapper for fields to hold field reference and user-defined, compile-time field size.
Definition: field_wrapper.h:43
Definition: archive.h:37
Experimental API header.
Definition: sql_resultset.h:36