MySQL 9.6.0
Source Code Documentation
fixstr_binary_basic.h
Go to the documentation of this file.
1// Copyright (c) 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_STRCONV_CONV_FIXSTR_BINARY_BASIC_H
25#define MYSQL_STRCONV_CONV_FIXSTR_BINARY_BASIC_H
26
27/// @file
28/// Experimental API header
29
30#include <string_view> // string_view
31#include "mysql/strconv/decode/parser.h" // Parser
32#include "mysql/strconv/encode/string_target.h" // Is_string_target
33#include "mysql/strconv/formats/fixstr_binary_format.h" // Fixstr_binary_format
34
35/// @addtogroup GroupLibsMysqlStrconv
36/// @{
37
38namespace mysql::strconv {
39
40/// Parse a string in fixed-length format into @c out, advance the position, and
41/// return the status. The length is not encoded in the input string; it is a
42/// nonstatic member of the format.
43///
44/// @param format Type tag to identify that this relates to fixed-width binary
45/// format
46///
47/// @param[in,out] parser Parser position and parser.
48///
49/// @param[out] out Reference to string_view, which will be altered to point
50/// directly into the input string.
52 std::string_view &out) {
53 if (parser.remaining_size() < format.m_string_size) {
55 parser.set_parse_error("Expected more characters");
56 return;
57 }
58 out = std::string_view(parser.pos(), format.m_string_size);
59 parser.advance(format.m_string_size);
60}
61
62/// Parse a string in fixed-length format into @c out, advance the position, and
63/// return the status. The length is not encoded in the input string; it is a
64/// nonstatic member of the format.
65///
66/// @param format Type tag to identify that this relates to fixed-width binary
67/// format
68///
69/// @param[in,out] parser Parser position and parser.
70///
71/// @param[out] out Output string wrapper to store into.
73 Is_string_target auto &out) {
74 std::string_view sv;
76 out.write_raw(sv);
77}
78
79} // namespace mysql::strconv
80
81// addtogroup GroupLibsMysqlStrconv
82/// @}
83
84#endif // ifndef MYSQL_STRCONV_CONV_FIXSTR_BINARY_BASIC_H
Object used to parse strings.
Definition: parser.h:69
Return_status_t read(const Is_parse_options auto &opt, Object_t &obj)
Parse into the given object.
Definition: parser.h:225
void set_parse_error(const std::string_view &message)
Store a result representing that the requested object could not be parsed because the string is wrong...
Definition: parser.h:94
void advance(std::ptrdiff_t delta)
Move the iterator delta steps.
Definition: parse_position.h:79
std::size_t remaining_size() const
Return the remaining size.
Definition: parse_position.h:153
const char * pos() const
Return the current position as a char pointer.
Definition: parse_position.h:110
Concept that holds for String_counter and String_writer.
Definition: string_target.h:111
Experimental API header.
struct Parser parser
std::string format(const routing_guidelines::Session_info &session_info, bool extended_session_info)
Definition: dest_metadata_cache.cc:170
Definition: gtid_binary_format.h:41
void decode_impl(const Gtid_binary_format &format, Parser &parser, mysql::gtids::Is_tag auto &tag)
Definition: gtid_binary_format_conv.h:63
@ ok
operation succeeded
Experimental API header.
Experimental API header.
Format tag to identify fixed-length-string binary format.
Definition: fixstr_binary_format.h:38