binlog_dump.js 972 B

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