mysql_async/conn/binlog_stream/
request.rs

1use mysql_common::packets::{
2    binlog_request::BinlogRequest, BinlogDumpFlags, ComRegisterSlave, Sid,
3};
4
5/// Binlog stream request builder.
6pub struct BinlogStreamRequest<'a> {
7    pub(crate) binlog_request: BinlogRequest<'a>,
8    pub(crate) register_slave: ComRegisterSlave<'a>,
9}
10
11impl<'a> BinlogStreamRequest<'a> {
12    /// Creates a new request with the given slave server id.
13    pub fn new(server_id: u32) -> Self {
14        Self {
15            binlog_request: BinlogRequest::new(server_id),
16            register_slave: ComRegisterSlave::new(server_id),
17        }
18    }
19
20    /// Enables GTID-based replication (disabled by default).
21    pub fn with_gtid(mut self) -> Self {
22        self.binlog_request = self.binlog_request.with_use_gtid(true);
23        self
24    }
25
26    /// Enables `NON_BLOCK` flag. Stream will be terminated as soon as there are no events.
27    pub fn with_non_blocking(mut self) -> Self {
28        self.binlog_request = self
29            .binlog_request
30            .with_flags(BinlogDumpFlags::BINLOG_DUMP_NON_BLOCK);
31        self
32    }
33
34    /// Sets the filename of the binlog on the master (try `SHOW BINARY LOGS`).
35    pub fn with_filename(mut self, filename: &'a [u8]) -> Self {
36        self.binlog_request = self.binlog_request.with_filename(filename);
37        self
38    }
39
40    /// Sets the start position (defaults to `4`).
41    pub fn with_pos(mut self, position: u64) -> Self {
42        self.binlog_request = self.binlog_request.with_pos(position);
43        self
44    }
45
46    /// Adds the given set of GTIDs to the request (ignored if not GTID-based).
47    pub fn with_gtid_set<T>(mut self, set: T) -> Self
48    where
49        T: IntoIterator<Item = Sid<'a>>,
50    {
51        self.binlog_request = self.binlog_request.with_sids(set);
52        self
53    }
54
55    /// This hostname will be reported to the server (max len 255, default to an empty string).
56    ///
57    /// Usually left default.
58    pub fn with_hostname(mut self, hostname: &'a [u8]) -> Self {
59        self.register_slave = self.register_slave.with_hostname(hostname);
60        self
61    }
62
63    /// This username will be reported to the server (max len 255, default to an empty string).
64    ///
65    /// Usually left default.
66    pub fn with_user(mut self, user: &'a [u8]) -> Self {
67        self.register_slave = self.register_slave.with_user(user);
68        self
69    }
70
71    /// This password will be reported to the server (max len 255, default to an empty string).
72    ///
73    /// Usually left default.
74    pub fn with_password(mut self, password: &'a [u8]) -> Self {
75        self.register_slave = self.register_slave.with_password(password);
76        self
77    }
78
79    /// This port number will be reported to the server (defaults to `0`).
80    ///
81    /// Usually left default.
82    pub fn with_port(mut self, port: u16) -> Self {
83        self.register_slave = self.register_slave.with_port(port);
84        self
85    }
86}