mysql_binlog_connector_rust/command/
dump_binlog_command.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::io::Write;

use byteorder::{LittleEndian, WriteBytesExt};

use crate::binlog_error::BinlogError;

use super::command_type::CommandType;

pub struct DumpBinlogCommand {
    pub server_id: u64,
    pub binlog_filename: String,
    pub binlog_position: u32,
}

impl DumpBinlogCommand {
    pub fn to_bytes(&mut self) -> Result<Vec<u8>, BinlogError> {
        let mut buf = Vec::new();
        buf.write_u8(CommandType::BinlogDump as u8)?;
        buf.write_u32::<LittleEndian>(self.binlog_position)?;

        let binlog_flags = 0;
        buf.write_u16::<LittleEndian>(binlog_flags)?;

        buf.write_u32::<LittleEndian>(self.server_id as u32)?;
        buf.write_all(self.binlog_filename.as_bytes())?;

        Ok(buf)
    }
}