commands.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package binlog
  2. const BINLOG_DUMP_NON_BLOCK = 0x01
  3. const COMMAND_BIN_LOG_DUMP = 0x12
  4. const COMMAND_REGISTER_SLAVE = 0x15
  5. type BinlogRegisterSlaveCommand struct {
  6. Status uint64
  7. ServerId uint64
  8. Hostname string // Length Encoded
  9. User string // Length Encoded
  10. Password string // Length Encoded
  11. Port uint64
  12. ReplRank uint64
  13. MasterId uint64
  14. }
  15. func (c *Conn) writeBinlogRegisterSlaveCommand(brsc *BinlogRegisterSlaveCommand) error {
  16. c.putInt(TypeFixedInt, brsc.Status, 1)
  17. c.putInt(TypeFixedInt, brsc.ServerId, 4)
  18. c.putString(TypeLenEncString, brsc.Hostname)
  19. c.putString(TypeLenEncString, brsc.User)
  20. c.putString(TypeLenEncString, brsc.Password)
  21. c.putInt(TypeFixedInt, brsc.Port, 2)
  22. c.putInt(TypeFixedInt, brsc.ReplRank, 4)
  23. c.putInt(TypeFixedInt, brsc.MasterId, 4)
  24. if c.Flush() != nil {
  25. return c.Flush()
  26. }
  27. return nil
  28. }
  29. type BinlogDumpCommand struct {
  30. Status uint64
  31. Position uint64
  32. Flags uint64
  33. ServerId uint64
  34. Filename string
  35. }
  36. func (c *Conn) writeBinlogDumpCommand(bldc *BinlogDumpCommand) error {
  37. c.putInt(TypeFixedInt, bldc.Status, 1)
  38. c.putInt(TypeFixedInt, bldc.Position, 4)
  39. c.putInt(TypeFixedInt, bldc.Flags, 2)
  40. c.putInt(TypeFixedInt, bldc.ServerId, 4)
  41. c.putString(TypeRestOfPacketString, bldc.Filename)
  42. if c.Flush() != nil {
  43. return c.Flush()
  44. }
  45. return nil
  46. }