summaryrefslogtreecommitdiffstats
path: root/gril/parcel.h
blob: 623dcc6cc898462c4d118fa9fe41ff3e05b7c352 (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
/*
 * Copyright © 2011 Joel Armstrong <jcarmst@sandia.gov>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (`GPL') as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Based on parcel implementation from https://bitbucket.org/floren/inferno
 *
 */

#ifndef __PARCEL_H
#define __PARCEL_H

#include <stdlib.h>

struct parcel {
	char *data;
	size_t offset;
	size_t capacity;
	size_t size;
	int malformed;
};

struct parcel_str_array {
	int num_str;
	char *str[];
};

void parcel_init(struct parcel *p);
void parcel_grow(struct parcel *p, size_t size);
void parcel_free(struct parcel *p);
int32_t parcel_r_int32(struct parcel *p);
int parcel_w_int32(struct parcel *p, int32_t val);
int parcel_w_string(struct parcel *p, const char *str);
char *parcel_r_string(struct parcel *p);
void parcel_skip_string(struct parcel *p);
int parcel_w_raw(struct parcel *p, const void *data, size_t len);
void *parcel_r_raw(struct parcel *p,  int *len);
size_t parcel_data_avail(struct parcel *p);
struct parcel_str_array *parcel_r_str_array(struct parcel *p);
void parcel_free_str_array(struct parcel_str_array *str_arr);
char **parcel_r_strv(struct parcel *p);

#endif