binlog_dump.js 984 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. // http://dev.mysql.com/doc/internals/en/com-binlog-dump.html#packet-COM_BINLOG_DUMP
  3. const Packet = require('../packets/packet');
  4. const CommandCodes = require('../constants/commands');
  5. // TODO: add flag to constants
  6. // 0x01 - BINLOG_DUMP_NON_BLOCK
  7. // send EOF instead of blocking
  8. class BinlogDump {
  9. constructor(opts) {
  10. this.binlogPos = opts.binlogPos || 0;
  11. this.serverId = opts.serverId || 0;
  12. this.flags = opts.flags || 0;
  13. this.filename = opts.filename || '';
  14. }
  15. toPacket() {
  16. const length = 15 + Buffer.byteLength(this.filename, 'utf8'); // TODO: should be ascii?
  17. const buffer = Buffer.allocUnsafe(length);
  18. const packet = new Packet(0, buffer, 0, length);
  19. packet.offset = 4;
  20. packet.writeInt8(CommandCodes.BINLOG_DUMP);
  21. packet.writeInt32(this.binlogPos);
  22. packet.writeInt16(this.flags);
  23. packet.writeInt32(this.serverId);
  24. packet.writeString(this.filename);
  25. return packet;
  26. }
  27. }
  28. module.exports = BinlogDump;