From c02d28085a1f81b542df62fe97a530bb6cbce86d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 2 Jan 2022 18:22:35 -0500 Subject: Add support for xsd:hexBinary literals --- include/serd/serd.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/serd/serd.h b/include/serd/serd.h index 52245077..e450f853 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -1014,6 +1014,17 @@ SerdWriteResult serd_node_construct_integer(size_t buf_size, void* SERD_NULLABLE buf, int64_t value); +/** + Construct a canonical xsd:hexBinary literal. + + The constructed node will be an xsd:hexBinary literal like "534D", with + datatype xsd:hexBinary. +*/ +SerdWriteResult +serd_node_construct_hex(size_t buf_size, + void* SERD_NULLABLE buf, + size_t value_size, + const void* SERD_NONNULL value); /** Construct a canonical xsd:base64Binary literal. @@ -1182,6 +1193,21 @@ SERD_API SerdNode* SERD_ALLOCATED serd_new_integer(SerdAllocator* SERD_NULLABLE allocator, int64_t i); +/** + Create a new canonical xsd:hexBinary literal. + + This is a wrapper for serd_node_construct_hex() that allocates a new + node on the heap. + + @return A newly allocated node that must be freed with serd_node_free(), or + null. +*/ +SERD_API +SerdNode* SERD_ALLOCATED +serd_new_hex(SerdAllocator* SERD_NULLABLE allocator, + const void* SERD_NONNULL buf, + size_t size); + /** Create a new canonical xsd:base64Binary literal. @@ -1237,16 +1263,20 @@ serd_get_value_as(const SerdNode* SERD_NONNULL node, bool lossy); /** - Return the maximum size of a decoded base64 node in bytes. + Return the maximum size of a decoded hex or base64 binary node in bytes. This returns an upper bound on the number of bytes that would be decoded by - serd_get_base64(). This is calculated as a simple constant-time arithmetic + serd_get_blob(). This is calculated as a simple constant-time arithmetic expression based on the length of the encoded string, so may be larger than the actual size of the data due to things like additional whitespace. + + @return The size of the decoded hex or base64 blob `node`, or zero if it + does not have datatype or + . */ SERD_PURE_API size_t -serd_get_base64_size(const SerdNode* SERD_NONNULL node); +serd_get_blob_size(const SerdNode* SERD_NONNULL node); /** Decode a base64 node. @@ -1265,9 +1295,9 @@ serd_get_base64_size(const SerdNode* SERD_NONNULL node); */ SERD_API SerdWriteResult -serd_get_base64(const SerdNode* SERD_NONNULL node, - size_t buf_size, - void* SERD_NONNULL buf); +serd_get_blob(const SerdNode* SERD_NONNULL node, + size_t buf_size, + void* SERD_NONNULL buf); /// Return a deep copy of `node` SERD_API @@ -1527,6 +1557,18 @@ SERD_API const SerdNode* SERD_ALLOCATED serd_nodes_integer(SerdNodes* SERD_NONNULL nodes, int64_t value); +/** + Make a canonical xsd:hexBinary node. + + A new node will be constructed with serd_node_construct_hex() if an + equivalent one is not already in the set. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_hex(SerdNodes* SERD_NONNULL nodes, + const void* SERD_NONNULL value, + size_t value_size); + /** Make a canonical xsd:base64Binary node. -- cgit v1.2.1