summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-11 23:43:57 +0000
committerDavid Robillard <d@drobilla.net>2012-04-11 23:43:57 +0000
commitb716b49fd9e6943f8f6555931bb5997423de3fe5 (patch)
tree2117c11eb5dc372aaf9d624ebbc61370879f0720
parentd69e1fb5c865b09d134eb671a626165a019908d9 (diff)
downloadsratom-b716b49fd9e6943f8f6555931bb5997423de3fe5.tar.gz
sratom-b716b49fd9e6943f8f6555931bb5997423de3fe5.tar.bz2
sratom-b716b49fd9e6943f8f6555931bb5997423de3fe5.zip
Save/restore atom:Chunk as base64Binary literals (not blank nodes).
git-svn-id: http://svn.drobilla.net/lad/trunk/sratom@4167 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/sratom.c21
-rw-r--r--tests/sratom_test.c17
-rw-r--r--wscript2
3 files changed, 28 insertions, 12 deletions
diff --git a/src/sratom.c b/src/sratom.c
index 556d4ed..7896e1b 100644
--- a/src/sratom.c
+++ b/src/sratom.c
@@ -157,12 +157,12 @@ list_end(SerdStatementSink sink,
}
static void
-start_object(Sratom* sratom,
- uint32_t flags,
- const SerdNode* subject,
- const SerdNode* predicate,
- const SerdNode* node,
- const char* type)
+start_object(Sratom* sratom,
+ uint32_t flags,
+ const SerdNode* subject,
+ const SerdNode* predicate,
+ const SerdNode* node,
+ const char* type)
{
sratom->write_statement(sratom->handle, flags|SERD_ANON_O_BEGIN, NULL,
subject, predicate, node, NULL, NULL);
@@ -206,6 +206,9 @@ sratom_write(Sratom* sratom,
object = serd_node_from_string(SERD_URI, USTR(NS_RDF "nil"));
} else if (type_urid == sratom->forge.String) {
object = serd_node_from_string(SERD_LITERAL, (const uint8_t*)body);
+ } else if (type_urid == sratom->forge.Chunk) {
+ datatype = serd_node_from_string(SERD_URI, NS_XSD "base64Binary");
+ object = serd_node_new_blob(body, size, true);
} else if (type_urid == sratom->forge.Literal) {
LV2_Atom_Literal_Body* lit = (LV2_Atom_Literal_Body*)body;
const uint8_t* str = USTR(lit + 1);
@@ -531,6 +534,12 @@ read_node(Sratom* sratom,
lv2_atom_forge_double(forge, serd_strtod(str, &endptr));
} else if (!strcmp(type_uri, (char*)NS_XSD "boolean")) {
lv2_atom_forge_bool(forge, !strcmp(str, "true"));
+ } else if (!strcmp(type_uri, (char*)NS_XSD "base64Binary")) {
+ size_t size = 0;
+ void* body = serd_base64_decode(USTR(str), len, &size);
+ lv2_atom_forge_atom(forge, size, forge->Chunk);
+ lv2_atom_forge_write(forge, body, size);
+ free(body);
} else if (!strcmp(type_uri, LV2_ATOM__Path)) {
lv2_atom_forge_path(forge, str, len);
} else if (!strcmp(type_uri, (char*)NS_MIDI "MidiEvent")) {
diff --git a/tests/sratom_test.c b/tests/sratom_test.c
index e8745fa..f992153 100644
--- a/tests/sratom_test.c
+++ b/tests/sratom_test.c
@@ -97,11 +97,12 @@ main()
LV2_URID eg_langlit = urid_map(NULL, "http://example.org/j-langlit");
LV2_URID eg_typelit = urid_map(NULL, "http://example.org/k-typelit");
LV2_URID eg_null = urid_map(NULL, "http://example.org/l-null");
- LV2_URID eg_blob = urid_map(NULL, "http://example.org/m-blob");
- LV2_URID eg_blank = urid_map(NULL, "http://example.org/n-blank");
- LV2_URID eg_tuple = urid_map(NULL, "http://example.org/o-tuple");
- LV2_URID eg_vector = urid_map(NULL, "http://example.org/p-vector");
- LV2_URID eg_seq = urid_map(NULL, "http://example.org/q-seq");
+ LV2_URID eg_chunk = urid_map(NULL, "http://example.org/m-chunk");
+ LV2_URID eg_blob = urid_map(NULL, "http://example.org/n-blob");
+ LV2_URID eg_blank = urid_map(NULL, "http://example.org/o-blank");
+ LV2_URID eg_tuple = urid_map(NULL, "http://example.org/p-tuple");
+ LV2_URID eg_vector = urid_map(NULL, "http://example.org/q-vector");
+ LV2_URID eg_seq = urid_map(NULL, "http://example.org/r-seq");
uint8_t buf[1024];
lv2_atom_forge_set_buffer(&forge, buf, sizeof(buf));
@@ -165,6 +166,12 @@ main()
lv2_atom_forge_property_head(&forge, eg_null, 0);
lv2_atom_forge_atom(&forge, 0, 0);
+ // eg_chunk = 0xBEEFDEAD
+ uint8_t chunk_buf[] = { 0xBE, 0xEF, 0xDE, 0xAD };
+ lv2_atom_forge_property_head(&forge, eg_chunk, 0);
+ lv2_atom_forge_atom(&forge, sizeof(chunk_buf), forge.Chunk);
+ lv2_atom_forge_write(&forge, chunk_buf, sizeof(chunk_buf));
+
// eg_blob = 0xDEADBEEF
uint32_t blob_type = map.map(map.handle, "http://example.org/Blob");
uint8_t blob_buf[] = { 0xDE, 0xAD, 0xBE, 0xEF };
diff --git a/wscript b/wscript
index 8db75c2..3b1f161 100644
--- a/wscript
+++ b/wscript
@@ -55,7 +55,7 @@ def configure(conf):
define_name='HAVE_GCOV',
mandatory=False)
- autowaf.check_pkg(conf, 'lv2', atleast_version='0.1.0', uselib_store='LV2')
+ autowaf.check_pkg(conf, 'lv2', atleast_version='0.4.0', uselib_store='LV2')
autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD',
atleast_version='0.11.0', mandatory=True)
autowaf.check_pkg(conf, 'sord-0', uselib_store='SORD',