MySQL 8.4.0
Source Code Documentation
read_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_READ_ARCHIVE_BINARY_H
25#define MYSQL_SERIALIZATION_READ_ARCHIVE_BINARY_H
26
27#include <sstream>
28
33
34/// @file
35/// Experimental API header
36
37/// @addtogroup GroupLibsMysqlSerialization
38/// @{
39
40namespace mysql::serialization {
41
42/// @brief Binary, read only archive implementation based on vector of bytes
43class Read_archive_binary : public Archive<Read_archive_binary> {
44 public:
45 using Internal_type = const unsigned char *;
46
47 /// @copydoc Archive::operator>>
48 template <typename Field_type>
50
51 /// @copydoc Archive::get_size
52 template <typename Field_type>
53 static std::size_t get_size(Field_type &&arg) {
54 static constexpr auto value_size = Field_type::value_size;
56 return Primitive_type_codec<value_type>::template count_write_bytes<
57 value_size>(arg.get());
58 }
59
60 /// @copydoc Archive::get_max_size
61 template <typename T, Field_size S>
62 static constexpr std::size_t get_max_size() {
64 }
65
66 /// @brief Set up internal stream, this implementation of Archive does not
67 /// own memory, it just reads it
68 /// @param[in] stream Captured stream
69 /// @param[in] stream_size Size of stream
70 void set_stream(const unsigned char *stream, std::size_t stream_size) {
71 m_stream = stream;
72 m_stream_size = stream_size;
73 }
74
75 // internal
76
77 /// @copydoc Archive::get_raw_data
79
80 /// @copydoc Archive::peek
81 template <class Field_type>
82 void peek(Field_type &&field);
83
84 /// @copydoc Archive::seek_to
85 void seek_to(std::size_t num_pos) { read_pos += num_pos; }
86
87 /// @copydoc Archive::get_read_pos
88 inline std::size_t get_read_pos() const { return read_pos; }
89
90 private:
91 const unsigned char *m_stream; ///< Internal data stream
92 std::size_t read_pos{0}; ///< Read position
93 std::size_t m_stream_size{0}; /// length of m_stream
94};
95
96} // namespace mysql::serialization
97
98/// @}
99
101
102#endif // MYSQL_SERIALIZATION_READ_ARCHIVE_BINARY_H
Experimental API header.
Interface for archives (file archive, byte vector archive, string archive etc.), available only to in...
Definition: archive.h:50
Binary, read only archive implementation based on vector of bytes.
Definition: read_archive_binary.h:43
static constexpr std::size_t get_max_size()
Function returns maximum size of the Type.
Definition: read_archive_binary.h:62
std::size_t read_pos
Read position.
Definition: read_archive_binary.h:92
Read_archive_binary & operator>>(Field_type &&arg)
Reads argument from this archive.
Definition: read_archive_binary_impl.hpp:30
void seek_to(std::size_t num_pos)
Moves the current read position to current position + size.
Definition: read_archive_binary.h:85
std::size_t get_read_pos() const
Gets current read pos.
Definition: read_archive_binary.h:88
void set_stream(const 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: read_archive_binary.h:70
static std::size_t get_size(Field_type &&arg)
Function returns size of serialized argument.
Definition: read_archive_binary.h:53
std::size_t m_stream_size
Definition: read_archive_binary.h:93
void peek(Field_type &&field)
Peeks selected field wrapper (reads data without updating read stream position)
Definition: read_archive_binary_impl.hpp:49
const unsigned char * m_stream
Internal data stream.
Definition: read_archive_binary.h:91
const unsigned char * Internal_type
Definition: read_archive_binary.h:45
Internal_type & get_raw_data()
Function for the API user to access data in the archive.
Definition: read_archive_binary.cpp:30
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
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