No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

81 líneas
1.9 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. // the number limited for job servers.
  8. WORKER_SERVER_CAP = 32
  9. // the number limited for functions.
  10. WORKER_FUNCTION_CAP = 512
  11. // queue size
  12. QUEUE_SIZE = 512
  13. // read buffer size
  14. BUFFER_SIZE = 1024
  15. // \x00REQ
  16. REQ = 5391697
  17. REQ_STR = "\x00REQ"
  18. // \x00RES
  19. RES = 5391699
  20. RES_STR = "\x00RES"
  21. // package data type
  22. CAN_DO = 1
  23. CANT_DO = 2
  24. RESET_ABILITIES = 3
  25. PRE_SLEEP = 4
  26. NOOP = 6
  27. JOB_CREATED = 8
  28. GRAB_JOB = 9
  29. NO_JOB = 10
  30. JOB_ASSIGN = 11
  31. WORK_STATUS = 12
  32. WORK_COMPLETE = 13
  33. WORK_FAIL = 14
  34. GET_STATUS = 15
  35. ECHO_REQ = 16
  36. ECHO_RES = 17
  37. ERROR = 19
  38. STATUS_RES = 20
  39. SET_CLIENT_ID = 22
  40. CAN_DO_TIMEOUT = 23
  41. WORK_EXCEPTION = 25
  42. WORK_DATA = 28
  43. WORK_WARNING = 29
  44. GRAB_JOB_UNIQ = 30
  45. JOB_ASSIGN_UNIQ = 31
  46. SUBMIT_JOB = 7
  47. SUBMIT_JOB_BG = 18
  48. SUBMIT_JOB_HIGH = 21
  49. SUBMIT_JOB_HIGH_BG = 32
  50. SUBMIT_JOB_LOW = 33
  51. SUBMIT_JOB_LOW_BG = 34
  52. // Job type
  53. // JOB_NORMAL | JOB_BG means a normal level job run in background
  54. // normal level
  55. JOB_NORMAL = 0
  56. // background job
  57. JOB_BG = 1
  58. // low level
  59. JOB_LOW = 2
  60. // high level
  61. JOB_HIGH = 4
  62. )
  63. // Decode [4]byte to uint32
  64. func BytesToUint32(buf [4]byte) uint32 {
  65. return uint32(buf[0])<<24 + uint32(buf[1])<<16 + uint32(buf[2])<<8 +
  66. uint32(buf[3])
  67. }
  68. // Encode uint32 to [4]byte
  69. func Uint32ToBytes(i uint32) [4]byte {
  70. return [4]byte{byte((i >> 24) & 0xff), byte((i >> 16) & 0xff),
  71. byte((i >> 8) & 0xff), byte(i & 0xff),}
  72. }