gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: implement GNUNET_buffer_write_data_encod


From: gnunet
Subject: [gnunet] branch master updated: implement GNUNET_buffer_write_data_encoded
Date: Thu, 30 Jul 2020 11:52:04 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new d335baac8 implement GNUNET_buffer_write_data_encoded
d335baac8 is described below

commit d335baac87c2c59796a543fc2df44e2db33f5e8e
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Thu Jul 30 15:15:59 2020 +0530

    implement GNUNET_buffer_write_data_encoded
---
 src/include/gnunet_buffer_lib.h | 15 +++++++++++++++
 src/util/buffer.c               | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/src/include/gnunet_buffer_lib.h b/src/include/gnunet_buffer_lib.h
index e09ec130a..046aee72b 100644
--- a/src/include/gnunet_buffer_lib.h
+++ b/src/include/gnunet_buffer_lib.h
@@ -109,6 +109,21 @@ void
 GNUNET_buffer_write_str (struct GNUNET_Buffer *buf, const char *str);
 
 
+/**
+ * Write data encoded via #GNUNET_STRINGS_data_to_string to the buffer.
+ *
+ * Grows the buffer if necessary.
+ *
+ * @param buf buffer to write to
+ * @param data data to read from
+ * @param len number of bytes to copy from @a data to @a buf
+ */
+void
+GNUNET_buffer_write_data_encoded (struct GNUNET_Buffer *buf,
+                                  const char *data,
+                                  size_t len);
+
+
 /**
  * Write a path component to a buffer, ensuring that
  * there is exactly one slash between the previous contents
diff --git a/src/util/buffer.c b/src/util/buffer.c
index d0261889e..2af972413 100644
--- a/src/util/buffer.c
+++ b/src/util/buffer.c
@@ -248,3 +248,35 @@ GNUNET_buffer_write_vfstr (struct GNUNET_Buffer *buf,
   buf->position += res;
   GNUNET_assert (buf->position <= buf->capacity);
 }
+
+
+/**
+ * Write data encoded via #GNUNET_STRINGS_data_to_string to the buffer.
+ *
+ * Grows the buffer if necessary.
+ *
+ * @param buf buffer to write to
+ * @param data data to read from
+ * @param len number of bytes to copy from @a data to @a buf
+ */
+void
+GNUNET_buffer_write_data_encoded (struct GNUNET_Buffer *buf,
+                                  const char *data,
+                                  size_t len)
+{
+  size_t outlen = len * 8;
+  char *p = buf->mem + buf->position;
+
+  if (outlen % 5 > 0)
+    outlen += 5 - outlen % 5;
+  outlen /= 5;
+
+  GNUNET_buffer_ensure_remaining (buf, outlen);
+  GNUNET_assert (NULL !=
+                 GNUNET_STRINGS_data_to_string (data,
+                                                len,
+                                                p,
+                                                outlen));
+  buf->position += outlen;
+  GNUNET_assert (buf->position <= buf->capacity);
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]