|
| 1 | +// Copyright (c) 2023-2024 Percona 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 distributed in the hope that it will be useful, |
| 8 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | +// GNU General Public License, version 2.0, for more details. |
| 11 | +// |
| 12 | +// You should have received a copy of the GNU General Public License |
| 13 | +// along with this program; if not, write to the Free Software |
| 14 | +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 | + |
| 16 | +#include "binsrv/event/previous_gtids_log_body_impl.hpp" |
| 17 | + |
| 18 | +#include <cstddef> |
| 19 | +#include <iterator> |
| 20 | +#include <ostream> |
| 21 | +#include <span> |
| 22 | +#include <string> |
| 23 | + |
| 24 | +#include <boost/lexical_cast.hpp> |
| 25 | + |
| 26 | +#include "binsrv/event/code_type.hpp" |
| 27 | + |
| 28 | +#include "binsrv/gtids/common_types.hpp" |
| 29 | +#include "binsrv/gtids/gtid_set.hpp" |
| 30 | + |
| 31 | +#include "util/byte_span.hpp" |
| 32 | +#include "util/byte_span_extractors.hpp" |
| 33 | + |
| 34 | +namespace binsrv::event { |
| 35 | + |
| 36 | +generic_body_impl<code_type::previous_gtids_log>::generic_body_impl( |
| 37 | + util::const_byte_span portion) { |
| 38 | + // TODO: rework with direct member initialization |
| 39 | + |
| 40 | + auto remainder = portion; |
| 41 | + const std::size_t gtids_size{std::size(remainder)}; |
| 42 | + gtids_.resize(gtids_size); |
| 43 | + const std::span<gtids::gtid_set_storage::value_type> gtids_range{gtids_}; |
| 44 | + util::extract_byte_span_from_byte_span(remainder, gtids_range); |
| 45 | +} |
| 46 | + |
| 47 | +[[nodiscard]] gtids::gtid_set |
| 48 | +generic_body_impl<code_type::previous_gtids_log>::get_gtids() const { |
| 49 | + return gtids::gtid_set{gtids_}; |
| 50 | +} |
| 51 | + |
| 52 | +[[nodiscard]] std::string |
| 53 | +generic_body_impl<code_type::previous_gtids_log>::get_readable_gtids() const { |
| 54 | + return boost::lexical_cast<std::string>(get_gtids()); |
| 55 | +} |
| 56 | + |
| 57 | +std::ostream & |
| 58 | +operator<<(std::ostream &output, |
| 59 | + const generic_body_impl<code_type::previous_gtids_log> &obj) { |
| 60 | + return output << "gtid_set: " << obj.get_readable_gtids(); |
| 61 | +} |
| 62 | + |
| 63 | +} // namespace binsrv::event |
0 commit comments