Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: third_party/brotli/dec/decode.h

Issue 2537133002: Update brotli to v1.0.0-snapshot. (Closed)
Patch Set: Fixed typo Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/brotli/dec/context.h ('k') | third_party/brotli/dec/decode.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 /* API for Brotli decompression */
8
9 #ifndef BROTLI_DEC_DECODE_H_
10 #define BROTLI_DEC_DECODE_H_
11
12 #include "./types.h"
13
14 #if defined(__cplusplus) || defined(c_plusplus)
15 extern "C" {
16 #endif
17
18 typedef struct BrotliStateStruct BrotliState;
19
20 typedef enum {
21 /* Decoding error, e.g. corrupt input or memory allocation problem */
22 BROTLI_RESULT_ERROR = 0,
23 /* Decoding successfully completed */
24 BROTLI_RESULT_SUCCESS = 1,
25 /* Partially done; should be called again with more input */
26 BROTLI_RESULT_NEEDS_MORE_INPUT = 2,
27 /* Partially done; should be called again with more output */
28 BROTLI_RESULT_NEEDS_MORE_OUTPUT = 3
29 } BrotliResult;
30
31 typedef enum {
32 BROTLI_NO_ERROR = 0,
33 /* Same as BrotliResult values */
34 BROTLI_SUCCESS = 1,
35 BROTLI_NEEDS_MORE_INPUT = 2,
36 BROTLI_NEEDS_MORE_OUTPUT = 3,
37
38 /* Errors caused by invalid input */
39 BROTLI_ERROR_FORMAT_EXUBERANT_NIBBLE = -1,
40 BROTLI_ERROR_FORMAT_RESERVED = -2,
41 BROTLI_ERROR_FORMAT_EXUBERANT_META_NIBBLE = -3,
42 BROTLI_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET = -4,
43 BROTLI_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME = -5,
44 BROTLI_ERROR_FORMAT_CL_SPACE = -6,
45 BROTLI_ERROR_FORMAT_HUFFMAN_SPACE = -7,
46 BROTLI_ERROR_FORMAT_CONTEXT_MAP_REPEAT = -8,
47 BROTLI_ERROR_FORMAT_BLOCK_LENGTH_1 = -9,
48 BROTLI_ERROR_FORMAT_BLOCK_LENGTH_2 = -10,
49 BROTLI_ERROR_FORMAT_TRANSFORM = -11,
50 BROTLI_ERROR_FORMAT_DICTIONARY = -12,
51 BROTLI_ERROR_FORMAT_WINDOW_BITS = -13,
52 BROTLI_ERROR_FORMAT_PADDING_1 = -14,
53 BROTLI_ERROR_FORMAT_PADDING_2 = -15,
54
55 /* -16..-20 codes are reserved */
56
57 /* Memory allocation problems */
58 BROTLI_ERROR_ALLOC_CONTEXT_MODES = -21,
59 BROTLI_ERROR_ALLOC_TREE_GROUPS = -22, /* Literal, insert, distance */
60 /* -23..-24 codes are reserved for distinct tree groups */
61 BROTLI_ERROR_ALLOC_CONTEXT_MAP = -25,
62 BROTLI_ERROR_ALLOC_RING_BUFFER_1 = -26,
63 BROTLI_ERROR_ALLOC_RING_BUFFER_2 = -27,
64 /* -28..-29 codes are reserved for dynamic ringbuffer allocation */
65 BROTLI_ERROR_ALLOC_BLOCK_TYPE_TREES = -30,
66
67 /* "Impossible" states */
68 BROTLI_ERROR_UNREACHABLE_1 = -31,
69 BROTLI_ERROR_UNREACHABLE_2 = -32,
70 BROTLI_ERROR_UNREACHABLE_3 = -33,
71 BROTLI_ERROR_UNREACHABLE_4 = -34,
72 BROTLI_ERROR_UNREACHABLE_5 = -35,
73 BROTLI_ERROR_UNREACHABLE_6 = -36
74 } BrotliErrorCode;
75
76 #define BROTLI_LAST_ERROR_CODE BROTLI_ERROR_UNREACHABLE_6
77
78 /* Creates the instance of BrotliState and initializes it. |alloc_func| and
79 |free_func| MUST be both zero or both non-zero. In the case they are both
80 zero, default memory allocators are used. |opaque| is passed to |alloc_func|
81 and |free_func| when they are called. */
82 BrotliState* BrotliCreateState(
83 brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
84
85 /* Deinitializes and frees BrotliState instance. */
86 void BrotliDestroyState(BrotliState* state);
87
88 /* Sets |*decoded_size| to the decompressed size of the given encoded stream.
89 This function only works if the encoded buffer has a single meta block,
90 or if it has two meta-blocks, where the first is uncompressed and the
91 second is empty.
92 Returns 1 on success, 0 on failure. */
93 int BrotliDecompressedSize(size_t encoded_size,
94 const uint8_t* encoded_buffer,
95 size_t* decoded_size);
96
97 /* Decompresses the data in |encoded_buffer| into |decoded_buffer|, and sets
98 |*decoded_size| to the decompressed length. */
99 BrotliResult BrotliDecompressBuffer(size_t encoded_size,
100 const uint8_t* encoded_buffer,
101 size_t* decoded_size,
102 uint8_t* decoded_buffer);
103
104 /* Decompresses the data. Supports partial input and output.
105
106 Must be called with an allocated input buffer in |*next_in| and an allocated
107 output buffer in |*next_out|. The values |*available_in| and |*available_out|
108 must specify the allocated size in |*next_in| and |*next_out| respectively.
109
110 After each call, |*available_in| will be decremented by the amount of input
111 bytes consumed, and the |*next_in| pointer will be incremented by that
112 amount. Similarly, |*available_out| will be decremented by the amount of
113 output bytes written, and the |*next_out| pointer will be incremented by that
114 amount. |total_out| will be set to the number of bytes decompressed since
115 last state initialization.
116
117 Input is never overconsumed, so |next_in| and |available_in| could be passed
118 to the next consumer after decoding is complete. */
119 BrotliResult BrotliDecompressStream(size_t* available_in,
120 const uint8_t** next_in,
121 size_t* available_out,
122 uint8_t** next_out,
123 size_t* total_out,
124 BrotliState* s);
125
126 /* Fills the new state with a dictionary for LZ77, warming up the ringbuffer,
127 e.g. for custom static dictionaries for data formats.
128 Not to be confused with the built-in transformable dictionary of Brotli.
129 |size| should be less or equal to 2^24 (16MiB), otherwise the dictionary will
130 be ignored. The dictionary must exist in memory until decoding is done and
131 is owned by the caller. To use:
132 1) Allocate and initialize state with BrotliCreateState
133 2) Use BrotliSetCustomDictionary
134 3) Use BrotliDecompressStream
135 4) Clean up and free state with BrotliDestroyState
136 */
137 void BrotliSetCustomDictionary(
138 size_t size, const uint8_t* dict, BrotliState* s);
139
140 /* Returns 1, if s is in a state where we have not read any input bytes yet,
141 and 0 otherwise */
142 int BrotliStateIsStreamStart(const BrotliState* s);
143
144 /* Returns 1, if s is in a state where we reached the end of the input and
145 produced all of the output, and 0 otherwise. */
146 int BrotliStateIsStreamEnd(const BrotliState* s);
147
148 /* Returns detailed error code after BrotliDecompressStream returns
149 BROTLI_RESULT_ERROR. */
150 BrotliErrorCode BrotliGetErrorCode(const BrotliState* s);
151
152 #if defined(__cplusplus) || defined(c_plusplus)
153 } /* extern "C" */
154 #endif
155
156 #endif /* BROTLI_DEC_DECODE_H_ */
OLDNEW
« no previous file with comments | « third_party/brotli/dec/context.h ('k') | third_party/brotli/dec/decode.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698