GNUnet  0.17.6
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 #ifndef GNUNET_BUFFER_LIB_H
32 #define GNUNET_BUFFER_LIB_H
33 
44 {
48  size_t capacity;
49 
53  size_t position;
54 
58  char *mem;
59 
63  int warn_grow;
64 };
65 
66 
76 void
77 GNUNET_buffer_prealloc (struct GNUNET_Buffer *buf, size_t capacity);
78 
79 
86 void
88 
89 
100 void
101 GNUNET_buffer_write (struct GNUNET_Buffer *buf, const char *data, size_t len);
102 
103 
112 void
113 GNUNET_buffer_write_str (struct GNUNET_Buffer *buf, const char *str);
114 
115 
125 void
127  const void *data,
128  size_t data_len);
129 
130 
139 void
140 GNUNET_buffer_write_path (struct GNUNET_Buffer *buf, const char *str);
141 
142 
153 void
154 GNUNET_buffer_write_fstr (struct GNUNET_Buffer *buf, const char *fmt, ...)
155 __attribute__ ((format (printf, 2, 3)));
156 
157 
168 void
169 GNUNET_buffer_write_vfstr (struct GNUNET_Buffer *buf, const char *fmt, va_list
170  args);
171 
172 
183 char *
185 
186 
196 void *
197 GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size);
198 
199 
205 void
207 
208 
209 #endif
210  /* 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:67
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.