Path: blob/master/Utilities/cmnghttp2/lib/nghttp2_hd_huffman.h
3153 views
/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2013 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef NGHTTP2_HD_HUFFMAN_H25#define NGHTTP2_HD_HUFFMAN_H2627#ifdef HAVE_CONFIG_H28# include <config.h>29#endif /* HAVE_CONFIG_H */3031#include <nghttp2/nghttp2.h>3233typedef enum {34/* FSA accepts this state as the end of huffman encoding35sequence. */36NGHTTP2_HUFF_ACCEPTED = 1 << 14,37/* This state emits symbol */38NGHTTP2_HUFF_SYM = 1 << 15,39} nghttp2_huff_decode_flag;4041typedef struct {42/* fstate is the current huffman decoding state, which is actually43the node ID of internal huffman tree with44nghttp2_huff_decode_flag OR-ed. We have 257 leaf nodes, but they45are identical to root node other than emitting a symbol, so we46have 256 internal nodes [1..255], inclusive. The node ID 256 is47a special node and it is a terminal state that means decoding48failed. */49uint16_t fstate;50/* symbol if NGHTTP2_HUFF_SYM flag set */51uint8_t sym;52} nghttp2_huff_decode;5354typedef nghttp2_huff_decode huff_decode_table_type[16];5556typedef struct {57/* fstate is the current huffman decoding state. */58uint16_t fstate;59} nghttp2_hd_huff_decode_context;6061typedef struct {62/* The number of bits in this code */63uint32_t nbits;64/* Huffman code aligned to LSB */65uint32_t code;66} nghttp2_huff_sym;6768extern const nghttp2_huff_sym huff_sym_table[];69extern const nghttp2_huff_decode huff_decode_table[][16];7071#endif /* NGHTTP2_HD_HUFFMAN_H */727374