summaryrefslogtreecommitdiff
path: root/include/lib/capnp-c/capnp_priv.h
blob: 6c03763e66e485a2e5f5dc1f42a4b7f3776590f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* vim: set sw=8 ts=8 sts=8 noet: */
/* capnp_c.h
 *
 * Copyright (C) 2013 James McKaskill
 * Copyright (C) 2014 Steve Dee
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

/*
 * functions / structures in this header are private to the capnproto-c
 * library;  applications should not call or use them.
 */

#ifndef CAPNP_PRIV_H
#define CAPNP_PRIV_H

#include "capnp_c.h"

#if defined(__GNUC__) && __GNUC__ >= 4
# define intern __attribute__((visibility ("internal")))
#else
# define intern /**/
#endif

/* capn_stream encapsulates the needed fields for capn_(deflate|inflate) in a
 * similar manner to z_stream from zlib
 *
 * The user should set next_in, avail_in, next_out, avail_out to the
 * available in/out buffers before calling capn_(deflate|inflate).
 *
 * Other fields should be zero initialized.
 */
struct capn_stream {
	const uint8_t *next_in;
	size_t avail_in;
	uint8_t *next_out;
	size_t avail_out;
	unsigned zeros, raw;

	uint8_t inflate_buf[8];
	size_t avail_buf;
};

#define CAPN_MISALIGNED -1
#define CAPN_NEED_MORE -2

/* capn_deflate deflates a stream to the packed format
 * capn_inflate inflates a stream from the packed format
 *
 * Returns:
 * CAPN_MISALIGNED - if the unpacked data is not 8 byte aligned
 * CAPN_NEED_MORE - more packed data/room is required (out for inflate, in for
 * deflate)
 * 0 - success, all output for inflate, all input for deflate processed
 */
intern int capn_deflate(struct capn_stream*);
intern int capn_inflate(struct capn_stream*);


#endif /* CAPNP_PRIV_H */