MySQL  8.0.27
Source Code Documentation
rpl_record.h
Go to the documentation of this file.
1 /* Copyright (c) 2007, 2021, 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 also distributed 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 included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef RPL_RECORD_H
24 #define RPL_RECORD_H
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 
29 #include "my_inttypes.h"
30 
31 class Relay_log_info;
32 struct TABLE;
33 
34 struct MY_BITMAP;
35 
37 
38 #if defined(MYSQL_SERVER)
39 size_t pack_row(TABLE *table, MY_BITMAP const *cols, uchar *row_data,
40  const uchar *data, enum_row_image_type row_image_type,
41  ulonglong value_options = 0);
42 
43 bool unpack_row(Relay_log_info const *rli, TABLE *table,
44  uint const master_column_count, uchar const *const row_data,
45  MY_BITMAP const *column_image,
46  uchar const **const row_image_end_p,
47  uchar const *const event_end,
48  enum_row_image_type row_image_type,
49  bool event_has_value_options, bool only_seek);
50 
51 // Fill table's record[0] with default values.
52 int prepare_record(TABLE *const table, const MY_BITMAP *cols, const bool check);
53 #endif
54 
55 /**
56  Template base class of Bit_reader / Bit_writer.
57 */
58 template <typename T, typename UT>
60  protected:
61  /// Pointer to beginning of buffer where bits are read or written.
62  T *m_ptr;
63  /// Current position in buffer.
65 
66  public:
67  /**
68  Construct a new Bit_stream (either reader or writer).
69  @param ptr Pointer where bits will be read or written.
70  */
71  Bit_stream_base(T *ptr) : m_ptr(ptr), m_current_bit(0) {}
72 
73  /**
74  Set the buffer pointer.
75  @param ptr Pointer where bits will be read or written.
76  */
77  void set_ptr(T *ptr) { m_ptr = ptr; }
78  /**
79  Set the buffer pointer, using an unsigned datatype.
80  @param ptr Pointer where bits will be read or written.
81  */
82  void set_ptr(UT *ptr) { m_ptr = (T *)ptr; }
83 
84  /// @return the current position.
85  uint tell() const { return m_current_bit; }
86 
87  /**
88  Print all the bits before the current position to the debug trace.
89  @param str Descriptive text that will be prefixed before the bit string.
90  */
91  void dbug_print(const char *str [[maybe_unused]]) const;
92 };
93 
94 /**
95  Auxiliary class to write a stream of bits to a memory location.
96 
97  Call set() to write a bit and move the position one bit foward.
98 */
99 class Bit_writer : public Bit_stream_base<char, uchar> {
100  public:
101  Bit_writer(char *ptr = nullptr) : Bit_stream_base<char, uchar>(ptr) {}
102  Bit_writer(uchar *ptr) : Bit_writer((char *)ptr) {}
103 
104  /**
105  Write the next bit and move the write position one bit forward.
106  @param set_to_on If true, set the bit to 1, otherwise set it to 0.
107  */
108  void set(bool set_to_on) {
109  uint byte = m_current_bit / 8;
110  uint bit_within_byte = m_current_bit % 8;
111  m_current_bit++;
112  if (bit_within_byte == 0)
113  m_ptr[byte] = set_to_on ? 1 : 0;
114  else if (set_to_on)
115  m_ptr[byte] |= 1 << bit_within_byte;
116  }
117 };
118 
119 /**
120  Auxiliary class to read or write a stream of bits to a memory location.
121 
122  Call get() to read a bit and move the position one bit foward.
123 */
124 class Bit_reader : public Bit_stream_base<const char, const uchar> {
125  public:
126  Bit_reader(const char *ptr = nullptr)
127  : Bit_stream_base<const char, const uchar>(ptr) {}
128  Bit_reader(const uchar *ptr) : Bit_reader((const char *)ptr) {}
129 
130  /**
131  Read the next bit and move the read position one bit forward.
132  @return true if the bit was 1, false if the bit was 0.
133  */
134  bool get() {
135  uint byte = m_current_bit / 8;
136  uint bit_within_byte = m_current_bit % 8;
137  m_current_bit++;
138  return (m_ptr[byte] & (1 << bit_within_byte)) != 0;
139  }
140 };
141 
142 #endif // ifdef RPL_RECORD_H
Auxiliary class to read or write a stream of bits to a memory location.
Definition: rpl_record.h:124
bool get()
Read the next bit and move the read position one bit forward.
Definition: rpl_record.h:134
Bit_reader(const uchar *ptr)
Definition: rpl_record.h:128
Bit_reader(const char *ptr=nullptr)
Definition: rpl_record.h:126
Template base class of Bit_reader / Bit_writer.
Definition: rpl_record.h:59
T * m_ptr
Pointer to beginning of buffer where bits are read or written.
Definition: rpl_record.h:62
uint m_current_bit
Current position in buffer.
Definition: rpl_record.h:64
uint tell() const
Definition: rpl_record.h:85
void set_ptr(UT *ptr)
Set the buffer pointer, using an unsigned datatype.
Definition: rpl_record.h:82
void set_ptr(T *ptr)
Set the buffer pointer.
Definition: rpl_record.h:77
Bit_stream_base(T *ptr)
Construct a new Bit_stream (either reader or writer).
Definition: rpl_record.h:71
void dbug_print(const char *str[[maybe_unused]]) const
Print all the bits before the current position to the debug trace.
Definition: rpl_record.cc:59
Auxiliary class to write a stream of bits to a memory location.
Definition: rpl_record.h:99
void set(bool set_to_on)
Write the next bit and move the write position one bit forward.
Definition: rpl_record.h:108
Bit_writer(uchar *ptr)
Definition: rpl_record.h:102
Bit_writer(char *ptr=nullptr)
Definition: rpl_record.h:101
Definition: rpl_rli.h:200
unsigned char byte
Blob class.
Definition: common.h:150
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1056
bool unpack_row(Relay_log_info const *rli, TABLE *table, uint const master_column_count, uchar const *const row_data, MY_BITMAP const *column_image, uchar const **const row_image_end_p, uchar const *const event_end, enum_row_image_type row_image_type, bool event_has_value_options, bool only_seek)
Unpack a row image (either before-image or after-image) into table->record[0].
Definition: rpl_record.cc:568
enum_row_image_type
Definition: rpl_record.h:36
int prepare_record(TABLE *const table, const MY_BITMAP *cols, const bool check)
Fills table->record[0] with default values.
Definition: rpl_record.cc:905
size_t pack_row(TABLE *table, MY_BITMAP const *cols, uchar *row_data, const uchar *data, enum_row_image_type row_image_type, ulonglong value_options=0)
Pack a record of data for a table into a format suitable for the binary log.
Definition: rpl_record.cc:267
Definition: my_bitmap.h:41
Definition: table.h:1394
unsigned int uint
Definition: uca-dump.cc:29