GNUnet  0.11.x
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 
27 #ifndef GNUNET_BUFFER_LIB_H
28 #define GNUNET_BUFFER_LIB_H
29 
40 {
44  size_t capacity;
45 
49  size_t position;
50 
54  char *mem;
55 
59  int warn_grow;
60 };
61 
62 
72 void
74 
75 
82 void
84 
85 
96 void
97 GNUNET_buffer_write (struct GNUNET_Buffer *buf, const char *data, size_t len);
98 
99 
108 void
109 GNUNET_buffer_write_str (struct GNUNET_Buffer *buf, const char *str);
110 
111 
121 void
123  const void *data,
124  size_t data_len);
125 
126 
135 void
136 GNUNET_buffer_write_path (struct GNUNET_Buffer *buf, const char *str);
137 
138 
149 void
150 GNUNET_buffer_write_fstr (struct GNUNET_Buffer *buf, const char *fmt, ...)
151 __attribute__ ((format (printf, 2, 3)));
152 
153 
164 void
165 GNUNET_buffer_write_vfstr (struct GNUNET_Buffer *buf, const char *fmt, va_list
166  args);
167 
168 
179 char *
181 
182 
192 void *
193 GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size);
194 
195 
201 void
202 GNUNET_buffer_clear (struct GNUNET_Buffer *buf);
203 
204 
205 #endif
size_t capacity
Capacity of the buffer.
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_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 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_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_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_reap(struct GNUNET_Buffer *buf, size_t *size)
Clear the buffer and return its contents.
Definition: buffer.c:149
static char buf[2048]
char * mem
Backing memory.
size_t position
Current write position.
static unsigned int size
Size of the "table".
Definition: peer.c:67
void GNUNET_buffer_prealloc(struct GNUNET_Buffer *buf, size_t capacity)
Initialize a buffer with the given capacity.
Definition: buffer.c:35
enum RadiotapType __attribute__
void GNUNET_buffer_clear(struct GNUNET_Buffer *buf)
Free the backing memory of the given buffer.
Definition: buffer.c:164
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
Common buffer management functions.
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
uint32_t data
The data value.
int warn_grow
Log a warning if the buffer is grown over its initially allocated capacity.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...