2 * Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * Plain C interface (a wrapper around the C++ implementation).
33 #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
34 #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
43 * Return values; see the documentation for each function to know
44 * what each can return.
48 SNAPPY_INVALID_INPUT = 1,
49 SNAPPY_BUFFER_TOO_SMALL = 2,
53 * Takes the data stored in "input[0..input_length-1]" and stores
54 * it in the array pointed to by "compressed".
56 * <compressed_length> signals the space available in "compressed".
57 * If it is not at least equal to "snappy_max_compressed_length(input_length)",
58 * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression,
59 * <compressed_length> contains the true length of the compressed output,
60 * and SNAPPY_OK is returned.
63 * size_t output_length = snappy_max_compressed_length(input_length);
64 * char* output = (char*)malloc(output_length);
65 * if (snappy_compress(input, input_length, output, &output_length)
67 * ... Process(output, output_length) ...
71 snappy_status snappy_compress(const char* input,
74 size_t* compressed_length);
77 * Given data in "compressed[0..compressed_length-1]" generated by
78 * calling the snappy_compress routine, this routine stores
79 * the uncompressed data to
80 * uncompressed[0..uncompressed_length-1].
81 * Returns failure (a value not equal to SNAPPY_OK) if the message
82 * is corrupted and could not be decrypted.
84 * <uncompressed_length> signals the space available in "uncompressed".
85 * If it is not at least equal to the value returned by
86 * snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL
87 * is returned. After successful decompression, <uncompressed_length>
88 * contains the true length of the decompressed output.
91 * size_t output_length;
92 * if (snappy_uncompressed_length(input, input_length, &output_length)
96 * char* output = (char*)malloc(output_length);
97 * if (snappy_uncompress(input, input_length, output, &output_length)
99 * ... Process(output, output_length) ...
103 snappy_status snappy_uncompress(const char* compressed,
104 size_t compressed_length,
106 size_t* uncompressed_length);
109 * Returns the maximal size of the compressed representation of
110 * input data that is "source_length" bytes in length.
112 size_t snappy_max_compressed_length(size_t source_length);
115 * REQUIRES: "compressed[]" was produced by snappy_compress()
116 * Returns SNAPPY_OK and stores the length of the uncompressed data in
117 * *result normally. Returns SNAPPY_INVALID_INPUT on parsing error.
118 * This operation takes O(1) time.
120 snappy_status snappy_uncompressed_length(const char* compressed,
121 size_t compressed_length,
125 * Check if the contents of "compressed[]" can be uncompressed successfully.
126 * Does not return the uncompressed data; if so, returns SNAPPY_OK,
127 * or if not, returns SNAPPY_INVALID_INPUT.
128 * Takes time proportional to compressed_length, but is usually at least a
129 * factor of four faster than actual decompression.
131 snappy_status snappy_validate_compressed_buffer(const char* compressed,
132 size_t compressed_length);
138 #endif /* UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */