diff options
author | David Robillard <d@drobilla.net> | 2011-12-30 08:23:19 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-12-30 08:23:19 +0000 |
commit | 8708ccb858ddbf5d521c4755e137bd04544a6ae5 (patch) | |
tree | 2da5030db36592ff19b13f8ff802a5f5c3bfb3b8 /src/node.c | |
parent | c5c4a6e935eecc2d2dac7bb9cccd36057b8dc123 (diff) | |
download | lilv-8708ccb858ddbf5d521c4755e137bd04544a6ae5.tar.gz lilv-8708ccb858ddbf5d521c4755e137bd04544a6ae5.tar.bz2 lilv-8708ccb858ddbf5d521c4755e137bd04544a6ae5.zip |
Support arbitrary binary data in plugin state via base64 encoding.
Unit testing for plugin instantiation and state.
Build without LV2 state available.
Support URID values in plugin state nicely.
Fix various holes in state implementation exposed by tests.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3908 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/node.c')
-rw-r--r-- | src/node.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -21,7 +21,7 @@ #include "lilv_internal.h" static void -lilv_node_set_numerics_from_string(LilvNode* val) +lilv_node_set_numerics_from_string(LilvNode* val, size_t len) { char* endptr; @@ -39,6 +39,9 @@ lilv_node_set_numerics_from_string(LilvNode* val) case LILV_VALUE_BOOL: val->val.bool_val = (!strcmp(val->str_val, "true")); break; + case LILV_VALUE_BLOB: + val->val.blob_val.buf = serd_base64_decode( + (const uint8_t*)val->str_val, len, &val->val.blob_val.size); } } @@ -66,6 +69,7 @@ lilv_node_new(LilvWorld* world, LilvNodeType type, const char* str) case LILV_VALUE_INT: case LILV_VALUE_FLOAT: case LILV_VALUE_BOOL: + case LILV_VALUE_BLOB: val->str_val = lilv_strdup(str); break; } @@ -80,6 +84,7 @@ lilv_node_new_from_node(LilvWorld* world, const SordNode* node) LilvNode* result = NULL; SordNode* datatype_uri = NULL; LilvNodeType type = LILV_VALUE_STRING; + size_t len = 0; switch (sord_node_get_type(node)) { case SORD_URI: @@ -106,19 +111,15 @@ lilv_node_new_from_node(LilvWorld* world, const SordNode* node) type = LILV_VALUE_FLOAT; else if (sord_node_equals(datatype_uri, world->xsd_integer_node)) type = LILV_VALUE_INT; + else if (sord_node_equals(datatype_uri, world->xsd_base64Binary_node)) + type = LILV_VALUE_BLOB; else LILV_ERRORF("Unknown datatype `%s'\n", sord_node_get_string(datatype_uri)); } - result = lilv_node_new(world, type, (const char*)sord_node_get_string(node)); - switch (result->type) { - case LILV_VALUE_INT: - case LILV_VALUE_FLOAT: - case LILV_VALUE_BOOL: - lilv_node_set_numerics_from_string(result); - default: - break; - } + result = lilv_node_new( + world, type, (const char*)sord_node_get_string_counted(node, &len)); + lilv_node_set_numerics_from_string(result, len); break; default: assert(false); @@ -237,6 +238,10 @@ lilv_node_equals(const LilvNode* value, const LilvNode* other) return (value->val.float_val == other->val.float_val); case LILV_VALUE_BOOL: return (value->val.bool_val == other->val.bool_val); + case LILV_VALUE_BLOB: + return (value->val.blob_val.size == other->val.blob_val.size) + && !memcmp(value->val.blob_val.buf, other->val.blob_val.buf, + value->val.blob_val.size); } return false; /* shouldn't get here */ @@ -263,6 +268,7 @@ lilv_node_get_turtle_token(const LilvNode* value) break; case LILV_VALUE_STRING: case LILV_VALUE_BOOL: + case LILV_VALUE_BLOB: result = lilv_strdup(value->str_val); break; case LILV_VALUE_INT: |