token.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package token
  2. import "fmt"
  3. var SingleByteTokens = [...]string{"", "", "", "200", "400", "404", "500", "501", "502", "action", "add",
  4. "after", "archive", "author", "available", "battery", "before", "body",
  5. "broadcast", "chat", "clear", "code", "composing", "contacts", "count",
  6. "create", "debug", "delete", "demote", "duplicate", "encoding", "error",
  7. "false", "filehash", "from", "g.us", "group", "groups_v2", "height", "id",
  8. "image", "in", "index", "invis", "item", "jid", "kind", "last", "leave",
  9. "live", "log", "media", "message", "mimetype", "missing", "modify", "name",
  10. "notification", "notify", "out", "owner", "participant", "paused",
  11. "picture", "played", "presence", "preview", "promote", "query", "raw",
  12. "read", "receipt", "received", "recipient", "recording", "relay",
  13. "remove", "response", "resume", "retry", "s.whatsapp.net", "seconds",
  14. "set", "size", "status", "subject", "subscribe", "t", "text", "to", "true",
  15. "type", "unarchive", "unavailable", "url", "user", "value", "web", "width",
  16. "mute", "read_only", "admin", "creator", "short", "update", "powersave",
  17. "checksum", "epoch", "block", "previous", "409", "replaced", "reason",
  18. "spam", "modify_tag", "message_info", "delivery", "emoji", "title",
  19. "description", "canonical-url", "matched-text", "star", "unstar",
  20. "media_key", "filename", "identity", "unread", "page", "page_count",
  21. "search", "media_message", "security", "call_log", "profile", "ciphertext",
  22. "invite", "gif", "vcard", "frequent", "privacy", "blacklist", "whitelist",
  23. "verify", "location", "document", "elapsed", "revoke_invite", "expiration",
  24. "unsubscribe", "disable", "vname", "old_jid", "new_jid", "announcement",
  25. "locked", "prop", "label", "color", "call", "offer", "call-id"}
  26. var doubleByteTokens = [...]string{}
  27. func GetSingleToken(i int) (string, error) {
  28. if i < 3 || i >= len(SingleByteTokens) {
  29. return "", fmt.Errorf("index out of single byte token bounds %d", i)
  30. }
  31. return SingleByteTokens[i], nil
  32. }
  33. func GetDoubleToken(index1 int, index2 int) (string, error) {
  34. n := 256*index1 + index2
  35. if n < 0 || n >= len(doubleByteTokens) {
  36. return "", fmt.Errorf("index out of double byte token bounds %d", n)
  37. }
  38. return doubleByteTokens[n], nil
  39. }
  40. func IndexOfSingleToken(token string) int {
  41. for i, t := range SingleByteTokens {
  42. if t == token {
  43. return i
  44. }
  45. }
  46. return -1
  47. }
  48. const (
  49. LIST_EMPTY = 0
  50. STREAM_END = 2
  51. DICTIONARY_0 = 236
  52. DICTIONARY_1 = 237
  53. DICTIONARY_2 = 238
  54. DICTIONARY_3 = 239
  55. LIST_8 = 248
  56. LIST_16 = 249
  57. JID_PAIR = 250
  58. HEX_8 = 251
  59. BINARY_8 = 252
  60. BINARY_20 = 253
  61. BINARY_32 = 254
  62. NIBBLE_8 = 255
  63. )
  64. const (
  65. PACKED_MAX = 254
  66. SINGLE_BYTE_MAX = 256
  67. )