aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-17 17:31:53 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commit08a3b8a18093d1623309f5f406865f51e7bff39a (patch)
tree4c1c0dab3680d3e1ed8cbdc1d698c10eb5a9ba49 /src/node.c
parent9c613b337712314c169d4add61212f4fc4102022 (diff)
downloadserd-08a3b8a18093d1623309f5f406865f51e7bff39a.tar.gz
serd-08a3b8a18093d1623309f5f406865f51e7bff39a.tar.bz2
serd-08a3b8a18093d1623309f5f406865f51e7bff39a.zip
Clean up base64 node construction and access API
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/node.c b/src/node.c
index ca173a51..c2f6ebab 100644
--- a/src/node.c
+++ b/src/node.c
@@ -11,9 +11,11 @@
#include "serd/attributes.h"
#include "serd/buffer.h"
#include "serd/node.h"
+#include "serd/status.h"
#include "serd/string.h"
#include "serd/string_view.h"
#include "serd/uri.h"
+#include "serd/write_result.h"
#include <assert.h>
#include <math.h>
@@ -185,6 +187,13 @@ serd_node_zero_pad(SerdNode* node)
}
}
+static SerdWriteResult
+result(const SerdStatus status, const size_t count)
+{
+ const SerdWriteResult result = {status, count};
+ return result;
+}
+
SerdNode*
serd_new_token(const SerdNodeType type, const SerdStringView str)
{
@@ -386,6 +395,26 @@ serd_get_integer(const SerdNode* const node)
return value;
}
+size_t
+serd_get_base64_size(const SerdNode* const node)
+{
+ return exess_base64_decoded_size(serd_node_length(node));
+}
+
+SerdWriteResult
+serd_get_base64(const SerdNode* const node,
+ const size_t buf_size,
+ void* const buf)
+{
+ const size_t max_size = serd_get_base64_size(node);
+ const ExessVariableResult r =
+ exess_read_base64(buf_size, buf, serd_node_string(node));
+
+ return r.status == EXESS_NO_SPACE ? result(SERD_OVERFLOW, max_size)
+ : r.status ? result(SERD_BAD_SYNTAX, 0U)
+ : result(SERD_SUCCESS, r.write_count);
+}
+
SerdNode*
serd_node_copy(const SerdNode* node)
{