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