nghttp2_hd_huffman.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * nghttp2 - HTTP/2 C Library
  3. *
  4. * Copyright (c) 2013 Tatsuhiro Tsujikawa
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGHTTP2_HD_HUFFMAN_H
  26. #define NGHTTP2_HD_HUFFMAN_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* HAVE_CONFIG_H */
  30. #include <nghttp2/nghttp2.h>
  31. typedef enum {
  32. /* FSA accepts this state as the end of huffman encoding
  33. sequence. */
  34. NGHTTP2_HUFF_ACCEPTED = 1 << 14,
  35. /* This state emits symbol */
  36. NGHTTP2_HUFF_SYM = 1 << 15,
  37. } nghttp2_huff_decode_flag;
  38. typedef struct {
  39. /* fstate is the current huffman decoding state, which is actually
  40. the node ID of internal huffman tree with
  41. nghttp2_huff_decode_flag OR-ed. We have 257 leaf nodes, but they
  42. are identical to root node other than emitting a symbol, so we
  43. have 256 internal nodes [1..255], inclusive. The node ID 256 is
  44. a special node and it is a terminal state that means decoding
  45. failed. */
  46. uint16_t fstate;
  47. /* symbol if NGHTTP2_HUFF_SYM flag set */
  48. uint8_t sym;
  49. } nghttp2_huff_decode;
  50. typedef nghttp2_huff_decode huff_decode_table_type[16];
  51. typedef struct {
  52. /* fstate is the current huffman decoding state. */
  53. uint16_t fstate;
  54. } nghttp2_hd_huff_decode_context;
  55. typedef struct {
  56. /* The number of bits in this code */
  57. uint32_t nbits;
  58. /* Huffman code aligned to LSB */
  59. uint32_t code;
  60. } nghttp2_huff_sym;
  61. extern const nghttp2_huff_sym huff_sym_table[];
  62. extern const nghttp2_huff_decode huff_decode_table[][16];
  63. #endif /* NGHTTP2_HD_HUFFMAN_H */