summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/row.cpp34
-rw-r--r--lib/row.h18
2 files changed, 41 insertions, 11 deletions
diff --git a/lib/row.cpp b/lib/row.cpp
index d59cdba..45e2959 100644
--- a/lib/row.cpp
+++ b/lib/row.cpp
@@ -3,13 +3,21 @@
#include <string>
namespace MyGrate {
- Row::Row(const st_mariadb_rpl_rows_event & r, const st_mariadb_rpl_table_map_event & t) : row {r}, tm {t} { }
+ Row::Row(const st_mariadb_rpl_rows_event & row, const st_mariadb_rpl_table_map_event & tm) :
+ Row(row, tm, RawDataReader {tm.metadata}, RawDataReader {row.row_data, row.row_data_size})
+ {
+ }
+
+ Row::Row(const st_mariadb_rpl_rows_event & row, const st_mariadb_rpl_table_map_event & tm,
+ MyGrate::RawDataReader && md, MyGrate::RawDataReader && data) :
+ Row {row, tm, md, data}
+ {
+ }
- void
- Row::forEachField(const std::function<void(MySQL::FieldValue)> & cb)
+ Row::Row(const st_mariadb_rpl_rows_event & row, const st_mariadb_rpl_table_map_event & tm,
+ MyGrate::RawDataReader & md, MyGrate::RawDataReader & data)
{
- MyGrate::RawDataReader md {tm.metadata};
- MyGrate::RawDataReader data {row.row_data, row.row_data_size};
+ reserve(tm.column_count);
const size_t flagBytes {(tm.column_count + 7) / 8};
MyGrate::BitSet nullFlags {data.viewValue<std::span<const std::byte>>(flagBytes)};
MyGrate::BitSet columnFlags {{reinterpret_cast<const std::byte *>(row.column_bitmap), flagBytes}};
@@ -44,13 +52,13 @@ namespace MyGrate {
break;
default:;
}
- cb(nullptr);
+ emplace_back(nullptr);
}
else {
switch (type) {
#define TYPE_CALLBACK(T) \
case T: \
- cb(MySQL::Type<T>::read(md, data)); \
+ emplace_back(MySQL::Type<T>::read(md, data)); \
break
TYPE_CALLBACK(MYSQL_TYPE_DECIMAL);
TYPE_CALLBACK(MYSQL_TYPE_TINY);
@@ -98,4 +106,16 @@ namespace MyGrate {
++colIter;
}
}
+
+ RowPair::RowPair(const st_mariadb_rpl_rows_event & row, const st_mariadb_rpl_table_map_event & tm) :
+ RowPair(row, tm, RawDataReader {tm.metadata}, RawDataReader {tm.metadata},
+ RawDataReader {row.row_data, row.row_data_size})
+ {
+ }
+
+ RowPair::RowPair(const st_mariadb_rpl_rows_event & row, const st_mariadb_rpl_table_map_event & tm,
+ MyGrate::RawDataReader && md1, MyGrate::RawDataReader && md2, MyGrate::RawDataReader && data) :
+ std::pair<Row, Row> {Row {row, tm, md1, data}, Row {row, tm, md2, data}}
+ {
+ }
}
diff --git a/lib/row.h b/lib/row.h
index ac2c135..4191644 100644
--- a/lib/row.h
+++ b/lib/row.h
@@ -6,15 +6,25 @@
#include <functional>
namespace MyGrate {
- class Row {
+ class Row : public std::vector<MySQL::FieldValue> {
public:
Row(const st_mariadb_rpl_rows_event &, const st_mariadb_rpl_table_map_event &);
- void forEachField(const std::function<void(MySQL::FieldValue)> & callback);
+ private:
+ friend class RowPair;
+ Row(const st_mariadb_rpl_rows_event &, const st_mariadb_rpl_table_map_event &, MyGrate::RawDataReader && md,
+ MyGrate::RawDataReader && data);
+ Row(const st_mariadb_rpl_rows_event &, const st_mariadb_rpl_table_map_event &, MyGrate::RawDataReader & md,
+ MyGrate::RawDataReader & data);
+ };
+
+ class RowPair : public std::pair<Row, Row> {
+ public:
+ RowPair(const st_mariadb_rpl_rows_event &, const st_mariadb_rpl_table_map_event &);
private:
- const st_mariadb_rpl_rows_event & row;
- const st_mariadb_rpl_table_map_event & tm;
+ RowPair(const st_mariadb_rpl_rows_event &, const st_mariadb_rpl_table_map_event &,
+ MyGrate::RawDataReader && md1, MyGrate::RawDataReader && md2, MyGrate::RawDataReader && data);
};
}