1 /* CC0 license (public domain) - see LICENSE file for details */
2 #ifndef CCAN_PUSHPULL_PUSH_H
3 #define CCAN_PUSHPULL_PUSH_H
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.
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).
21 bool push_bytes(char **p, size_t *len, const void *src, size_t srclen);
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.
29 * If realloc() fails, false is returned.
31 bool push_u64(char **p, size_t *len, uint64_t val);
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.
39 * If realloc() fails, false is returned.
41 bool push_u32(char **p, size_t *len, uint32_t val);
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.
49 * If realloc() fails, false is returned.
51 bool push_u16(char **p, size_t *len, uint16_t val);
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.
59 * If realloc() fails, false is returned.
61 bool push_u8(char **p, size_t *len, uint8_t val);
62 #define push_uchar push_u8
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.
70 * If realloc() fails, false is returned.
72 bool push_s64(char **p, size_t *len, int64_t val);
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.
80 * If realloc() fails, false is returned.
82 bool push_s32(char **p, size_t *len, int32_t val);
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.
90 * If realloc() fails, false is returned.
92 bool push_s16(char **p, size_t *len, int16_t val);
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.
100 * If realloc() fails, false is returned.
102 bool push_s8(char **p, size_t *len, int8_t val);
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.
110 * If realloc() fails, false is returned.
112 bool push_char(char **p, size_t *len, char val);
115 * push_set_realloc - set function to use (instead of realloc).
116 * @reallocfn: new reallocation function.
118 * This can be used, for example, to cache reallocations.
120 void push_set_realloc(void *(reallocfn)(void *ptr, size_t size));
121 #endif /* CCAN_PUSHPULL_PUSH_H */