mysql_binlog_connector_rust/event/
delete_rows_event.rs

1use std::{collections::HashMap, io::Cursor};
2
3use serde::{Deserialize, Serialize};
4
5use crate::{binlog_error::BinlogError, ext::cursor_ext::CursorExt};
6
7use super::{event_header::EventHeader, row_event::RowEvent, table_map_event::TableMapEvent};
8
9#[derive(Debug, Deserialize, Serialize, Clone)]
10pub struct DeleteRowsEvent {
11    pub table_id: u64,
12    pub included_columns: Vec<bool>,
13    pub rows: Vec<RowEvent>,
14}
15
16impl DeleteRowsEvent {
17    pub fn parse(
18        cursor: &mut Cursor<&Vec<u8>>,
19        table_map_event_by_table_id: &mut HashMap<u64, TableMapEvent>,
20        row_event_version: u8,
21    ) -> Result<Self, BinlogError> {
22        let (table_id, _column_count, included_columns) =
23            EventHeader::parse_rows_event_common_header(cursor, row_event_version)?;
24        let table_map_event = table_map_event_by_table_id.get(&table_id).unwrap();
25
26        let mut rows: Vec<RowEvent> = Vec::new();
27        while cursor.available() > 0 {
28            let row = RowEvent::parse(cursor, table_map_event, &included_columns)?;
29            rows.push(row);
30        }
31
32        Ok(Self {
33            table_id,
34            included_columns,
35            rows,
36        })
37    }
38}