1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/snappy/src/snappy-c.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,138 @@ 1.4 +/* 1.5 + * Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>. 1.6 + * 1.7 + * Redistribution and use in source and binary forms, with or without 1.8 + * modification, are permitted provided that the following conditions are 1.9 + * met: 1.10 + * 1.11 + * * Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * * Redistributions in binary form must reproduce the above 1.14 + * copyright notice, this list of conditions and the following disclaimer 1.15 + * in the documentation and/or other materials provided with the 1.16 + * distribution. 1.17 + * * Neither the name of Google Inc. nor the names of its 1.18 + * contributors may be used to endorse or promote products derived from 1.19 + * this software without specific prior written permission. 1.20 + * 1.21 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.22 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.23 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.24 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.25 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.26 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.27 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.28 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.29 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.30 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.31 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.32 + * 1.33 + * Plain C interface (a wrapper around the C++ implementation). 1.34 + */ 1.35 + 1.36 +#ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_ 1.37 +#define UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_ 1.38 + 1.39 +#ifdef __cplusplus 1.40 +extern "C" { 1.41 +#endif 1.42 + 1.43 +#include <stddef.h> 1.44 + 1.45 +/* 1.46 + * Return values; see the documentation for each function to know 1.47 + * what each can return. 1.48 + */ 1.49 +typedef enum { 1.50 + SNAPPY_OK = 0, 1.51 + SNAPPY_INVALID_INPUT = 1, 1.52 + SNAPPY_BUFFER_TOO_SMALL = 2 1.53 +} snappy_status; 1.54 + 1.55 +/* 1.56 + * Takes the data stored in "input[0..input_length-1]" and stores 1.57 + * it in the array pointed to by "compressed". 1.58 + * 1.59 + * <compressed_length> signals the space available in "compressed". 1.60 + * If it is not at least equal to "snappy_max_compressed_length(input_length)", 1.61 + * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression, 1.62 + * <compressed_length> contains the true length of the compressed output, 1.63 + * and SNAPPY_OK is returned. 1.64 + * 1.65 + * Example: 1.66 + * size_t output_length = snappy_max_compressed_length(input_length); 1.67 + * char* output = (char*)malloc(output_length); 1.68 + * if (snappy_compress(input, input_length, output, &output_length) 1.69 + * == SNAPPY_OK) { 1.70 + * ... Process(output, output_length) ... 1.71 + * } 1.72 + * free(output); 1.73 + */ 1.74 +snappy_status snappy_compress(const char* input, 1.75 + size_t input_length, 1.76 + char* compressed, 1.77 + size_t* compressed_length); 1.78 + 1.79 +/* 1.80 + * Given data in "compressed[0..compressed_length-1]" generated by 1.81 + * calling the snappy_compress routine, this routine stores 1.82 + * the uncompressed data to 1.83 + * uncompressed[0..uncompressed_length-1]. 1.84 + * Returns failure (a value not equal to SNAPPY_OK) if the message 1.85 + * is corrupted and could not be decrypted. 1.86 + * 1.87 + * <uncompressed_length> signals the space available in "uncompressed". 1.88 + * If it is not at least equal to the value returned by 1.89 + * snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL 1.90 + * is returned. After successful decompression, <uncompressed_length> 1.91 + * contains the true length of the decompressed output. 1.92 + * 1.93 + * Example: 1.94 + * size_t output_length; 1.95 + * if (snappy_uncompressed_length(input, input_length, &output_length) 1.96 + * != SNAPPY_OK) { 1.97 + * ... fail ... 1.98 + * } 1.99 + * char* output = (char*)malloc(output_length); 1.100 + * if (snappy_uncompress(input, input_length, output, &output_length) 1.101 + * == SNAPPY_OK) { 1.102 + * ... Process(output, output_length) ... 1.103 + * } 1.104 + * free(output); 1.105 + */ 1.106 +snappy_status snappy_uncompress(const char* compressed, 1.107 + size_t compressed_length, 1.108 + char* uncompressed, 1.109 + size_t* uncompressed_length); 1.110 + 1.111 +/* 1.112 + * Returns the maximal size of the compressed representation of 1.113 + * input data that is "source_length" bytes in length. 1.114 + */ 1.115 +size_t snappy_max_compressed_length(size_t source_length); 1.116 + 1.117 +/* 1.118 + * REQUIRES: "compressed[]" was produced by snappy_compress() 1.119 + * Returns SNAPPY_OK and stores the length of the uncompressed data in 1.120 + * *result normally. Returns SNAPPY_INVALID_INPUT on parsing error. 1.121 + * This operation takes O(1) time. 1.122 + */ 1.123 +snappy_status snappy_uncompressed_length(const char* compressed, 1.124 + size_t compressed_length, 1.125 + size_t* result); 1.126 + 1.127 +/* 1.128 + * Check if the contents of "compressed[]" can be uncompressed successfully. 1.129 + * Does not return the uncompressed data; if so, returns SNAPPY_OK, 1.130 + * or if not, returns SNAPPY_INVALID_INPUT. 1.131 + * Takes time proportional to compressed_length, but is usually at least a 1.132 + * factor of four faster than actual decompression. 1.133 + */ 1.134 +snappy_status snappy_validate_compressed_buffer(const char* compressed, 1.135 + size_t compressed_length); 1.136 + 1.137 +#ifdef __cplusplus 1.138 +} // extern "C" 1.139 +#endif 1.140 + 1.141 +#endif /* UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */