MySQL 9.1.0
Source Code Documentation
field_definition_helpers.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_FIELD_DEFINITION_HELPERS_H
25#define MYSQL_SERIALIZATION_FIELD_DEFINITION_HELPERS_H
26
31
32/// @brief helpers aimed at deducing Field_type in case size is provided,
33/// and basic field and compound field definitions
34
35/// @file
36/// Experimental API header
37
38/// @addtogroup GroupLibsMysqlSerialization
39/// @{
40
41namespace mysql::serialization {
42
43template <class Type>
44constexpr std::size_t get_default_type_size() {
45 return 0;
46}
47
48template <Field_size size, typename Field_type, typename... Args>
49auto define_field_with_size(Field_type &arg, Args &&...args) {
50 return Field_definition<Field_type, size>(arg, std::forward<Args>(args)...);
51}
52
53template <typename Field_type, typename... Args>
54auto define_field(Field_type &arg, Args &&...args) {
56 arg, std::forward<Args>(args)...);
57}
58
59template <typename Field_type, typename... Args>
60auto define_field(const Field_type &arg, Args &&...args) {
61 return Field_definition<const Field_type,
62 get_default_type_size<Field_type>()>(
63 arg, std::forward<Args>(args)...);
64}
65
66template <class Serializable_derived>
68 return std::ref(arg);
69}
70
71template <class Serializable_derived>
73 return std::cref(arg);
74}
75
76template <class Serializable_derived>
78 const Unknown_field_policy &policy) {
80 const_cast<Serializable<Serializable_derived> &>(arg);
81 n_arg.set_unknown_field_policy(policy);
82 return std::cref(arg);
83}
84
85} // namespace mysql::serialization
86
87/// @}
88
89#endif // MYSQL_SERIALIZATION_FIELD_DEFINITION_HELPERS_H
Field definition provided by classes implementing Serializable interface.
Definition: field_definition.h:45
Interface for serializable data structures.
Definition: serializable.h:86
void set_unknown_field_policy(const Unknown_field_policy &policy)
Sets unknown field policy for this object.
Definition: serializable.h:149
Experimental API header.
Experimental API header.
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
Definition: archive.h:37
auto define_field(Field_type &arg, Args &&...args)
Definition: field_definition_helpers.h:54
auto define_field_with_size(Field_type &arg, Args &&...args)
Definition: field_definition_helpers.h:49
Unknown_field_policy
Represents 'unknown field' policy - decision what needs to be done in case unknown field is encounter...
Definition: unknown_field_policy.h:39
auto define_compound_field(Serializable< Serializable_derived > &arg)
Definition: field_definition_helpers.h:67
constexpr std::size_t get_default_type_size()
Definition: field_definition_helpers.h:44
size_t size(const char *const c)
Definition: base64.h:46
Experimental API header.
Experimental API header.
Definition: sql_resultset.h:36
mysql::serialization::Field_size Field_size
Definition: tag.cpp:35