diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-21 08:43:43 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-21 08:43:43 +0100 |
commit | bf55ecaeb6849eab89fdb9bc5da51ff32dd1ea33 (patch) | |
tree | 3e5d8bd554aff8f455bf55c38d0cb63505beb4b9 /lib | |
parent | Default intialize structs (diff) | |
download | mygrate-bf55ecaeb6849eab89fdb9bc5da51ff32dd1ea33.tar.bz2 mygrate-bf55ecaeb6849eab89fdb9bc5da51ff32dd1ea33.tar.xz mygrate-bf55ecaeb6849eab89fdb9bc5da51ff32dd1ea33.zip |
Unpack row data into a vector or vector pair
Diffstat (limited to 'lib')
-rw-r--r-- | lib/row.cpp | 34 | ||||
-rw-r--r-- | lib/row.h | 18 |
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}} + { + } } @@ -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); }; } |