MySQL 9.1.0
Source Code Documentation
write_archive_binary_impl.hpp
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/// @file
25/// Experimental API header
26
27namespace mysql::serialization {
28
29template <typename Field_type>
31 static constexpr auto value_size = Field_type::value_size;
33 if (is_good() == true) {
34 bool is_error = true;
35 auto bytes_needed =
37 if (can_write(bytes_needed)) {
38 auto bytes_written =
39 Primitive_type_codec<value_type>::template write_bytes<value_size>(
40 m_stream + m_write_pos, arg.get());
41 is_error = bytes_written == 0;
42 m_write_pos += bytes_written;
43 }
44 if (is_error) {
46 __FILE__, __LINE__, "Unable to write data to the stream",
48 return *this;
49 }
50 }
51 return *this;
52}
53
54} // namespace mysql::serialization
bool is_good() const
Definition: archive.h:190
Serialization_error m_error
Holds information about error.
Definition: archive.h:197
bool is_error() const
Definition: archive.h:189
Error used internally in serialization framework.
Definition: serialization_error.h:43
Binary, write only archive implementation based on vector of bytes.
Definition: write_archive_binary.h:44
Internal_type m_stream
Internal data stream.
Definition: write_archive_binary.h:94
Write_archive_binary & operator<<(Field_type &&arg)
Ingests argument into this archive.
Definition: write_archive_binary_impl.hpp:30
std::size_t m_write_pos
Write position.
Definition: write_archive_binary.h:96
bool can_write(size_t bytes) const
Internal function used to check whether writing is possible.
Definition: write_archive_binary.cpp:34
uint16_t value_type
Definition: vt100.h:184
Definition: archive.h:37
@ archive_write_error
Cannot write data to the stream.
Definition: sql_resultset.h:36
static size_t count_write_bytes(const Type &)
Calculates bytes needed to encode the field.
Definition: primitive_type_codec.h:96
This class is to provide functionality to encode/decode the primitive types into/out of defined strea...
Definition: primitive_type_codec.h:113