use mysql_common::packets::{
binlog_request::BinlogRequest, BinlogDumpFlags, ComRegisterSlave, Sid,
};
pub struct BinlogStreamRequest<'a> {
pub(crate) binlog_request: BinlogRequest<'a>,
pub(crate) register_slave: ComRegisterSlave<'a>,
}
impl<'a> BinlogStreamRequest<'a> {
pub fn new(server_id: u32) -> Self {
Self {
binlog_request: BinlogRequest::new(server_id),
register_slave: ComRegisterSlave::new(server_id),
}
}
pub fn with_gtid(mut self) -> Self {
self.binlog_request = self.binlog_request.with_use_gtid(true);
self
}
pub fn with_non_blocking(mut self) -> Self {
self.binlog_request = self
.binlog_request
.with_flags(BinlogDumpFlags::BINLOG_DUMP_NON_BLOCK);
self
}
pub fn with_filename(mut self, filename: &'a [u8]) -> Self {
self.binlog_request = self.binlog_request.with_filename(filename);
self
}
pub fn with_pos(mut self, position: u64) -> Self {
self.binlog_request = self.binlog_request.with_pos(position);
self
}
pub fn with_gtid_set<T>(mut self, set: T) -> Self
where
T: IntoIterator<Item = Sid<'a>>,
{
self.binlog_request = self.binlog_request.with_sids(set);
self
}
pub fn with_hostname(mut self, hostname: &'a [u8]) -> Self {
self.register_slave = self.register_slave.with_hostname(hostname);
self
}
pub fn with_user(mut self, user: &'a [u8]) -> Self {
self.register_slave = self.register_slave.with_user(user);
self
}
pub fn with_password(mut self, password: &'a [u8]) -> Self {
self.register_slave = self.register_slave.with_password(password);
self
}
pub fn with_port(mut self, port: u16) -> Self {
self.register_slave = self.register_slave.with_port(port);
self
}
}