decode.h(3)
π decode.h β the Brotli decompression API, bestie edition π
okay so this is decode.h, a page from the Library Functions Manual, and it's literally the whole API for Brotli decompression. if you've ever wondered how to un-squish a Brotli stream, this is the header that hands you the keys. no cap. π
β¨ NAME β¨
decode.h β API for Brotli decompression. that's it, that's the whole vibe. she decompresses. π
πΈ SYNOPSIS πΈ
π§ Macros
#define BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR)β a template that evaluates items ofBrotliDecoderErrorCode. iykyk, you feed it macros and it does the thing.#define BROTLI_LAST_ERROR_CODE BROTLI_DECODER_ERROR_UNREACHABLEβ the value of the last error code, and it's a negative integer. π«Ά
π¦ Typedefs
typedef void(* brotli_decoder_metadata_chunk_func) (void *opaque, const uint8_t *data, size_t size)β the callback that fires when a metadata block chunk becomes available.typedef void(* brotli_decoder_metadata_start_func) (void *opaque, size_t size)β the callback that fires on metadata block start.typedef enum BrotliDecoderParameter BrotliDecoderParameterβ options to be used withBrotliDecoderSetParameter.typedef struct BrotliDecoderStateStruct BrotliDecoderStateβ an opaque structure that holds decoder state. main character energy, but you can't peek inside her. π
π Enumerations
(she's listed here, the actual enumerators live further down, be patient bestie)
β Functions
BROTLI_BOOL BrotliDecoderAttachDictionary (BrotliDecoderState *state, BrotliSharedDictionaryType type, size_t data_size, const uint8_t data[data_size])β adds an LZ77 prefix dictionary, and adds or replaces the built-in static dictionary and transforms.BrotliDecoderState * BrotliDecoderCreateInstance (brotli_alloc_func alloc_func, brotli_free_func free_func, void *opaque)β creates an instance ofBrotliDecoderStateand initializes it.BrotliDecoderResult BrotliDecoderDecompress (size_t encoded_size, const uint8_t encoded_buffer[encoded_size], size_t *decoded_size, uint8_t decoded_buffer[*decoded_size])β performs one-shot memory-to-memory decompression.BrotliDecoderResult BrotliDecoderDecompressStream (BrotliDecoderState *state, size_t *available_in, const uint8_t **next_in, size_t *available_out, uint8_t **next_out, size_t *total_out)β decompresses the input stream to the output stream.void BrotliDecoderDestroyInstance (BrotliDecoderState *state)β deinitializes and frees aBrotliDecoderStateinstance. rest in peace queen ποΈconst char * BrotliDecoderErrorString (BrotliDecoderErrorCode c)β converts an error code to a c-string.BrotliDecoderErrorCode BrotliDecoderGetErrorCode (const BrotliDecoderState *state)β acquires a detailed error code.BROTLI_BOOL BrotliDecoderHasMoreOutput (const BrotliDecoderState *state)β checks if the decoder has more output.BROTLI_BOOL BrotliDecoderIsFinished (const BrotliDecoderState *state)β checks if the decoder instance reached the final state.BROTLI_BOOL BrotliDecoderIsUsed (const BrotliDecoderState *state)β checks if the instance has already consumed input.void BrotliDecoderSetMetadataCallbacks (BrotliDecoderState *state, brotli_decoder_metadata_start_func start_func, brotli_decoder_metadata_chunk_func chunk_func, void *opaque)β sets the callback for receiving metadata blocks.BROTLI_BOOL BrotliDecoderSetParameter (BrotliDecoderState *state, BrotliDecoderParameter param, uint32_t value)β sets the specified parameter to the given decoder instance.const uint8_t * BrotliDecoderTakeOutput (BrotliDecoderState *state, size_t *size)β acquires a pointer to the internal output buffer.uint32_t BrotliDecoderVersion (void)β gets a decoder library version.
π Detailed Description π
API for Brotli decompression. periodt.
π Macro Definition Documentation π
#define BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR)
Template that evaluates items of BrotliDecoderErrorCode. Example:
// Log Brotli error code.
switch (brotliDecoderErrorCode) {
#define CASE_(PREFIX, NAME, CODE) case BROTLI_DECODER ## PREFIX ## NAME: LOG(INFO) << "error code:" << #NAME; break;
#define NEWLINE_
BROTLI_DECODER_ERROR_CODES_LIST(CASE_, NEWLINE_)
#undef CASE_
#undef NEWLINE_
default: LOG(FATAL) << "unknown brotli error code";
}
#define BROTLI_LAST_ERROR_CODE BROTLI_DECODER_ERROR_UNREACHABLE
The value of the last error code, a negative integer. All other error code values are in the range from BROTLI_LAST_ERROR_CODE to -1. There are also 4 other possible non-error codes 0 .. 3 in the BrotliDecoderErrorCode enumeration. so like, don't panic if you see a tiny number, she's not mad at you π
π Typedef Documentation π
typedef void(* brotli_decoder_metadata_chunk_func) (void *opaque, const uint8_t *data, size_t size)
Callback to fire on metadata block chunk becomes available. this function can be invoked multiple times per metadata block; the block should be considered finished when the sum of size matches the announced metadata block size.
β οΈ ngl this part matters: chunks' contents pointed by data are transient and shouln not be accessed after leaving the callback. (yes, "shouln" β we keep the typo, we don't fix the queen's spelling π)
Parameters:
opaqueβ callback handledataβ pointer to metadata contentssizeβ size of metadata block chunk, at least 1
typedef void(* brotli_decoder_metadata_start_func) (void *opaque, size_t size)
Callback to fire on metadata block start. After this callback is fired, if size is not 0, it is followed by brotli_decoder_metadata_chunk_func as more metadata block contents become accessible.
Parameters:
opaqueβ callback handlesizeβ size of metadata block
typedef enum BrotliDecoderParameter BrotliDecoderParameter
Options to be used with BrotliDecoderSetParameter. slay.
typedef struct BrotliDecoderStateStruct BrotliDecoderState
Opaque structure that holds decoder state. Allocated and initialized with BrotliDecoderCreateInstance. Cleaned up and deallocated with BrotliDecoderDestroyInstance. she is born, she decodes, she is freed. iconic arc honestly. β¨
π Enumeration Type Documentation π
enum BrotliDecoderErrorCode
Error code for detailed logging / production debugging. See BrotliDecoderGetErrorCode and BROTLI_LAST_ERROR_CODE.
enum BrotliDecoderParameter
Options to be used with BrotliDecoderSetParameter.
Enumerator
BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATIONβ disable the 'canny' ring buffer allocation strategy. the ring buffer is allocated according to window size, despite the real size of the content.BROTLI_DECODER_PARAM_LARGE_WINDOWβ flag that determines if 'Large Window Brotli' is used.
enum BrotliDecoderResult
Result type for BrotliDecoderDecompress and BrotliDecoderDecompressStream functions.
Enumerator
BROTLI_DECODER_RESULT_ERRORβ decoding error, e.g. corrupted input or memory allocation problem. πBROTLI_DECODER_RESULT_SUCCESSβ decoding successfully completed. ate. πBROTLI_DECODER_RESULT_NEEDS_MORE_INPUTβ partially done; should be called again with more input.BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUTβ partially done; should be called again with more output.
okay bestie, that's part 1 β the rest is still coming, don't go anywhere π«Ά
β¨ FUNCTION DOCUMENTATION β¨
Bestie, this is the main character section. Every function you get to call, with the receipts on params and return values. Buckle up. π
π BrotliDecoderAttachDictionary
BROTLI_BOOL BrotliDecoderAttachDictionary (BrotliDecoderState * state,
BrotliSharedDictionaryType type, size_t data_size, const uint8_t
data[data_size])
Adds an LZ77 prefix dictionary, and also adds or replaces the built-in static dictionary and its transforms. Okay so here's the tea: attached dictionary ownership is not transferred. So the data you hand over? You have to keep it accessible until decoding is done and the decoder instance is destroyed. No handing it off and forgetting, bestie. π
Note: Dictionaries can NOT be attached after actual decoding is started. Like, the door closes. That's it.
Parameters:
stateβ decoder instancetypeβ dictionary data formatdata_sizeβ length of the memory region pointed to bydatadataβ dictionary data, in the format that corresponds totype
Returns:
BROTLI_FALSEif the dictionary is corrupted, or if the dictionary count limit is reachedBROTLI_TRUEif the dictionary is accepted / attached β¨
π¦ BrotliDecoderCreateInstance
BrotliDecoderState* BrotliDecoderCreateInstance (brotli_alloc_func
alloc_func, brotli_free_func free_func, void * opaque)
Creates an instance of BrotliDecoderState and initializes it. Ngl this is where it all begins. The instance can be used once for decoding and should then be destroyed with BrotliDecoderDestroyInstance β it cannot be reused for a new decoding session. One and done, one-shot icon behavior. π
alloc_func and free_func MUST be both zero or both non-zero. In the case they are both zero, default memory allocators are used. opaque gets passed to alloc_func and free_func when they're called. And free_func has to return without doing anything when asked to free a NULL pointer. That's the rule, fr fr.
Parameters:
alloc_funcβ custom memory allocation functionfree_funcβ custom memory free functionopaqueβ custom memory manager handle
Returns:
0if the instance can not be allocated or initialized- a pointer to the initialized
BrotliDecoderStateotherwise π«Ά
πΈ BrotliDecoderDecompress
BrotliDecoderResult BrotliDecoderDecompress (size_t encoded_size, const
uint8_t encoded_buffer[encoded_size], size_t * decoded_size, uint8_t
decoded_buffer[*decoded_size])
Performs one-shot memory-to-memory decompression. Decompresses the data in encoded_buffer into decoded_buffer, and sets *decoded_size to the decompressed length. No streaming, no drama, just in and out. π₯
Parameters:
encoded_sizeβ size ofencoded_bufferencoded_bufferβ compressed data buffer with at leastencoded_sizeaddressable bytesdecoded_sizeβ in: size ofdecoded_buffer; out: length of the decompressed data written todecoded_bufferdecoded_bufferβ decompressed data destination buffer
Returns:
BROTLI_DECODER_RESULT_ERRORif the input is corrupted, memory allocation failed, ordecoded_bufferis not large enoughBROTLI_DECODER_RESULT_SUCCESSotherwise π
β BrotliDecoderDecompressStream
BrotliDecoderResult BrotliDecoderDecompressStream (BrotliDecoderState *
state, size_t * available_in, const uint8_t ** next_in, size_t *
available_out, uint8_t ** next_out, size_t * total_out)
Decompresses the input stream to the output stream. The values *available_in and *available_out must specify the number of bytes addressable at *next_in and *next_out respectively. When *available_out is 0, next_out is allowed to be NULL. Okay so this one's the workhorse, the main character, the whole vibe. π
After each call, *available_in will be decremented by the amount of input bytes consumed, and the *next_in pointer will be incremented by that amount. Similarly, *available_out will be decremented by the amount of output bytes written, and the *next_out pointer will be incremented by that amount.
total_out, if it is not a null-pointer, will be set to the number of bytes decompressed since the last state initialization.
Note: Input is never overconsumed, sonext_inandavailable_incould be passed to the next consumer after decoding is complete. So polite. So considerate. π§
Parameters:
stateβ decoder instanceavailable_inβ in: amount of available input; out: amount of unused inputnext_inβ pointer to the next compressed byteavailable_outβ in: length of output buffer; out: remaining size of output buffernext_outβ output buffer cursor; can beNULLifavailable_outis0total_outβ number of bytes decompressed so far; can beNULL
Returns:
BROTLI_DECODER_RESULT_ERRORif the input is corrupted, memory allocation failed, arguments were invalid, etc.; useBrotliDecoderGetErrorCodeto get the detailed error codeBROTLI_DECODER_RESULT_NEEDS_MORE_INPUTβ decoding is blocked until more input data is providedBROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUTβ decoding is blocked until more output space is providedBROTLI_DECODER_RESULT_SUCCESSβ decoding is finished, no more input might be consumed and no more output will be produced π
π BrotliDecoderDestroyInstance
void BrotliDecoderDestroyInstance (BrotliDecoderState * state)
Deinitializes and frees the BrotliDecoderState instance. The farewell tour. Say your goodbyes, clean up after yourself, leave no trace. π
Parameters:
stateβ decoder instance to be cleaned up and deallocated
π BrotliDecoderGetErrorCode
BrotliDecoderErrorCode BrotliDecoderGetErrorCode (const BrotliDecoderState *
state)
Acquires a detailed error code. Should be used only after BrotliDecoderDecompressStream returns BROTLI_DECODER_RESULT_ERROR. Like, don't come asking for the error code before there's an error, bestie. It's giving premature. π
See also BrotliDecoderErrorString
Parameters:
stateβ decoder instance
Returns:
- the last saved error code
β¨ BrotliDecoderHasMoreOutput
BROTLI_BOOL BrotliDecoderHasMoreOutput (const BrotliDecoderState * state)
Checks if the decoder has more output. Vibe check on the output buffer. π
Parameters:
stateβ decoder instance
Returns:
BROTLI_TRUEif the decoder has some unconsumed outputBROTLI_FALSEotherwise
π BrotliDecoderIsFinished
BROTLI_BOOL BrotliDecoderIsFinished (const BrotliDecoderState * state)
Checks if the decoder instance reached the final state. Did we make it to the end? Did we finish the story? π
Parameters:
stateβ decoder instance
Returns:
BROTLI_TRUEif the decoder is in a state where it reached the end of the input and produced all of the outputBROTLI_FALSEotherwise
π± BrotliDecoderIsUsed
BROTLI_BOOL BrotliDecoderIsUsed (const BrotliDecoderState * state)
Checks if the instance has already consumed input. An instance that returns BROTLI_FALSE is considered 'fresh' and could be reused. Fresh like a brand new day, no cap. πΈ
Parameters:
stateβ decoder instance
Returns:
BROTLI_TRUEif the decoder has already used some input bytesBROTLI_FALSEotherwise
π¬ BrotliDecoderSetMetadataCallbacks
void BrotliDecoderSetMetadataCallbacks (BrotliDecoderState * state,
brotli_decoder_metadata_start_func start_func,
brotli_decoder_metadata_chunk_func chunk_func, void * opaque)
Sets the callback for receiving metadata blocks. The little extra info packets get their own delivery service. π
Parameters:
stateβ decoder instancestart_funcβ callback on metadata block startchunk_funcβ callback on metadata block chunkopaqueβ callback handle
ποΈ BrotliDecoderSetParameter
BROTLI_BOOL BrotliDecoderSetParameter (BrotliDecoderState * state,
BrotliDecoderParameter param, uint32_t value)
Sets the specified parameter to the given decoder instance. Tuning the vibes, adjusting the dials. βοΈ
Parameters:
stateβ decoder instanceparamβ parameter to setvalueβ new parameter value
Returns:
BROTLI_FALSEif the parameter is unrecognized, or the value is invalidBROTLI_TRUEif the value is accepted β
π BrotliDecoderTakeOutput
const uint8_t* BrotliDecoderTakeOutput (BrotliDecoderState * state, size_t *
size)
Acquires a pointer to the internal output buffer. This method is used to make language bindings easier and more efficient:
- push data to
BrotliDecoderDecompressStream, untilBROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUTis reported - use
BrotliDecoderTakeOutputto peek bytes and copy to a language-specific entity
Also this could be useful if there is an output stream that is able to consume all the provided data (e.g. when data is saved to the file system). Slay, efficient queen. π
Attention: After every call toBrotliDecoderTakeOutput,*sizebytes of output are considered consumed for all consecutive calls to the instance methods; the returned pointer becomes invalidated as well. So like, don't hold onto that pointer, bestie, it's gone. π
Note: Decoder output is not guaranteed to be contiguous. This means that after the size-unrestricted call toBrotliDecoderTakeOutput, the immediate next call toBrotliDecoderTakeOutputmay return more data. Not me getting surprise extra bytes. π
Parameters:
stateβ decoder instancesizeβ in: number of bytes the caller is ready to take,0if any amount could be handled; out: amount of data pointed to by the returned pointer and considered consumed; the out value is never greater than the in value, unless it is0
Returns:
- pointer to output data
π·οΈ BrotliDecoderVersion
uint32_t BrotliDecoderVersion (void)
Gets the decoder library version. Look at BROTLI_MAKE_HEX_VERSION for more information. Gotta know which era of the library you're living in. β
π AUTHOR
Generated automatically by Doxygen for Brotli from the source code.
And that's a wrap, bestie! π This was Brotli's decode.h(3), served up by the Brotli crew and dated August 2021 β automatically generated by Doxygen from the source code, because even docs deserve a glow-up. Go forth and decode responsibly. β¨ππ¦
π¦ where this page comes from
- centos-stream 10: brotli-devel 1.1.0-8.el10 Β· MIT
- fedora 43: brotli-devel 1.1.0-10.fc43 Β· MIT
- fedora 43: brotli-devel 1.1.0-10.fc43 Β· MIT
- fedora 43: brotli-devel 1.2.0-1.fc43
- fedora 43: brotli-devel 1.2.0-1.fc43
- fedora 43: brotli-devel 1.2.1-1.fc43 Β· MIT
- fedora 43: brotli-devel 1.2.1-1.fc43 Β· MIT
- fedora 44: brotli-devel 1.2.0-3.fc44 Β· MIT
- fedora 44: brotli-devel 1.2.0-3.fc44 Β· MIT
- fedora 44: brotli-devel 1.2.1-1.fc44 Β· MIT
- fedora 44: brotli-devel 1.2.1-1.fc44 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms