~ubuntu-branches/ubuntu/wily/libsereal-encoder-perl/wily-proposed

« back to all changes in this revision

Viewing changes to snappy/csnappy.h

  • Committer: Package Import Robot
  • Author(s): Alexandre Mestiashvili
  • Date: 2013-02-20 08:29:14 UTC
  • Revision ID: package-import@ubuntu.com-20130220082914-dljb6eixvtj2m1v2
Tags: upstream-0.31
ImportĀ upstreamĀ versionĀ 0.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __CSNAPPY_H__
 
2
#define __CSNAPPY_H__
 
3
/*
 
4
File modified for the Linux Kernel by
 
5
Zeev Tarantov <zeev.tarantov@gmail.com>
 
6
*/
 
7
#ifdef __cplusplus
 
8
extern "C" {
 
9
#endif
 
10
 
 
11
#define CSNAPPY_VERSION 4
 
12
 
 
13
#define CSNAPPY_WORKMEM_BYTES_POWER_OF_TWO 15
 
14
#define CSNAPPY_WORKMEM_BYTES (1 << CSNAPPY_WORKMEM_BYTES_POWER_OF_TWO)
 
15
 
 
16
#ifndef __GNUC__
 
17
#define __attribute__(x) /*NOTHING*/
 
18
#endif
 
19
 
 
20
/*
 
21
 * Returns the maximal size of the compressed representation of
 
22
 * input data that is "source_len" bytes in length;
 
23
 */
 
24
uint32_t
 
25
csnappy_max_compressed_length(uint32_t source_len) __attribute__((const));
 
26
 
 
27
/*
 
28
 * Flat array compression that does not emit the "uncompressed length"
 
29
 * prefix. Compresses "input" array to the "output" array.
 
30
 *
 
31
 * REQUIRES: "input" is at most 32KiB long.
 
32
 * REQUIRES: "output" points to an array of memory that is at least
 
33
 * "csnappy_max_compressed_length(input_length)" in size.
 
34
 * REQUIRES: working_memory has (1 << workmem_bytes_power_of_two) bytes.
 
35
 * REQUIRES: 9 <= workmem_bytes_power_of_two <= 15.
 
36
 *
 
37
 * Returns an "end" pointer into "output" buffer.
 
38
 * "end - output" is the compressed size of "input".
 
39
 */
 
40
char*
 
41
csnappy_compress_fragment(
 
42
        const char *input,
 
43
        const uint32_t input_length,
 
44
        char *output,
 
45
        void *working_memory,
 
46
        const int workmem_bytes_power_of_two);
 
47
 
 
48
/*
 
49
 * REQUIRES: "compressed" must point to an area of memory that is at
 
50
 * least "csnappy_max_compressed_length(input_length)" bytes in length.
 
51
 * REQUIRES: working_memory has (1 << workmem_bytes_power_of_two) bytes.
 
52
 * REQUIRES: 9 <= workmem_bytes_power_of_two <= 15.
 
53
 *
 
54
 * Takes the data stored in "input[0..input_length-1]" and stores
 
55
 * it in the array pointed to by "compressed".
 
56
 *
 
57
 * "*out_compressed_length" is set to the length of the compressed output.
 
58
 */
 
59
void
 
60
csnappy_compress(
 
61
        const char *input,
 
62
        uint32_t input_length,
 
63
        char *compressed,
 
64
        uint32_t *out_compressed_length,
 
65
        void *working_memory,
 
66
        const int workmem_bytes_power_of_two);
 
67
 
 
68
/*
 
69
 * Reads header of compressed data to get stored length of uncompressed data.
 
70
 * REQUIRES: start points to compressed data.
 
71
 * REQUIRES: n is length of available compressed data.
 
72
 *
 
73
 * Returns SNAPPY_E_HEADER_BAD on error.
 
74
 * Returns number of bytes read from input on success.
 
75
 * Stores decoded length into *result.
 
76
 */
 
77
int
 
78
csnappy_get_uncompressed_length(
 
79
        const char *start,
 
80
        uint32_t n,
 
81
        uint32_t *result);
 
82
 
 
83
/*
 
84
 * Safely decompresses all data from array "src" of length "src_len" containing
 
85
 * entire compressed stream (with header) into array "dst" of size "dst_len".
 
86
 * REQUIRES: dst_len is at least csnappy_get_uncompressed_length(...).
 
87
 *
 
88
 * Iff successful, returns CSNAPPY_E_OK.
 
89
 * If recorded length in header is greater than dst_len, returns
 
90
 *  CSNAPPY_E_OUTPUT_INSUF.
 
91
 * If compressed data is malformed, does not write more than dst_len into dst.
 
92
 */
 
93
int
 
94
csnappy_decompress(
 
95
        const char *src,
 
96
        uint32_t src_len,
 
97
        char *dst,
 
98
        uint32_t dst_len);
 
99
 
 
100
/*
 
101
 * Safely decompresses stream src_len bytes long read from src to dst.
 
102
 * Amount of available space at dst must be provided in *dst_len by caller.
 
103
 * If compressed stream needs more space, it will not overflow and return
 
104
 *  CSNAPPY_E_OUTPUT_OVERRUN.
 
105
 * On success, sets *dst_len to actal number of bytes decompressed.
 
106
 * Iff successful, returns CSNAPPY_E_OK.
 
107
 */
 
108
int
 
109
csnappy_decompress_noheader(
 
110
        const char *src,
 
111
        uint32_t src_len,
 
112
        char *dst,
 
113
        uint32_t *dst_len);
 
114
 
 
115
/*
 
116
 * Return values (< 0 = Error)
 
117
 */
 
118
#define CSNAPPY_E_OK                    0
 
119
#define CSNAPPY_E_HEADER_BAD            (-1)
 
120
#define CSNAPPY_E_OUTPUT_INSUF          (-2)
 
121
#define CSNAPPY_E_OUTPUT_OVERRUN        (-3)
 
122
#define CSNAPPY_E_INPUT_NOT_CONSUMED    (-4)
 
123
#define CSNAPPY_E_DATA_MALFORMED        (-5)
 
124
 
 
125
#ifdef __cplusplus
 
126
}
 
127
#endif
 
128
 
 
129
#endif