You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.5 KiB

  1. // Copyright 2011 - 2012 Xing Xing <mikespook@gmail.com>.
  2. // All rights reserved.
  3. // Use of this source code is governed by a MIT
  4. // license that can be found in the LICENSE file.
  5. package common
  6. const (
  7. NETWORK = "tcp"
  8. // queue size
  9. QUEUE_SIZE = 512
  10. // read buffer size
  11. BUFFER_SIZE = 1024
  12. // \x00REQ
  13. REQ = 5391697
  14. REQ_STR = "\x00REQ"
  15. // \x00RES
  16. RES = 5391699
  17. RES_STR = "\x00RES"
  18. // package data type
  19. CAN_DO = 1
  20. CANT_DO = 2
  21. RESET_ABILITIES = 3
  22. PRE_SLEEP = 4
  23. NOOP = 6
  24. JOB_CREATED = 8
  25. GRAB_JOB = 9
  26. NO_JOB = 10
  27. JOB_ASSIGN = 11
  28. WORK_STATUS = 12
  29. WORK_COMPLETE = 13
  30. WORK_FAIL = 14
  31. GET_STATUS = 15
  32. ECHO_REQ = 16
  33. ECHO_RES = 17
  34. ERROR = 19
  35. STATUS_RES = 20
  36. SET_CLIENT_ID = 22
  37. CAN_DO_TIMEOUT = 23
  38. WORK_EXCEPTION = 25
  39. WORK_DATA = 28
  40. WORK_WARNING = 29
  41. GRAB_JOB_UNIQ = 30
  42. JOB_ASSIGN_UNIQ = 31
  43. SUBMIT_JOB = 7
  44. SUBMIT_JOB_BG = 18
  45. SUBMIT_JOB_HIGH = 21
  46. SUBMIT_JOB_HIGH_BG = 32
  47. SUBMIT_JOB_LOW = 33
  48. SUBMIT_JOB_LOW_BG = 34
  49. )
  50. // Decode [4]byte to uint32
  51. func BytesToUint32(buf [4]byte) uint32 {
  52. return uint32(buf[0])<<24 + uint32(buf[1])<<16 + uint32(buf[2])<<8 +
  53. uint32(buf[3])
  54. }
  55. // Encode uint32 to [4]byte
  56. func Uint32ToBytes(i uint32) [4]byte {
  57. return [4]byte{byte((i >> 24) & 0xff), byte((i >> 16) & 0xff),
  58. byte((i >> 8) & 0xff), byte(i & 0xff),}
  59. }