mysql_binlog_connector_rust/event/
rows_query_event.rs

1use serde::{Deserialize, Serialize};
2
3use std::io::{Cursor, Seek, SeekFrom};
4
5use crate::{binlog_error::BinlogError, ext::cursor_ext::CursorExt};
6
7#[derive(Debug, Deserialize, Serialize, Clone)]
8pub struct RowsQueryEvent {
9    pub query: String,
10}
11
12impl RowsQueryEvent {
13    pub fn parse(cursor: &mut Cursor<&Vec<u8>>) -> Result<Self, BinlogError> {
14        // refer: https://dev.mysql.com/doc/dev/mysql-server/latest/classbinary__log_1_1Rows__query__event.html
15        // query length is stored using one byte, but it is ignored and the left bytes contain the full query
16        cursor.seek(SeekFrom::Current(1))?;
17
18        let query = cursor.read_string(cursor.get_ref().len() - 1)?;
19        Ok(Self { query })
20    }
21}