GNUnet  0.19.2
gnunet_buffer_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
31 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
32 #error "Only <gnunet_util_lib.h> can be included directly."
33 #endif
34 
35 #ifndef GNUNET_BUFFER_LIB_H
36 #define GNUNET_BUFFER_LIB_H
37 
48 {
52  size_t capacity;
53 
57  size_t position;
58 
62  char *mem;
63 
67  int warn_grow;
68 };
69 
70 
80 void
81 GNUNET_buffer_prealloc (struct GNUNET_Buffer *buf, size_t capacity);
82 
83 
90 void
92 
93 
104 void
105 GNUNET_buffer_write (struct GNUNET_Buffer *buf, const char *data, size_t len);
106 
107 
116 void
117 GNUNET_buffer_write_str (struct GNUNET_Buffer *buf, const char *str);
118 
119 
129 void
131  const void *data,
132  size_t data_len);
133 
134 
143 void
144 GNUNET_buffer_write_path (struct GNUNET_Buffer *buf, const char *str);
145 
146 
157 void
158 GNUNET_buffer_write_fstr (struct GNUNET_Buffer *buf, const char *fmt, ...)
159 __attribute__ ((format (printf, 2, 3)));
160 
161 
172 void
173 GNUNET_buffer_write_vfstr (struct GNUNET_Buffer *buf, const char *fmt, va_list
174  args);
175 
176 
187 char *
189 
190 
200 void *
201 GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size);
202 
203 
209 void
211 
212 
213 #endif
214  /* end of group addition */
uint32_t data
The data value.
enum RadiotapType __attribute__
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static char buf[2048]
char * GNUNET_buffer_reap_str(struct GNUNET_Buffer *buf)
Clear the buffer and return the string it contained.
Definition: buffer.c:123
void * GNUNET_buffer_reap(struct GNUNET_Buffer *buf, size_t *size)
Clear the buffer and return its contents.
Definition: buffer.c:149
void GNUNET_buffer_write_data_encoded(struct GNUNET_Buffer *buf, const void *data, size_t data_len)
Write data encoded via GNUNET_STRINGS_data_to_string to the buffer.
Definition: buffer.c:264
void GNUNET_buffer_ensure_remaining(struct GNUNET_Buffer *buf, size_t n)
Make sure that at least n bytes remaining in the buffer.
Definition: buffer.c:55
void GNUNET_buffer_write_fstr(struct GNUNET_Buffer *buf, const char *fmt,...) __attribute__((format(printf
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
void void GNUNET_buffer_write_vfstr(struct GNUNET_Buffer *buf, const char *fmt, va_list args)
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
Definition: buffer.c:230
void GNUNET_buffer_write(struct GNUNET_Buffer *buf, const char *data, size_t len)
Write bytes to the buffer.
Definition: buffer.c:86
void GNUNET_buffer_prealloc(struct GNUNET_Buffer *buf, size_t capacity)
Initialize a buffer with the given capacity.
Definition: buffer.c:35
void GNUNET_buffer_write_path(struct GNUNET_Buffer *buf, const char *str)
Write a path component to a buffer, ensuring that there is exactly one slash between the previous con...
Definition: buffer.c:180
void GNUNET_buffer_write_str(struct GNUNET_Buffer *buf, const char *str)
Write a 0-terminated string to a buffer, excluding the 0-terminator.
Definition: buffer.c:103
void GNUNET_buffer_clear(struct GNUNET_Buffer *buf)
Free the backing memory of the given buffer.
Definition: buffer.c:164
static unsigned int size
Size of the "table".
Definition: peer.c:68
Dynamically growing buffer.
size_t capacity
Capacity of the buffer.
int warn_grow
Log a warning if the buffer is grown over its initially allocated capacity.
size_t position
Current write position.
char * mem
Backing memory.