![]() |
|
|||
File indexing completed on 2025-08-27 09:55:47
0001 /* 0002 * Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>. 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions are 0006 * met: 0007 * 0008 * * Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * * Redistributions in binary form must reproduce the above 0011 * copyright notice, this list of conditions and the following disclaimer 0012 * in the documentation and/or other materials provided with the 0013 * distribution. 0014 * * Neither the name of Google Inc. nor the names of its 0015 * contributors may be used to endorse or promote products derived from 0016 * this software without specific prior written permission. 0017 * 0018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0021 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0022 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0023 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0024 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0025 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0026 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0028 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0029 * 0030 * Plain C interface (a wrapper around the C++ implementation). 0031 */ 0032 0033 #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_ 0034 #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_ 0035 0036 #ifdef __cplusplus 0037 extern "C" { 0038 #endif 0039 0040 #include <stddef.h> 0041 0042 /* 0043 * Return values; see the documentation for each function to know 0044 * what each can return. 0045 */ 0046 typedef enum { 0047 SNAPPY_OK = 0, 0048 SNAPPY_INVALID_INPUT = 1, 0049 SNAPPY_BUFFER_TOO_SMALL = 2 0050 } snappy_status; 0051 0052 /* 0053 * Takes the data stored in "input[0..input_length-1]" and stores 0054 * it in the array pointed to by "compressed". 0055 * 0056 * <compressed_length> signals the space available in "compressed". 0057 * If it is not at least equal to "snappy_max_compressed_length(input_length)", 0058 * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression, 0059 * <compressed_length> contains the true length of the compressed output, 0060 * and SNAPPY_OK is returned. 0061 * 0062 * Example: 0063 * size_t output_length = snappy_max_compressed_length(input_length); 0064 * char* output = (char*)malloc(output_length); 0065 * if (snappy_compress(input, input_length, output, &output_length) 0066 * == SNAPPY_OK) { 0067 * ... Process(output, output_length) ... 0068 * } 0069 * free(output); 0070 */ 0071 snappy_status snappy_compress(const char* input, 0072 size_t input_length, 0073 char* compressed, 0074 size_t* compressed_length); 0075 0076 /* 0077 * Given data in "compressed[0..compressed_length-1]" generated by 0078 * calling the snappy_compress routine, this routine stores 0079 * the uncompressed data to 0080 * uncompressed[0..uncompressed_length-1]. 0081 * Returns failure (a value not equal to SNAPPY_OK) if the message 0082 * is corrupted and could not be decrypted. 0083 * 0084 * <uncompressed_length> signals the space available in "uncompressed". 0085 * If it is not at least equal to the value returned by 0086 * snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL 0087 * is returned. After successful decompression, <uncompressed_length> 0088 * contains the true length of the decompressed output. 0089 * 0090 * Example: 0091 * size_t output_length; 0092 * if (snappy_uncompressed_length(input, input_length, &output_length) 0093 * != SNAPPY_OK) { 0094 * ... fail ... 0095 * } 0096 * char* output = (char*)malloc(output_length); 0097 * if (snappy_uncompress(input, input_length, output, &output_length) 0098 * == SNAPPY_OK) { 0099 * ... Process(output, output_length) ... 0100 * } 0101 * free(output); 0102 */ 0103 snappy_status snappy_uncompress(const char* compressed, 0104 size_t compressed_length, 0105 char* uncompressed, 0106 size_t* uncompressed_length); 0107 0108 /* 0109 * Returns the maximal size of the compressed representation of 0110 * input data that is "source_length" bytes in length. 0111 */ 0112 size_t snappy_max_compressed_length(size_t source_length); 0113 0114 /* 0115 * REQUIRES: "compressed[]" was produced by snappy_compress() 0116 * Returns SNAPPY_OK and stores the length of the uncompressed data in 0117 * *result normally. Returns SNAPPY_INVALID_INPUT on parsing error. 0118 * This operation takes O(1) time. 0119 */ 0120 snappy_status snappy_uncompressed_length(const char* compressed, 0121 size_t compressed_length, 0122 size_t* result); 0123 0124 /* 0125 * Check if the contents of "compressed[]" can be uncompressed successfully. 0126 * Does not return the uncompressed data; if so, returns SNAPPY_OK, 0127 * or if not, returns SNAPPY_INVALID_INPUT. 0128 * Takes time proportional to compressed_length, but is usually at least a 0129 * factor of four faster than actual decompression. 0130 */ 0131 snappy_status snappy_validate_compressed_buffer(const char* compressed, 0132 size_t compressed_length); 0133 0134 #ifdef __cplusplus 0135 } // extern "C" 0136 #endif 0137 0138 #endif /* THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |