+++ /dev/null
-/* Copyright 2013 Google Inc. All Rights Reserved.\r
-\r
- Distributed under MIT license.\r
- See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r
-*/\r
-\r
-/**\r
- * @file\r
- * API for Brotli decompression.\r
- */\r
-\r
-#ifndef BROTLI_DEC_DECODE_H_\r
-#define BROTLI_DEC_DECODE_H_\r
-\r
-#include <brotli/port.h>\r
-#include <brotli/types.h>\r
-\r
-#if defined(__cplusplus) || defined(c_plusplus)\r
-extern "C" {\r
-#endif\r
-\r
-/**\r
- * Opaque structure that holds decoder state.\r
- *\r
- * Allocated and initialized with ::BrotliDecoderCreateInstance.\r
- * Cleaned up and deallocated with ::BrotliDecoderDestroyInstance.\r
- */\r
-typedef struct BrotliDecoderStateStruct BrotliDecoderState;\r
-\r
-/**\r
- * Result type for ::BrotliDecoderDecompress and\r
- * ::BrotliDecoderDecompressStream functions.\r
- */\r
-typedef enum {\r
- /** Decoding error, e.g. corrupted input or memory allocation problem. */\r
- BROTLI_DECODER_RESULT_ERROR = 0,\r
- /** Decoding successfully completed. */\r
- BROTLI_DECODER_RESULT_SUCCESS = 1,\r
- /** Partially done; should be called again with more input. */\r
- BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT = 2,\r
- /** Partially done; should be called again with more output. */\r
- BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT = 3\r
-} BrotliDecoderResult;\r
-\r
-/**\r
- * Template that evaluates items of ::BrotliDecoderErrorCode.\r
- *\r
- * Example: @code {.cpp}\r
- * // Log Brotli error code.\r
- * switch (brotliDecoderErrorCode) {\r
- * #define CASE_(PREFIX, NAME, CODE) \\r
- * case BROTLI_DECODER ## PREFIX ## NAME: \\r
- * LOG(INFO) << "error code:" << #NAME; \\r
- * break;\r
- * #define NEWLINE_\r
- * BROTLI_DECODER_ERROR_CODES_LIST(CASE_, NEWLINE_)\r
- * #undef CASE_\r
- * #undef NEWLINE_\r
- * default: LOG(FATAL) << "unknown brotli error code";\r
- * }\r
- * @endcode\r
- */\r
-#define BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR) \\r
- BROTLI_ERROR_CODE(_, NO_ERROR, 0) SEPARATOR \\r
- /* Same as BrotliDecoderResult values */ \\r
- BROTLI_ERROR_CODE(_, SUCCESS, 1) SEPARATOR \\r
- BROTLI_ERROR_CODE(_, NEEDS_MORE_INPUT, 2) SEPARATOR \\r
- BROTLI_ERROR_CODE(_, NEEDS_MORE_OUTPUT, 3) SEPARATOR \\r
- \\r
- /* Errors caused by invalid input */ \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_NIBBLE, -1) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, RESERVED, -2) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_META_NIBBLE, -3) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_ALPHABET, -4) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_SAME, -5) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, CL_SPACE, -6) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, HUFFMAN_SPACE, -7) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, CONTEXT_MAP_REPEAT, -8) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_1, -9) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_2, -10) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, TRANSFORM, -11) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, DICTIONARY, -12) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, WINDOW_BITS, -13) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_1, -14) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_FORMAT_, DISTANCE, -16) SEPARATOR \\r
- \\r
- /* -17..-18 codes are reserved */ \\r
- \\r
- BROTLI_ERROR_CODE(_ERROR_, DICTIONARY_NOT_SET, -19) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_, INVALID_ARGUMENTS, -20) SEPARATOR \\r
- \\r
- /* Memory allocation problems */ \\r
- BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MODES, -21) SEPARATOR \\r
- /* Literal, insert and distance trees together */ \\r
- BROTLI_ERROR_CODE(_ERROR_ALLOC_, TREE_GROUPS, -22) SEPARATOR \\r
- /* -23..-24 codes are reserved for distinct tree groups */ \\r
- BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MAP, -25) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_1, -26) SEPARATOR \\r
- BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_2, -27) SEPARATOR \\r
- /* -28..-29 codes are reserved for dynamic ring-buffer allocation */ \\r
- BROTLI_ERROR_CODE(_ERROR_ALLOC_, BLOCK_TYPE_TREES, -30) SEPARATOR \\r
- \\r
- /* "Impossible" states */ \\r
- BROTLI_ERROR_CODE(_ERROR_, UNREACHABLE, -31)\r
-\r
-/**\r
- * Error code for detailed logging / production debugging.\r
- *\r
- * See ::BrotliDecoderGetErrorCode and ::BROTLI_LAST_ERROR_CODE.\r
- */\r
-typedef enum {\r
-#define BROTLI_COMMA_ ,\r
-#define BROTLI_ERROR_CODE_ENUM_ITEM_(PREFIX, NAME, CODE) \\r
- BROTLI_DECODER ## PREFIX ## NAME = CODE\r
- BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE_ENUM_ITEM_, BROTLI_COMMA_)\r
-} BrotliDecoderErrorCode;\r
-#undef BROTLI_ERROR_CODE_ENUM_ITEM_\r
-#undef BROTLI_COMMA_\r
-\r
-/**\r
- * The value of the last error code, negative integer.\r
- *\r
- * All other error code values are in the range from ::BROTLI_LAST_ERROR_CODE\r
- * to @c -1. There are also 4 other possible non-error codes @c 0 .. @c 3 in\r
- * ::BrotliDecoderErrorCode enumeration.\r
- */\r
-#define BROTLI_LAST_ERROR_CODE BROTLI_DECODER_ERROR_UNREACHABLE\r
-\r
-/** Options to be used with ::BrotliDecoderSetParameter. */\r
-typedef enum BrotliDecoderParameter {\r
- /**\r
- * Disable "canny" ring buffer allocation strategy.\r
- *\r
- * Ring buffer is allocated according to window size, despite the real size of\r
- * the content.\r
- */\r
- BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION = 0,\r
- /**\r
- * Flag that determines if "Large Window Brotli" is used.\r
- */\r
- BROTLI_DECODER_PARAM_LARGE_WINDOW = 1\r
-} BrotliDecoderParameter;\r
-\r
-/**\r
- * Sets the specified parameter to the given decoder instance.\r
- *\r
- * @param state decoder instance\r
- * @param param parameter to set\r
- * @param value new parameter value\r
- * @returns ::BROTLI_FALSE if parameter is unrecognized, or value is invalid\r
- * @returns ::BROTLI_TRUE if value is accepted\r
- */\r
-BROTLI_DEC_API BROTLI_BOOL BrotliDecoderSetParameter(\r
- BrotliDecoderState* state, BrotliDecoderParameter param, uint32_t value);\r
-\r
-/**\r
- * Creates an instance of ::BrotliDecoderState and initializes it.\r
- *\r
- * The instance can be used once for decoding and should then be destroyed with\r
- * ::BrotliDecoderDestroyInstance, it cannot be reused for a new decoding\r
- * session.\r
- *\r
- * @p alloc_func and @p free_func @b MUST be both zero or both non-zero. In the\r
- * case they are both zero, default memory allocators are used. @p opaque is\r
- * passed to @p alloc_func and @p free_func when they are called. @p free_func\r
- * has to return without doing anything when asked to free a NULL pointer.\r
- *\r
- * @param alloc_func custom memory allocation function\r
- * @param free_func custom memory free function\r
- * @param opaque custom memory manager handle\r
- * @returns @c 0 if instance can not be allocated or initialized\r
- * @returns pointer to initialized ::BrotliDecoderState otherwise\r
- */\r
-BROTLI_DEC_API BrotliDecoderState* BrotliDecoderCreateInstance(\r
- brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);\r
-\r
-/**\r
- * Deinitializes and frees ::BrotliDecoderState instance.\r
- *\r
- * @param state decoder instance to be cleaned up and deallocated\r
- */\r
-BROTLI_DEC_API void BrotliDecoderDestroyInstance(BrotliDecoderState* state);\r
-\r
-/**\r
- * Performs one-shot memory-to-memory decompression.\r
- *\r
- * Decompresses the data in @p encoded_buffer into @p decoded_buffer, and sets\r
- * @p *decoded_size to the decompressed length.\r
- *\r
- * @param encoded_size size of @p encoded_buffer\r
- * @param encoded_buffer compressed data buffer with at least @p encoded_size\r
- * addressable bytes\r
- * @param[in, out] decoded_size @b in: size of @p decoded_buffer; \n\r
- * @b out: length of decompressed data written to\r
- * @p decoded_buffer\r
- * @param decoded_buffer decompressed data destination buffer\r
- * @returns ::BROTLI_DECODER_RESULT_ERROR if input is corrupted, memory\r
- * allocation failed, or @p decoded_buffer is not large enough;\r
- * @returns ::BROTLI_DECODER_RESULT_SUCCESS otherwise\r
- */\r
-BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompress(\r
- size_t encoded_size,\r
- const uint8_t encoded_buffer[BROTLI_ARRAY_PARAM(encoded_size)],\r
- size_t* decoded_size,\r
- uint8_t decoded_buffer[BROTLI_ARRAY_PARAM(*decoded_size)]);\r
-\r
-/**\r
- * Decompresses the input stream to the output stream.\r
- *\r
- * The values @p *available_in and @p *available_out must specify the number of\r
- * bytes addressable at @p *next_in and @p *next_out respectively.\r
- * When @p *available_out is @c 0, @p next_out is allowed to be @c NULL.\r
- *\r
- * After each call, @p *available_in will be decremented by the amount of input\r
- * bytes consumed, and the @p *next_in pointer will be incremented by that\r
- * amount. Similarly, @p *available_out will be decremented by the amount of\r
- * output bytes written, and the @p *next_out pointer will be incremented by\r
- * that amount.\r
- *\r
- * @p total_out, if it is not a null-pointer, will be set to the number\r
- * of bytes decompressed since the last @p state initialization.\r
- *\r
- * @note Input is never overconsumed, so @p next_in and @p available_in could be\r
- * passed to the next consumer after decoding is complete.\r
- *\r
- * @param state decoder instance\r
- * @param[in, out] available_in @b in: amount of available input; \n\r
- * @b out: amount of unused input\r
- * @param[in, out] next_in pointer to the next compressed byte\r
- * @param[in, out] available_out @b in: length of output buffer; \n\r
- * @b out: remaining size of output buffer\r
- * @param[in, out] next_out output buffer cursor;\r
- * can be @c NULL if @p available_out is @c 0\r
- * @param[out] total_out number of bytes decompressed so far; can be @c NULL\r
- * @returns ::BROTLI_DECODER_RESULT_ERROR if input is corrupted, memory\r
- * allocation failed, arguments were invalid, etc.;\r
- * use ::BrotliDecoderGetErrorCode to get detailed error code\r
- * @returns ::BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT decoding is blocked until\r
- * more input data is provided\r
- * @returns ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT decoding is blocked until\r
- * more output space is provided\r
- * @returns ::BROTLI_DECODER_RESULT_SUCCESS decoding is finished, no more\r
- * input might be consumed and no more output will be produced\r
- */\r
-BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompressStream(\r
- BrotliDecoderState* state, size_t* available_in, const uint8_t** next_in,\r
- size_t* available_out, uint8_t** next_out, size_t* total_out);\r
-\r
-/**\r
- * Checks if decoder has more output.\r
- *\r
- * @param state decoder instance\r
- * @returns ::BROTLI_TRUE, if decoder has some unconsumed output\r
- * @returns ::BROTLI_FALSE otherwise\r
- */\r
-BROTLI_DEC_API BROTLI_BOOL BrotliDecoderHasMoreOutput(\r
- const BrotliDecoderState* state);\r
-\r
-/**\r
- * Acquires pointer to internal output buffer.\r
- *\r
- * This method is used to make language bindings easier and more efficient:\r
- * -# push data to ::BrotliDecoderDecompressStream,\r
- * until ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT is reported\r
- * -# use ::BrotliDecoderTakeOutput to peek bytes and copy to language-specific\r
- * entity\r
- *\r
- * Also this could be useful if there is an output stream that is able to\r
- * consume all the provided data (e.g. when data is saved to file system).\r
- *\r
- * @attention After every call to ::BrotliDecoderTakeOutput @p *size bytes of\r
- * output are considered consumed for all consecutive calls to the\r
- * instance methods; returned pointer becomes invalidated as well.\r
- *\r
- * @note Decoder output is not guaranteed to be contiguous. This means that\r
- * after the size-unrestricted call to ::BrotliDecoderTakeOutput,\r
- * immediate next call to ::BrotliDecoderTakeOutput may return more data.\r
- *\r
- * @param state decoder instance\r
- * @param[in, out] size @b in: number of bytes caller is ready to take, @c 0 if\r
- * any amount could be handled; \n\r
- * @b out: amount of data pointed by returned pointer and\r
- * considered consumed; \n\r
- * out value is never greater than in value, unless it is @c 0\r
- * @returns pointer to output data\r
- */\r
-BROTLI_DEC_API const uint8_t* BrotliDecoderTakeOutput(\r
- BrotliDecoderState* state, size_t* size);\r
-\r
-/**\r
- * Checks if instance has already consumed input.\r
- *\r
- * Instance that returns ::BROTLI_FALSE is considered "fresh" and could be\r
- * reused.\r
- *\r
- * @param state decoder instance\r
- * @returns ::BROTLI_TRUE if decoder has already used some input bytes\r
- * @returns ::BROTLI_FALSE otherwise\r
- */\r
-BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* state);\r
-\r
-/**\r
- * Checks if decoder instance reached the final state.\r
- *\r
- * @param state decoder instance\r
- * @returns ::BROTLI_TRUE if decoder is in a state where it reached the end of\r
- * the input and produced all of the output\r
- * @returns ::BROTLI_FALSE otherwise\r
- */\r
-BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsFinished(\r
- const BrotliDecoderState* state);\r
-\r
-/**\r
- * Acquires a detailed error code.\r
- *\r
- * Should be used only after ::BrotliDecoderDecompressStream returns\r
- * ::BROTLI_DECODER_RESULT_ERROR.\r
- *\r
- * See also ::BrotliDecoderErrorString\r
- *\r
- * @param state decoder instance\r
- * @returns last saved error code\r
- */\r
-BROTLI_DEC_API BrotliDecoderErrorCode BrotliDecoderGetErrorCode(\r
- const BrotliDecoderState* state);\r
-\r
-/**\r
- * Converts error code to a c-string.\r
- */\r
-BROTLI_DEC_API const char* BrotliDecoderErrorString(BrotliDecoderErrorCode c);\r
-\r
-/**\r
- * Gets a decoder library version.\r
- *\r
- * Look at BROTLI_VERSION for more information.\r
- */\r
-BROTLI_DEC_API uint32_t BrotliDecoderVersion(void);\r
-\r
-#if defined(__cplusplus) || defined(c_plusplus)\r
-} /* extern "C" */\r
-#endif\r
-\r
-#endif /* BROTLI_DEC_DECODE_H_ */\r