MySQL 8.4.0
Source Code Documentation
archive_binary_field_max_size_calculator.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_FIELD_MAX_SIZE_CALCULATOR_H
25#define MYSQL_SERIALIZATION_ARCHIVE_BINARY_FIELD_MAX_SIZE_CALCULATOR_H
26
27#include <sstream>
28
32
33/// @file
34/// Experimental API header
35
36/// @addtogroup GroupLibsMysqlSerialization
37/// @{
38
39namespace mysql::serialization {
40
41/// @brief helper structure created for partial specialization of get_max_size
42/// function of Archive_binary, default version
43template <class T, Field_size S>
45 /// @brief Calculates maximum encoded size of the fixed-length integer and
46 /// floating point fields
47 /// @return maximum encoded byte length
48 static constexpr std::size_t get_max_size() { return S; }
49};
50
51/// @brief helper structure created for partial specialization of get_max_size
52/// function of Archive_binary, specialization for defined size equal to 0.
53/// 0 means default maximum size: for std::string default maximum size is
54/// unlimited, for variable length integer - sizeof(Type)+1, for double Type
55/// it equals to sizeof(Type)
56/// For unlimited strings, get_max_size is disabled (code won't compile)
57/// @tparam T type of field
58template <class T>
60 /// @brief Calculates maximum encoded size of the
61 /// variable-length integer fields
62 /// @return maximum encoded byte length
63 template <typename = std::enable_if_t<is_string_type<T>() == false>>
64 static constexpr std::size_t get_max_size() {
65 return sizeof(T) + is_integral_type<T>(); // + 1 for variable length
66 }
67};
68
69/// @brief helper structure created for partial specialization of get_max_size
70/// function of Archive_binary, version for std::string fields
71/// @tparam S Bound size for the string field
72template <Field_size S>
74 /// @brief Calculates maximum encoded size of the bounded
75 /// std::string field
76 /// @return maximum encoded byte length
77 static constexpr std::size_t get_max_size() {
80 }
81};
82
83} // namespace mysql::serialization
84
85/// @}
86
87#endif // MYSQL_SERIALIZATION_ARCHIVE_BINARY_FIELD_MAX_SIZE_CALCULATOR_H
Definition: archive.h:37
Definition: gcs_xcom_synode.h:64
Experimental API header.
Experimental API header.
Experimental API header.
static constexpr std::size_t get_max_size()
Calculates maximum encoded size of the variable-length integer fields.
Definition: archive_binary_field_max_size_calculator.h:64
static constexpr std::size_t get_max_size()
Calculates maximum encoded size of the bounded std::string field.
Definition: archive_binary_field_max_size_calculator.h:77
helper structure created for partial specialization of get_max_size function of Archive_binary,...
Definition: archive_binary_field_max_size_calculator.h:44
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