Coverage Report

Created: 2025-09-27 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mysql-server/libs/mysql/serialization/archive_binary.h
Line
Count
Source
1
// Copyright (c) 2023, 2025, 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
29
#include "mysql/serialization/archive.h"
30
#include "mysql/serialization/archive_binary_field_max_size_calculator.h"
31
#include "mysql/serialization/primitive_type_codec.h"
32
#include "mysql/serialization/serializable_type_traits.h"
33
#include "mysql/serialization/serialization_types.h"
34
35
/// @file
36
/// Experimental API header
37
38
/// @addtogroup GroupLibsMysqlSerialization
39
/// @{
40
41
namespace mysql::serialization {
42
43
/// @brief Binary archive implementation based on vector of bytes
44
class Archive_binary : public Archive<Archive_binary> {
45
 public:
46
  /// @copydoc Archive::operator<<
47
  template <typename Field_type>
48
  Archive_binary &operator<<(Field_type &&arg);
49
50
  /// @copydoc Archive::operator>>
51
  template <typename Field_type>
52
  Archive_binary &operator>>(Field_type &&arg);
53
54
  /// @copydoc Archive::get_max_size
55
  template <typename Field_type, Field_size defined_field_size>
56
0
  static constexpr std::size_t get_max_size() {
57
0
    return Archive_binary_field_max_size_calculator<
58
0
        Field_type, defined_field_size>::get_max_size();
59
0
  }
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;
65
    using value_type = typename std::decay_t<Field_type>::value_type;
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
0
  void seek_to(std::size_t num_pos) { read_pos += num_pos; }
79
80
  /// @copydoc Archive::get_read_pos
81
0
  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
92
#include "mysql/serialization/archive_binary_impl.hpp"
93
94
#endif  // MYSQL_SERIALIZATION_ARCHIVE_BINARY_H