| 1 | /* |
| 2 | * librdkafka - Apache Kafka C library |
| 3 | * |
| 4 | * Copyright (c) 2018 Magnus Edenhill |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions are met: |
| 9 | * |
| 10 | * 1. Redistributions of source code must retain the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | * this list of conditions and the following disclaimer in the documentation |
| 14 | * and/or other materials provided with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef _LINUX_SNAPPY_H |
| 30 | #define _LINUX_SNAPPY_H 1 |
| 31 | |
| 32 | #include <stdbool.h> |
| 33 | #include <stddef.h> |
| 34 | |
| 35 | /* Only needed for compression. This preallocates the worst case */ |
| 36 | struct snappy_env { |
| 37 | unsigned short *hash_table; |
| 38 | void *scratch; |
| 39 | void *scratch_output; |
| 40 | }; |
| 41 | |
| 42 | struct iovec; |
| 43 | int rd_kafka_snappy_init_env(struct snappy_env *env); |
| 44 | int rd_kafka_snappy_init_env_sg(struct snappy_env *env, bool sg); |
| 45 | void rd_kafka_snappy_free_env(struct snappy_env *env); |
| 46 | int rd_kafka_snappy_uncompress_iov(struct iovec *iov_in, int iov_in_len, |
| 47 | size_t input_len, char *uncompressed); |
| 48 | int rd_kafka_snappy_uncompress(const char *compressed, size_t n, char *uncompressed); |
| 49 | char *rd_kafka_snappy_java_uncompress (const char *inbuf, size_t inlen, |
| 50 | size_t *outlenp, |
| 51 | char *errstr, size_t errstr_size); |
| 52 | int rd_kafka_snappy_compress_iov(struct snappy_env *env, |
| 53 | const struct iovec *iov_in, size_t iov_in_cnt, |
| 54 | size_t input_length, |
| 55 | struct iovec *iov_out); |
| 56 | bool rd_kafka_snappy_uncompressed_length(const char *buf, size_t len, size_t *result); |
| 57 | size_t rd_kafka_snappy_max_compressed_length(size_t source_len); |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | #endif |
| 63 | |