]> git.ozlabs.org Git - ccan/blob - ccan/pushpull/push.h
tal: allow notifiers on NULL.
[ccan] / ccan / pushpull / push.h
1 /* CC0 license (public domain) - see LICENSE file for details */
2 #ifndef CCAN_PUSHPULL_PUSH_H
3 #define CCAN_PUSHPULL_PUSH_H
4 #include "config.h"
5
6 #include <stdbool.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9
10 /**
11  * push_bytes - marshall bytes into buffer
12  * @p: buffer of marshalled bytes
13  * @len: current length of @p buffer
14  * @src: source to copy bytes from (or NULL to copy zeroes)
15  * @srclen: length to copy from @src.
16  *
17  * If realloc() fails, false is returned.  Otherwise, *@p is increased
18  * by @srclen bytes, *@len is incremented by @srclen, and bytes appended
19  * to *@p (from @src if non-NULL).
20  */
21 bool push_bytes(char **p, size_t *len, const void *src, size_t srclen);
22
23 /**
24  * push_u64 - marshall a 64-bit value into buffer (as little-endian)
25  * @p: buffer of marshalled bytes
26  * @len: current length of @p buffer
27  * @val: the value to marshall.
28  *
29  * If realloc() fails, false is returned.
30  */
31 bool push_u64(char **p, size_t *len, uint64_t val);
32
33 /**
34  * push_u32 - marshall a 32-bit value into buffer (as little-endian)
35  * @p: buffer of marshalled bytes
36  * @len: current length of @p buffer
37  * @val: the value to marshall.
38  *
39  * If realloc() fails, false is returned.
40  */
41 bool push_u32(char **p, size_t *len, uint32_t val);
42
43 /**
44  * push_u16 - marshall a 16-bit value into buffer (as little-endian)
45  * @p: buffer of marshalled bytes
46  * @len: current length of @p buffer
47  * @val: the value to marshall.
48  *
49  * If realloc() fails, false is returned.
50  */
51 bool push_u16(char **p, size_t *len, uint16_t val);
52
53 /**
54  * push_u8 - marshall an 8-bit value into buffer
55  * @p: buffer of marshalled bytes
56  * @len: current length of @p buffer
57  * @val: the value to marshall.
58  *
59  * If realloc() fails, false is returned.
60  */
61 bool push_u8(char **p, size_t *len, uint8_t val);
62 #define push_uchar push_u8
63
64 /**
65  * push_u64 - marshall a signed 64-bit value into buffer (as little-endian)
66  * @p: buffer of marshalled bytes
67  * @len: current length of @p buffer
68  * @val: the value to marshall.
69  *
70  * If realloc() fails, false is returned.
71  */
72 bool push_s64(char **p, size_t *len, int64_t val);
73
74 /**
75  * push_u32 - marshall a signed 32-bit value into buffer (as little-endian)
76  * @p: buffer of marshalled bytes
77  * @len: current length of @p buffer
78  * @val: the value to marshall.
79  *
80  * If realloc() fails, false is returned.
81  */
82 bool push_s32(char **p, size_t *len, int32_t val);
83
84 /**
85  * push_u16 - marshall a signed 16-bit value into buffer (as little-endian)
86  * @p: buffer of marshalled bytes
87  * @len: current length of @p buffer
88  * @val: the value to marshall.
89  *
90  * If realloc() fails, false is returned.
91  */
92 bool push_s16(char **p, size_t *len, int16_t val);
93
94 /**
95  * push_u8 - marshall a signed 8-bit value into buffer
96  * @p: buffer of marshalled bytes
97  * @len: current length of @p buffer
98  * @val: the value to marshall.
99  *
100  * If realloc() fails, false is returned.
101  */
102 bool push_s8(char **p, size_t *len, int8_t val);
103
104 /**
105  * push_char - marshall a character into buffer
106  * @p: buffer of marshalled bytes
107  * @len: current length of @p buffer
108  * @val: the value to marshall.
109  *
110  * If realloc() fails, false is returned.
111  */
112 bool push_char(char **p, size_t *len, char val);
113
114 /**
115  * push_set_realloc - set function to use (instead of realloc).
116  * @reallocfn: new reallocation function.
117  *
118  * This can be used, for example, to cache reallocations.
119  */
120 void push_set_realloc(void *(reallocfn)(void *ptr, size_t size));
121 #endif /* CCAN_PUSHPULL_PUSH_H */