Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored binlog event data structures / parsers (#25)
Redesigned data structures for storing binlog event data components. Binlog events now have the following parts (as per MySQL design docs): * 'common_header' (of fixed length, for binlog V4 19 bytes) * 'post_header' (of various length depending on event code) * 'body' (of various length depending on event code) * optional 'footer' (currently holding CRC32 checksum, 4 bytes, of the event data) The footer is always present for 'format description' events. For the rest of the events, its presence depends on the 'checksum_algorithm' field from the last seen 'format description' event. All binlog event-related data structures moved into new 'binsrv::event' namespace. 'binsrv::event_type' bacame 'binsrv::event::code_type'. 'binsrv::event_flag' became 'binsrv::event::flag_type'. 'binsrv::event_flag_set' became 'binsrv::event::flag_set'. 'binsrv::event_header' became 'binsrv::event::common_header'. Introduced 'binsrv::event_checksum_algorithm_type' enum (with 2 values 'off' and 'crc32'). Introduced 'binsrv::event::footer' class for holding binlog event footer data (currently only 'checksum algorithm'). Introduced 'binsrv::event::generic_post_header_impl' class template that is supposed to be specialized for each known event code with post header data specific to this particular event. Introduced 'binsrv::event::generic_body_impl' class template that is supposed to be specialized for each known event code with body data specific to this particular event. For unknown (valid but not meaningful in this project) post headers / bodies introduced 'binsrv::event::unknown_post_header' and 'binsrv::event::unknown_body' classes which are used as default specialization. For empty (containing no data) post headers / bodies introduced 'binsrv::event::empty_post_header' and 'binsrv::event::empty_body'. Added specializations for post headers / bodies for the following events: * format description event * rotate event Introduced an aggregate class for storing all binlog event data components - 'binsrv::event::event'. It was designed to eliminate (with a few minor exceptions) dynamic memory allocations and virtual function calls for binlog event data manipulation. It includes: * binsrv::event::common_header * a smart union ('std::variant') of all possible event post headers (specializations of 'binsrv::event::generic_post_header_impl' ) * a smart union ('std::variant') of all possible event bodies (specializations of 'binsrv::event::generic_body_impl' ) * optional (via 'std::optional') binsrv::event::footer Reworked event reading loop in the main application: last seen format description event is now stored outside of the loop to make decisions about checksum presence in the footers of the events that follow. For 'trace' log level original event bytes are also printed in the row (non-hex) form. Non-printable characters are shown as '.'. Fixed incorrect help message describing expected command line arguments. 'byte_span' moved from 'easymysql' namespace to 'util' and became a writable range. Underlying type changed from 'unsigned char' to 'std::byte'. For read-only byte ranges, introduced 'const_byte_span'. Added 'util::as_string_view()' helper function for these two types. 'extract_fixed_int_from_byte_span()' and 'extract_byte_array_from_byte_span()' static helper functions moved to the 'util' namespace and became globally available. Introduced two new utility functions 'util::enum_to_index()' an 'util::index_to_enum()' that simplify the conversion from enums to 'std::size' (via underlying type) and back. Improved the behavior of the 'to_string()' function for 'util::flag_set' class template. Unknown bits in the set are now ignored instead of being printed as empty strings. More integral constant used used in 'std::size_t' contexts now have explicit 'U' integer suffix. This should be changed to `UZ` once the project switches to 'c++23'. More 'type var = value;' initializations converted to modern 'type var{value}';
- Loading branch information