mysql_binlog_connector_rust/command/
dump_binlog_command.rs1use std::io::Write;
2
3use byteorder::{LittleEndian, WriteBytesExt};
4
5use crate::binlog_error::BinlogError;
6
7use super::command_type::CommandType;
8
9pub struct DumpBinlogCommand {
10 pub server_id: u64,
11 pub binlog_filename: String,
12 pub binlog_position: u32,
13}
14
15impl DumpBinlogCommand {
16 pub fn to_bytes(&mut self) -> Result<Vec<u8>, BinlogError> {
17 let mut buf = Vec::new();
18 buf.write_u8(CommandType::BinlogDump as u8)?;
19 buf.write_u32::<LittleEndian>(self.binlog_position)?;
20
21 let binlog_flags = 0;
22 buf.write_u16::<LittleEndian>(binlog_flags)?;
23
24 buf.write_u32::<LittleEndian>(self.server_id as u32)?;
25 buf.write_all(self.binlog_filename.as_bytes())?;
26
27 Ok(buf)
28 }
29}