const.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package pomeloMessage
  2. // Message types
  3. const (
  4. Request Type = 0x00 // ----000-
  5. Notify Type = 0x01 // ----001-
  6. Response Type = 0x02 // ----010-
  7. Push Type = 0x03 // ----011-
  8. )
  9. // Type represents the type of message, which could be Request/Notify/Response/Push
  10. type Type byte
  11. var typeMap = map[Type]string{
  12. Request: "Request",
  13. Notify: "Notify",
  14. Response: "Response",
  15. Push: "Push",
  16. }
  17. func (t *Type) String() string {
  18. return typeMap[*t]
  19. }
  20. func Routable(t Type) bool {
  21. return t == Request || t == Notify || t == Push
  22. }
  23. func InvalidType(t Type) bool {
  24. return t < Request || t > Push
  25. }
  26. // 掩码定义用来操作flag(1byte)
  27. const (
  28. RouteCompressMask = 0x01 // 启用路由压缩 00000001
  29. MsgHeadLength = 0x02 // 消息头的长度 00000010
  30. TypeMask = 0x07 // 获取消息类型 00000111
  31. GZIPMask = 0x10 // data compressed gzip mark
  32. ErrorMask = 0x20 // 响应错误标识 00100000
  33. )
  34. var (
  35. dataCompression = false // encode message is compression
  36. )
  37. func IsDataCompression() bool {
  38. return dataCompression
  39. }
  40. func SetDataCompression(compression bool) {
  41. dataCompression = compression
  42. }