/**
  * @param Config $config
  * @throws MySQLReplicationException
  * @throws DBALException
  * @throws ConfigException
  * @throws BinLogException
  */
 public function __construct(Config $config)
 {
     $config->validate();
     $this->connection = DriverManager::getConnection(['user' => $config->getUser(), 'password' => $config->getPassword(), 'host' => $config->getHost(), 'port' => $config->getPort(), 'driver' => 'pdo_mysql', 'charset' => $config->getCharset()]);
     $this->repository = new MySQLRepository($this->connection);
     $this->gtiService = new GtidService();
     $this->binLogAuth = new BinLogAuth();
     $this->socketConnect = new BinLogSocketConnect($config, $this->repository, $this->binLogAuth, $this->gtiService);
     $this->socketConnect->connectToStream();
     $this->jsonBinaryDecoderFactory = new JsonBinaryDecoderFactory();
     $this->rowEventService = new RowEventService($config, $this->repository, $this->jsonBinaryDecoderFactory);
     $this->binaryDataReaderService = new BinaryDataReaderService();
     $this->eventDispatcher = new EventDispatcher();
     $this->event = new Event($config, $this->socketConnect, $this->binaryDataReaderService, $this->rowEventService, $this->eventDispatcher);
 }
 /**
  * @see https://dev.mysql.com/doc/internals/en/com-register-slave.html
  * @throws BinLogException
  */
 private function registerSlave()
 {
     $host = gethostname();
     $hostLength = strlen($host);
     $userLength = strlen($this->config->getUser());
     $passLength = strlen($this->config->getPassword());
     $prelude = pack('l', 18 + $hostLength + $userLength + $passLength);
     $prelude .= chr(ConstCommand::COM_REGISTER_SLAVE);
     $prelude .= pack('V', $this->config->getSlaveId());
     $prelude .= pack('C', $hostLength);
     $prelude .= $host;
     $prelude .= pack('C', $userLength);
     $prelude .= $this->config->getUser();
     $prelude .= pack('C', $passLength);
     $prelude .= $this->config->getPassword();
     $prelude .= pack('v', $this->config->getPort());
     $prelude .= pack('V', 0);
     $prelude .= pack('V', 0);
     $this->writeToSocket($prelude);
     $this->getPacket();
 }