isomorfeus-ferret 0.12.6 → 0.12.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -4
  3. data/ext/isomorfeus_ferret_ext/brotli_common_constants.c +15 -0
  4. data/ext/isomorfeus_ferret_ext/brotli_common_constants.h +200 -0
  5. data/ext/isomorfeus_ferret_ext/brotli_common_context.c +156 -0
  6. data/ext/isomorfeus_ferret_ext/brotli_common_context.h +113 -0
  7. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +5914 -0
  8. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.h +64 -0
  9. data/ext/isomorfeus_ferret_ext/brotli_common_platform.c +22 -0
  10. data/ext/isomorfeus_ferret_ext/brotli_common_platform.h +594 -0
  11. data/ext/isomorfeus_ferret_ext/brotli_common_transform.c +291 -0
  12. data/ext/isomorfeus_ferret_ext/brotli_common_transform.h +85 -0
  13. data/ext/isomorfeus_ferret_ext/brotli_common_version.h +26 -0
  14. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.c +76 -0
  15. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.h +351 -0
  16. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +2608 -0
  17. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.c +339 -0
  18. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.h +121 -0
  19. data/ext/isomorfeus_ferret_ext/brotli_dec_prefix.h +732 -0
  20. data/ext/isomorfeus_ferret_ext/brotli_dec_state.c +159 -0
  21. data/ext/isomorfeus_ferret_ext/brotli_dec_state.h +365 -0
  22. data/ext/isomorfeus_ferret_ext/brotli_decode.h +344 -0
  23. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.c +145 -0
  24. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.h +39 -0
  25. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.c +843 -0
  26. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.h +95 -0
  27. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_inc.h +163 -0
  28. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.c +35 -0
  29. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.h +63 -0
  30. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost_inc.h +127 -0
  31. data/ext/isomorfeus_ferret_ext/brotli_enc_block_encoder_inc.h +34 -0
  32. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.c +194 -0
  33. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.h +51 -0
  34. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter_inc.h +440 -0
  35. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.c +1314 -0
  36. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.h +84 -0
  37. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.c +56 -0
  38. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.h +48 -0
  39. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster_inc.h +320 -0
  40. data/ext/isomorfeus_ferret_ext/brotli_enc_command.c +28 -0
  41. data/ext/isomorfeus_ferret_ext/brotli_enc_command.h +190 -0
  42. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.c +790 -0
  43. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.h +61 -0
  44. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.c +645 -0
  45. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.h +54 -0
  46. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.c +1846 -0
  47. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.h +25 -0
  48. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +1927 -0
  49. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.c +33 -0
  50. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.h +43 -0
  51. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.c +503 -0
  52. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.h +122 -0
  53. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode_static.h +539 -0
  54. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.c +105 -0
  55. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.h +66 -0
  56. data/ext/isomorfeus_ferret_ext/brotli_enc_find_match_length.h +79 -0
  57. data/ext/isomorfeus_ferret_ext/brotli_enc_hash.h +488 -0
  58. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_composite_inc.h +125 -0
  59. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_forgetful_chain_inc.h +293 -0
  60. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match64_inc.h +267 -0
  61. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_inc.h +262 -0
  62. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_quickly_inc.h +266 -0
  63. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_rolling_inc.h +212 -0
  64. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_to_binary_tree_inc.h +329 -0
  65. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.c +100 -0
  66. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.h +63 -0
  67. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram_inc.h +51 -0
  68. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.c +175 -0
  69. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.h +30 -0
  70. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.c +170 -0
  71. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.h +114 -0
  72. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.c +663 -0
  73. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.h +105 -0
  74. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock_inc.h +183 -0
  75. data/ext/isomorfeus_ferret_ext/brotli_enc_params.h +46 -0
  76. data/ext/isomorfeus_ferret_ext/brotli_enc_prefix.h +53 -0
  77. data/ext/isomorfeus_ferret_ext/brotli_enc_quality.h +165 -0
  78. data/ext/isomorfeus_ferret_ext/brotli_enc_ringbuffer.h +167 -0
  79. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.c +486 -0
  80. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.h +40 -0
  81. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict_lut.h +5864 -0
  82. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.c +85 -0
  83. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.h +32 -0
  84. data/ext/isomorfeus_ferret_ext/brotli_enc_write_bits.h +87 -0
  85. data/ext/isomorfeus_ferret_ext/brotli_encode.h +448 -0
  86. data/ext/isomorfeus_ferret_ext/brotli_port.h +288 -0
  87. data/ext/isomorfeus_ferret_ext/brotli_types.h +83 -0
  88. data/ext/isomorfeus_ferret_ext/frb_index.c +35 -4
  89. data/ext/isomorfeus_ferret_ext/frt_document.h +1 -0
  90. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +1 -0
  91. data/ext/isomorfeus_ferret_ext/frt_index.c +174 -25
  92. data/ext/isomorfeus_ferret_ext/frt_index.h +6 -3
  93. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +1 -0
  94. data/ext/isomorfeus_ferret_ext/test_fields.c +57 -45
  95. data/ext/isomorfeus_ferret_ext/test_index.c +4 -1
  96. data/lib/isomorfeus/ferret/version.rb +1 -1
  97. metadata +88 -3
@@ -0,0 +1,344 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /**
8
+ * @file
9
+ * API for Brotli decompression.
10
+ */
11
+
12
+ #ifndef BROTLI_DEC_DECODE_H_
13
+ #define BROTLI_DEC_DECODE_H_
14
+
15
+ #include "brotli_port.h"
16
+ #include "brotli_types.h"
17
+
18
+ #if defined(__cplusplus) || defined(c_plusplus)
19
+ extern "C" {
20
+ #endif
21
+
22
+ /**
23
+ * Opaque structure that holds decoder state.
24
+ *
25
+ * Allocated and initialized with ::BrotliDecoderCreateInstance.
26
+ * Cleaned up and deallocated with ::BrotliDecoderDestroyInstance.
27
+ */
28
+ typedef struct BrotliDecoderStateStruct BrotliDecoderState;
29
+
30
+ /**
31
+ * Result type for ::BrotliDecoderDecompress and
32
+ * ::BrotliDecoderDecompressStream functions.
33
+ */
34
+ typedef enum {
35
+ /** Decoding error, e.g. corrupted input or memory allocation problem. */
36
+ BROTLI_DECODER_RESULT_ERROR = 0,
37
+ /** Decoding successfully completed. */
38
+ BROTLI_DECODER_RESULT_SUCCESS = 1,
39
+ /** Partially done; should be called again with more input. */
40
+ BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT = 2,
41
+ /** Partially done; should be called again with more output. */
42
+ BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT = 3
43
+ } BrotliDecoderResult;
44
+
45
+ /**
46
+ * Template that evaluates items of ::BrotliDecoderErrorCode.
47
+ *
48
+ * Example: @code {.cpp}
49
+ * // Log Brotli error code.
50
+ * switch (brotliDecoderErrorCode) {
51
+ * #define CASE_(PREFIX, NAME, CODE) \
52
+ * case BROTLI_DECODER ## PREFIX ## NAME: \
53
+ * LOG(INFO) << "error code:" << #NAME; \
54
+ * break;
55
+ * #define NEWLINE_
56
+ * BROTLI_DECODER_ERROR_CODES_LIST(CASE_, NEWLINE_)
57
+ * #undef CASE_
58
+ * #undef NEWLINE_
59
+ * default: LOG(FATAL) << "unknown brotli error code";
60
+ * }
61
+ * @endcode
62
+ */
63
+ #define BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR) \
64
+ BROTLI_ERROR_CODE(_, NO_ERROR, 0) SEPARATOR \
65
+ /* Same as BrotliDecoderResult values */ \
66
+ BROTLI_ERROR_CODE(_, SUCCESS, 1) SEPARATOR \
67
+ BROTLI_ERROR_CODE(_, NEEDS_MORE_INPUT, 2) SEPARATOR \
68
+ BROTLI_ERROR_CODE(_, NEEDS_MORE_OUTPUT, 3) SEPARATOR \
69
+ \
70
+ /* Errors caused by invalid input */ \
71
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_NIBBLE, -1) SEPARATOR \
72
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, RESERVED, -2) SEPARATOR \
73
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_META_NIBBLE, -3) SEPARATOR \
74
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_ALPHABET, -4) SEPARATOR \
75
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_SAME, -5) SEPARATOR \
76
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, CL_SPACE, -6) SEPARATOR \
77
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, HUFFMAN_SPACE, -7) SEPARATOR \
78
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, CONTEXT_MAP_REPEAT, -8) SEPARATOR \
79
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_1, -9) SEPARATOR \
80
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_2, -10) SEPARATOR \
81
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, TRANSFORM, -11) SEPARATOR \
82
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, DICTIONARY, -12) SEPARATOR \
83
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, WINDOW_BITS, -13) SEPARATOR \
84
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_1, -14) SEPARATOR \
85
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \
86
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, DISTANCE, -16) SEPARATOR \
87
+ \
88
+ /* -17..-18 codes are reserved */ \
89
+ \
90
+ BROTLI_ERROR_CODE(_ERROR_, DICTIONARY_NOT_SET, -19) SEPARATOR \
91
+ BROTLI_ERROR_CODE(_ERROR_, INVALID_ARGUMENTS, -20) SEPARATOR \
92
+ \
93
+ /* Memory allocation problems */ \
94
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MODES, -21) SEPARATOR \
95
+ /* Literal, insert and distance trees together */ \
96
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, TREE_GROUPS, -22) SEPARATOR \
97
+ /* -23..-24 codes are reserved for distinct tree groups */ \
98
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MAP, -25) SEPARATOR \
99
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_1, -26) SEPARATOR \
100
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_2, -27) SEPARATOR \
101
+ /* -28..-29 codes are reserved for dynamic ring-buffer allocation */ \
102
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, BLOCK_TYPE_TREES, -30) SEPARATOR \
103
+ \
104
+ /* "Impossible" states */ \
105
+ BROTLI_ERROR_CODE(_ERROR_, UNREACHABLE, -31)
106
+
107
+ /**
108
+ * Error code for detailed logging / production debugging.
109
+ *
110
+ * See ::BrotliDecoderGetErrorCode and ::BROTLI_LAST_ERROR_CODE.
111
+ */
112
+ typedef enum {
113
+ #define BROTLI_COMMA_ ,
114
+ #define BROTLI_ERROR_CODE_ENUM_ITEM_(PREFIX, NAME, CODE) \
115
+ BROTLI_DECODER ## PREFIX ## NAME = CODE
116
+ BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE_ENUM_ITEM_, BROTLI_COMMA_)
117
+ } BrotliDecoderErrorCode;
118
+ #undef BROTLI_ERROR_CODE_ENUM_ITEM_
119
+ #undef BROTLI_COMMA_
120
+
121
+ /**
122
+ * The value of the last error code, negative integer.
123
+ *
124
+ * All other error code values are in the range from ::BROTLI_LAST_ERROR_CODE
125
+ * to @c -1. There are also 4 other possible non-error codes @c 0 .. @c 3 in
126
+ * ::BrotliDecoderErrorCode enumeration.
127
+ */
128
+ #define BROTLI_LAST_ERROR_CODE BROTLI_DECODER_ERROR_UNREACHABLE
129
+
130
+ /** Options to be used with ::BrotliDecoderSetParameter. */
131
+ typedef enum BrotliDecoderParameter {
132
+ /**
133
+ * Disable "canny" ring buffer allocation strategy.
134
+ *
135
+ * Ring buffer is allocated according to window size, despite the real size of
136
+ * the content.
137
+ */
138
+ BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION = 0,
139
+ /**
140
+ * Flag that determines if "Large Window Brotli" is used.
141
+ */
142
+ BROTLI_DECODER_PARAM_LARGE_WINDOW = 1
143
+ } BrotliDecoderParameter;
144
+
145
+ /**
146
+ * Sets the specified parameter to the given decoder instance.
147
+ *
148
+ * @param state decoder instance
149
+ * @param param parameter to set
150
+ * @param value new parameter value
151
+ * @returns ::BROTLI_FALSE if parameter is unrecognized, or value is invalid
152
+ * @returns ::BROTLI_TRUE if value is accepted
153
+ */
154
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderSetParameter(
155
+ BrotliDecoderState* state, BrotliDecoderParameter param, uint32_t value);
156
+
157
+ /**
158
+ * Creates an instance of ::BrotliDecoderState and initializes it.
159
+ *
160
+ * The instance can be used once for decoding and should then be destroyed with
161
+ * ::BrotliDecoderDestroyInstance, it cannot be reused for a new decoding
162
+ * session.
163
+ *
164
+ * @p alloc_func and @p free_func @b MUST be both zero or both non-zero. In the
165
+ * case they are both zero, default memory allocators are used. @p opaque is
166
+ * passed to @p alloc_func and @p free_func when they are called. @p free_func
167
+ * has to return without doing anything when asked to free a NULL pointer.
168
+ *
169
+ * @param alloc_func custom memory allocation function
170
+ * @param free_func custom memory free function
171
+ * @param opaque custom memory manager handle
172
+ * @returns @c 0 if instance can not be allocated or initialized
173
+ * @returns pointer to initialized ::BrotliDecoderState otherwise
174
+ */
175
+ BROTLI_DEC_API BrotliDecoderState* BrotliDecoderCreateInstance(
176
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
177
+
178
+ /**
179
+ * Deinitializes and frees ::BrotliDecoderState instance.
180
+ *
181
+ * @param state decoder instance to be cleaned up and deallocated
182
+ */
183
+ BROTLI_DEC_API void BrotliDecoderDestroyInstance(BrotliDecoderState* state);
184
+
185
+ /**
186
+ * Performs one-shot memory-to-memory decompression.
187
+ *
188
+ * Decompresses the data in @p encoded_buffer into @p decoded_buffer, and sets
189
+ * @p *decoded_size to the decompressed length.
190
+ *
191
+ * @param encoded_size size of @p encoded_buffer
192
+ * @param encoded_buffer compressed data buffer with at least @p encoded_size
193
+ * addressable bytes
194
+ * @param[in, out] decoded_size @b in: size of @p decoded_buffer; \n
195
+ * @b out: length of decompressed data written to
196
+ * @p decoded_buffer
197
+ * @param decoded_buffer decompressed data destination buffer
198
+ * @returns ::BROTLI_DECODER_RESULT_ERROR if input is corrupted, memory
199
+ * allocation failed, or @p decoded_buffer is not large enough;
200
+ * @returns ::BROTLI_DECODER_RESULT_SUCCESS otherwise
201
+ */
202
+ BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompress(
203
+ size_t encoded_size,
204
+ const uint8_t encoded_buffer[BROTLI_ARRAY_PARAM(encoded_size)],
205
+ size_t* decoded_size,
206
+ uint8_t decoded_buffer[BROTLI_ARRAY_PARAM(*decoded_size)]);
207
+
208
+ /**
209
+ * Decompresses the input stream to the output stream.
210
+ *
211
+ * The values @p *available_in and @p *available_out must specify the number of
212
+ * bytes addressable at @p *next_in and @p *next_out respectively.
213
+ * When @p *available_out is @c 0, @p next_out is allowed to be @c NULL.
214
+ *
215
+ * After each call, @p *available_in will be decremented by the amount of input
216
+ * bytes consumed, and the @p *next_in pointer will be incremented by that
217
+ * amount. Similarly, @p *available_out will be decremented by the amount of
218
+ * output bytes written, and the @p *next_out pointer will be incremented by
219
+ * that amount.
220
+ *
221
+ * @p total_out, if it is not a null-pointer, will be set to the number
222
+ * of bytes decompressed since the last @p state initialization.
223
+ *
224
+ * @note Input is never overconsumed, so @p next_in and @p available_in could be
225
+ * passed to the next consumer after decoding is complete.
226
+ *
227
+ * @param state decoder instance
228
+ * @param[in, out] available_in @b in: amount of available input; \n
229
+ * @b out: amount of unused input
230
+ * @param[in, out] next_in pointer to the next compressed byte
231
+ * @param[in, out] available_out @b in: length of output buffer; \n
232
+ * @b out: remaining size of output buffer
233
+ * @param[in, out] next_out output buffer cursor;
234
+ * can be @c NULL if @p available_out is @c 0
235
+ * @param[out] total_out number of bytes decompressed so far; can be @c NULL
236
+ * @returns ::BROTLI_DECODER_RESULT_ERROR if input is corrupted, memory
237
+ * allocation failed, arguments were invalid, etc.;
238
+ * use ::BrotliDecoderGetErrorCode to get detailed error code
239
+ * @returns ::BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT decoding is blocked until
240
+ * more input data is provided
241
+ * @returns ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT decoding is blocked until
242
+ * more output space is provided
243
+ * @returns ::BROTLI_DECODER_RESULT_SUCCESS decoding is finished, no more
244
+ * input might be consumed and no more output will be produced
245
+ */
246
+ BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompressStream(
247
+ BrotliDecoderState* state, size_t* available_in, const uint8_t** next_in,
248
+ size_t* available_out, uint8_t** next_out, size_t* total_out);
249
+
250
+ /**
251
+ * Checks if decoder has more output.
252
+ *
253
+ * @param state decoder instance
254
+ * @returns ::BROTLI_TRUE, if decoder has some unconsumed output
255
+ * @returns ::BROTLI_FALSE otherwise
256
+ */
257
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderHasMoreOutput(
258
+ const BrotliDecoderState* state);
259
+
260
+ /**
261
+ * Acquires pointer to internal output buffer.
262
+ *
263
+ * This method is used to make language bindings easier and more efficient:
264
+ * -# push data to ::BrotliDecoderDecompressStream,
265
+ * until ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT is reported
266
+ * -# use ::BrotliDecoderTakeOutput to peek bytes and copy to language-specific
267
+ * entity
268
+ *
269
+ * Also this could be useful if there is an output stream that is able to
270
+ * consume all the provided data (e.g. when data is saved to file system).
271
+ *
272
+ * @attention After every call to ::BrotliDecoderTakeOutput @p *size bytes of
273
+ * output are considered consumed for all consecutive calls to the
274
+ * instance methods; returned pointer becomes invalidated as well.
275
+ *
276
+ * @note Decoder output is not guaranteed to be contiguous. This means that
277
+ * after the size-unrestricted call to ::BrotliDecoderTakeOutput,
278
+ * immediate next call to ::BrotliDecoderTakeOutput may return more data.
279
+ *
280
+ * @param state decoder instance
281
+ * @param[in, out] size @b in: number of bytes caller is ready to take, @c 0 if
282
+ * any amount could be handled; \n
283
+ * @b out: amount of data pointed by returned pointer and
284
+ * considered consumed; \n
285
+ * out value is never greater than in value, unless it is @c 0
286
+ * @returns pointer to output data
287
+ */
288
+ BROTLI_DEC_API const uint8_t* BrotliDecoderTakeOutput(
289
+ BrotliDecoderState* state, size_t* size);
290
+
291
+ /**
292
+ * Checks if instance has already consumed input.
293
+ *
294
+ * Instance that returns ::BROTLI_FALSE is considered "fresh" and could be
295
+ * reused.
296
+ *
297
+ * @param state decoder instance
298
+ * @returns ::BROTLI_TRUE if decoder has already used some input bytes
299
+ * @returns ::BROTLI_FALSE otherwise
300
+ */
301
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* state);
302
+
303
+ /**
304
+ * Checks if decoder instance reached the final state.
305
+ *
306
+ * @param state decoder instance
307
+ * @returns ::BROTLI_TRUE if decoder is in a state where it reached the end of
308
+ * the input and produced all of the output
309
+ * @returns ::BROTLI_FALSE otherwise
310
+ */
311
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsFinished(
312
+ const BrotliDecoderState* state);
313
+
314
+ /**
315
+ * Acquires a detailed error code.
316
+ *
317
+ * Should be used only after ::BrotliDecoderDecompressStream returns
318
+ * ::BROTLI_DECODER_RESULT_ERROR.
319
+ *
320
+ * See also ::BrotliDecoderErrorString
321
+ *
322
+ * @param state decoder instance
323
+ * @returns last saved error code
324
+ */
325
+ BROTLI_DEC_API BrotliDecoderErrorCode BrotliDecoderGetErrorCode(
326
+ const BrotliDecoderState* state);
327
+
328
+ /**
329
+ * Converts error code to a c-string.
330
+ */
331
+ BROTLI_DEC_API const char* BrotliDecoderErrorString(BrotliDecoderErrorCode c);
332
+
333
+ /**
334
+ * Gets a decoder library version.
335
+ *
336
+ * Look at BROTLI_VERSION for more information.
337
+ */
338
+ BROTLI_DEC_API uint32_t BrotliDecoderVersion(void);
339
+
340
+ #if defined(__cplusplus) || defined(c_plusplus)
341
+ } /* extern "C" */
342
+ #endif
343
+
344
+ #endif /* BROTLI_DEC_DECODE_H_ */
@@ -0,0 +1,145 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Function to find backward reference copies. */
8
+
9
+ #include "brotli_enc_backward_references.h"
10
+
11
+ #include "brotli_common_constants.h"
12
+ #include "brotli_common_context.h"
13
+ #include "brotli_common_dictionary.h"
14
+ #include "brotli_common_platform.h"
15
+ #include "brotli_types.h"
16
+ #include "brotli_enc_command.h"
17
+ #include "brotli_enc_dictionary_hash.h"
18
+ #include "brotli_enc_memory.h"
19
+ #include "brotli_enc_quality.h"
20
+
21
+ #if defined(__cplusplus) || defined(c_plusplus)
22
+ extern "C" {
23
+ #endif
24
+
25
+ static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance,
26
+ size_t max_distance,
27
+ const int* dist_cache) {
28
+ if (distance <= max_distance) {
29
+ size_t distance_plus_3 = distance + 3;
30
+ size_t offset0 = distance_plus_3 - (size_t)dist_cache[0];
31
+ size_t offset1 = distance_plus_3 - (size_t)dist_cache[1];
32
+ if (distance == (size_t)dist_cache[0]) {
33
+ return 0;
34
+ } else if (distance == (size_t)dist_cache[1]) {
35
+ return 1;
36
+ } else if (offset0 < 7) {
37
+ return (0x9750468 >> (4 * offset0)) & 0xF;
38
+ } else if (offset1 < 7) {
39
+ return (0xFDB1ACE >> (4 * offset1)) & 0xF;
40
+ } else if (distance == (size_t)dist_cache[2]) {
41
+ return 2;
42
+ } else if (distance == (size_t)dist_cache[3]) {
43
+ return 3;
44
+ }
45
+ }
46
+ return distance + BROTLI_NUM_DISTANCE_SHORT_CODES - 1;
47
+ }
48
+
49
+ #define EXPAND_CAT(a, b) CAT(a, b)
50
+ #define CAT(a, b) a ## b
51
+ #define FN(X) EXPAND_CAT(X, HASHER())
52
+ #define EXPORT_FN(X) EXPAND_CAT(X, EXPAND_CAT(PREFIX(), HASHER()))
53
+
54
+ #define PREFIX() N
55
+
56
+ #define HASHER() H2
57
+ /* NOLINTNEXTLINE(build/include) */
58
+ #include "brotli_enc_backward_references_inc.h"
59
+ #undef HASHER
60
+
61
+ #define HASHER() H3
62
+ /* NOLINTNEXTLINE(build/include) */
63
+ #include "brotli_enc_backward_references_inc.h"
64
+ #undef HASHER
65
+
66
+ #define HASHER() H4
67
+ /* NOLINTNEXTLINE(build/include) */
68
+ #include "brotli_enc_backward_references_inc.h"
69
+ #undef HASHER
70
+
71
+ #define HASHER() H5
72
+ /* NOLINTNEXTLINE(build/include) */
73
+ #include "brotli_enc_backward_references_inc.h"
74
+ #undef HASHER
75
+
76
+ #define HASHER() H6
77
+ /* NOLINTNEXTLINE(build/include) */
78
+ #include "brotli_enc_backward_references_inc.h"
79
+ #undef HASHER
80
+
81
+ #define HASHER() H40
82
+ /* NOLINTNEXTLINE(build/include) */
83
+ #include "brotli_enc_backward_references_inc.h"
84
+ #undef HASHER
85
+
86
+ #define HASHER() H41
87
+ /* NOLINTNEXTLINE(build/include) */
88
+ #include "brotli_enc_backward_references_inc.h"
89
+ #undef HASHER
90
+
91
+ #define HASHER() H42
92
+ /* NOLINTNEXTLINE(build/include) */
93
+ #include "brotli_enc_backward_references_inc.h"
94
+ #undef HASHER
95
+
96
+ #define HASHER() H54
97
+ /* NOLINTNEXTLINE(build/include) */
98
+ #include "brotli_enc_backward_references_inc.h"
99
+ #undef HASHER
100
+
101
+ #define HASHER() H35
102
+ /* NOLINTNEXTLINE(build/include) */
103
+ #include "brotli_enc_backward_references_inc.h"
104
+ #undef HASHER
105
+
106
+ #define HASHER() H55
107
+ /* NOLINTNEXTLINE(build/include) */
108
+ #include "brotli_enc_backward_references_inc.h"
109
+ #undef HASHER
110
+
111
+ #define HASHER() H65
112
+ /* NOLINTNEXTLINE(build/include) */
113
+ #include "brotli_enc_backward_references_inc.h"
114
+ #undef HASHER
115
+
116
+ #undef PREFIX
117
+
118
+ #undef EXPORT_FN
119
+ #undef FN
120
+ #undef CAT
121
+ #undef EXPAND_CAT
122
+
123
+ void BrotliCreateBackwardReferences(size_t num_bytes,
124
+ size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
125
+ ContextLut literal_context_lut, const BrotliEncoderParams* params,
126
+ Hasher* hasher, int* dist_cache, size_t* last_insert_len,
127
+ Command* commands, size_t* num_commands, size_t* num_literals) {
128
+ switch (params->hasher.type) {
129
+ #define CASE_(N) \
130
+ case N: \
131
+ CreateBackwardReferencesNH ## N(num_bytes, \
132
+ position, ringbuffer, ringbuffer_mask, \
133
+ literal_context_lut, params, hasher, dist_cache, \
134
+ last_insert_len, commands, num_commands, num_literals); \
135
+ return;
136
+ FOR_GENERIC_HASHERS(CASE_)
137
+ #undef CASE_
138
+ default:
139
+ break;
140
+ }
141
+ }
142
+
143
+ #if defined(__cplusplus) || defined(c_plusplus)
144
+ } /* extern "C" */
145
+ #endif
@@ -0,0 +1,39 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Function to find backward reference copies. */
8
+
9
+ #ifndef BROTLI_ENC_BACKWARD_REFERENCES_H_
10
+ #define BROTLI_ENC_BACKWARD_REFERENCES_H_
11
+
12
+ #include "brotli_common_constants.h"
13
+ #include "brotli_common_context.h"
14
+ #include "brotli_common_dictionary.h"
15
+ #include "brotli_common_platform.h"
16
+ #include "brotli_types.h"
17
+ #include "brotli_enc_command.h"
18
+ #include "brotli_enc_hash.h"
19
+ #include "brotli_enc_quality.h"
20
+
21
+ #if defined(__cplusplus) || defined(c_plusplus)
22
+ extern "C" {
23
+ #endif
24
+
25
+ /* "commands" points to the next output command to write to, "*num_commands" is
26
+ initially the total amount of commands output by previous
27
+ CreateBackwardReferences calls, and must be incremented by the amount written
28
+ by this call. */
29
+ BROTLI_INTERNAL void BrotliCreateBackwardReferences(size_t num_bytes,
30
+ size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
31
+ ContextLut literal_context_lut, const BrotliEncoderParams* params,
32
+ Hasher* hasher, int* dist_cache, size_t* last_insert_len,
33
+ Command* commands, size_t* num_commands, size_t* num_literals);
34
+
35
+ #if defined(__cplusplus) || defined(c_plusplus)
36
+ } /* extern "C" */
37
+ #endif
38
+
39
+ #endif /* BROTLI_ENC_BACKWARD_REFERENCES_H_ */