aboutsummaryrefslogtreecommitdiff
path: root/src/util/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/buffer.c')
-rw-r--r--src/util/buffer.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/util/buffer.c b/src/util/buffer.c
index d0261889e..8fb10c2a5 100644
--- a/src/util/buffer.c
+++ b/src/util/buffer.c
@@ -248,3 +248,35 @@ GNUNET_buffer_write_vfstr (struct GNUNET_Buffer *buf,
248 buf->position += res; 248 buf->position += res;
249 GNUNET_assert (buf->position <= buf->capacity); 249 GNUNET_assert (buf->position <= buf->capacity);
250} 250}
251
252
253/**
254 * Write data encoded via #GNUNET_STRINGS_data_to_string to the buffer.
255 *
256 * Grows the buffer if necessary.
257 *
258 * @param buf buffer to write to
259 * @param data data to read from
260 * @param len number of bytes to copy from @a data to @a buf
261 */
262void
263GNUNET_buffer_write_data_encoded (struct GNUNET_Buffer *buf,
264 const char *data,
265 size_t len)
266{
267 size_t outlen = len * 8;
268
269 if (outlen % 5 > 0)
270 outlen += 5 - outlen % 5;
271 outlen /= 5;
272
273 GNUNET_buffer_ensure_remaining (buf, outlen);
274 GNUNET_assert (NULL !=
275 GNUNET_STRINGS_data_to_string (data,
276 len,
277 (buf->mem +
278 buf->position),
279 outlen));
280 buf->position += outlen;
281 GNUNET_assert (buf->position <= buf->capacity);
282}