source: thirdparty/blosc/internal-complibs/snappy-1.1.1/snappy-c.h @ 8ebc79b

Revision 8ebc79b, 5.6 KB checked in by Hal Finkel <hfinkel@…>, 8 years ago (diff)

Add the other internal compression libraries from blocs

  • Property mode set to 100644
RevLine 
[8ebc79b]1/*
2 * Copyright 2011 Martin Gieseking <[email protected]>.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
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
13 * distribution.
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.
17 *
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.
29 *
30 * Plain C interface (a wrapper around the C++ implementation).
31 */
32
33#ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
34#define UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40// The next is for getting the Snappy version even if used the C API.
41// Please note that this is only defined in the Blosc sources of Snappy.
42#define SNAPPY_MAJOR 1
43#define SNAPPY_MINOR 1
44#define SNAPPY_PATCHLEVEL 1
45#define SNAPPY_VERSION \
46    ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
47
48#include <stddef.h>
49
50/*
51 * Return values; see the documentation for each function to know
52 * what each can return.
53 */
54typedef enum {
55  SNAPPY_OK = 0,
56  SNAPPY_INVALID_INPUT = 1,
57  SNAPPY_BUFFER_TOO_SMALL = 2
58} snappy_status;
59
60/*
61 * Takes the data stored in "input[0..input_length-1]" and stores
62 * it in the array pointed to by "compressed".
63 *
64 * <compressed_length> signals the space available in "compressed".
65 * If it is not at least equal to "snappy_max_compressed_length(input_length)",
66 * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression,
67 * <compressed_length> contains the true length of the compressed output,
68 * and SNAPPY_OK is returned.
69 *
70 * Example:
71 *   size_t output_length = snappy_max_compressed_length(input_length);
72 *   char* output = (char*)malloc(output_length);
73 *   if (snappy_compress(input, input_length, output, &output_length)
74 *       == SNAPPY_OK) {
75 *     ... Process(output, output_length) ...
76 *   }
77 *   free(output);
78 */
79snappy_status snappy_compress(const char* input,
80                              size_t input_length,
81                              char* compressed,
82                              size_t* compressed_length);
83
84/*
85 * Given data in "compressed[0..compressed_length-1]" generated by
86 * calling the snappy_compress routine, this routine stores
87 * the uncompressed data to
88 *   uncompressed[0..uncompressed_length-1].
89 * Returns failure (a value not equal to SNAPPY_OK) if the message
90 * is corrupted and could not be decrypted.
91 *
92 * <uncompressed_length> signals the space available in "uncompressed".
93 * If it is not at least equal to the value returned by
94 * snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL
95 * is returned. After successful decompression, <uncompressed_length>
96 * contains the true length of the decompressed output.
97 *
98 * Example:
99 *   size_t output_length;
100 *   if (snappy_uncompressed_length(input, input_length, &output_length)
101 *       != SNAPPY_OK) {
102 *     ... fail ...
103 *   }
104 *   char* output = (char*)malloc(output_length);
105 *   if (snappy_uncompress(input, input_length, output, &output_length)
106 *       == SNAPPY_OK) {
107 *     ... Process(output, output_length) ...
108 *   }
109 *   free(output);
110 */
111snappy_status snappy_uncompress(const char* compressed,
112                                size_t compressed_length,
113                                char* uncompressed,
114                                size_t* uncompressed_length);
115
116/*
117 * Returns the maximal size of the compressed representation of
118 * input data that is "source_length" bytes in length.
119 */
120size_t snappy_max_compressed_length(size_t source_length);
121
122/*
123 * REQUIRES: "compressed[]" was produced by snappy_compress()
124 * Returns SNAPPY_OK and stores the length of the uncompressed data in
125 * *result normally. Returns SNAPPY_INVALID_INPUT on parsing error.
126 * This operation takes O(1) time.
127 */
128snappy_status snappy_uncompressed_length(const char* compressed,
129                                         size_t compressed_length,
130                                         size_t* result);
131
132/*
133 * Check if the contents of "compressed[]" can be uncompressed successfully.
134 * Does not return the uncompressed data; if so, returns SNAPPY_OK,
135 * or if not, returns SNAPPY_INVALID_INPUT.
136 * Takes time proportional to compressed_length, but is usually at least a
137 * factor of four faster than actual decompression.
138 */
139snappy_status snappy_validate_compressed_buffer(const char* compressed,
140                                                size_t compressed_length);
141
142#ifdef __cplusplus
143}  // extern "C"
144#endif
145
146#endif  /* UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */
Note: See TracBrowser for help on using the repository browser.