- group SNAPPY_C_API
Plain C interface (a wrapper around the C++ implementation).
Enums
Functions
-
snappy_status snappy_compress(const char *input, size_t input_length, char *compressed, size_t *compressed_length)#
Takes the data stored in “input[0..input_length-1]” and stores it in the array pointed to by “compressed”.
Parameters
Direction
Description
input
in
This is the buffer where the data we want to compress is accessible.
input_length
in
Length of the input buffer.
compressed
out
This is a buffer in which compressed data is stored.
compressed_length
in,out
compressed_length signals the space available in “compressed” buffer. After successful compression compressed_length contains the true length of the compressed output.
Note
- Example:
size_t output_length = snappy_max_compressed_length(input_length); char* output = (char*)malloc(output_length); if (snappy_compress(input, input_length, output, &output_length) == SNAPPY_OK) { ... Process(output, output_length) ... } free(output);
- Returns:
Result
Description
Success
Returns SNAPPY_OK if successful.
Failure
While calling this function if compressed_length is not at least equal to “snappy_max_compressed_length(input_length)”, SNAPPY_BUFFER_TOO_SMALL is returned.
-
size_t snappy_max_compressed_length(size_t source_length)#
This function determines the maximal size of the compressed representation of input data that is “source_length” bytes in length.
Parameters
Direction
Description
source_length
in
The size of source in bytes.
- Returns:
Result
Description
Success
Returns the maximal size of the compressed representation of input data that is “source_bytes” bytes in length.
-
snappy_status snappy_uncompress(const char *compressed, size_t compressed_length, char *uncompressed, size_t *uncompressed_length)#
Given data in “compressed[0..compressed_length-1]” generated by calling the snappy_compress routine, this routine stores the uncompressed data to uncompressed[0..uncompressed_length-1].
Parameters
Direction
Description
compressed
in
This is a buffer which contains compressed data.
compressed_length
in
This is the length of the compressed buffer.
uncompressed
out
Uncompressed data is stored in this buffer.
uncompressed_length
in,out
uncompressed_length signals the space available in “uncompressed”. After successful decompression, uncompressed_length contains the true length of the decompressed output.
Note
- Example:
size_t output_length; if (snappy_uncompressed_length(input, input_length, &output_length) != SNAPPY_OK) { ... fail ... } char* output = (char*)malloc(output_length); if (snappy_uncompress(input, input_length, output, &output_length) == SNAPPY_OK) { ... Process(output, output_length) ... } free(output);
- Returns:
Result
Description
Success
Returns SNAPPY_OK if successful.
Failure
While calling this function if uncompressed_length is not at least equal to the value returned by snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL is returned Returns (a value not equal to SNAPPY_OK) if the message is corrupted and could not be decrypted.
-
snappy_status snappy_uncompressed_length(const char *compressed, size_t compressed_length, size_t *result)#
Get the Uncompressed Length object.
This operation takes O(1) time.
Parameters
Direction
Description
compressed
in
This is a buffer which contains compressed data.
compressed_length
in
This is the length of the compressed buffer.
result
out
This is the pointer to type size_t where the uncompressed length is stored.
- Attention
REQUIRES: “compressed[]” was produced by RawCompress() or Compress().
- Returns:
Result
Description
Success
Returns true on successful parsing.
Failure
Returns false on parsing error.
-
snappy_status snappy_validate_compressed_buffer(const char *compressed, size_t compressed_length)#
Returns true iff the contents of “compressed[]” can be uncompressed successfully. Does not return the uncompressed data. Takes time proportional to compressed_length, but is usually at least a factor of four faster than actual decompression.
Parameters
Direction
Description
compressed
in
This is a buffer which contains compressed data.
compressed_length
in
This is the length of the compressed buffer.
- Returns:
Result
Description
Success
Returns true iff the contents of “compressed[]” can be uncompressed successfully.
Failure
Returns false if error.
-
snappy_status snappy_compress(const char *input, size_t input_length, char *compressed, size_t *compressed_length)#