Browse Source

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
zrythm_meson
David Robillard 11 years ago
parent
commit
b716b49fd9
  1. 21
      src/sratom.c
  2. 17
      tests/sratom_test.c
  3. 2
      wscript

21
src/sratom.c

@ -157,12 +157,12 @@ list_end(SerdStatementSink sink, @@ -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, @@ -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, @@ -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")) {

17
tests/sratom_test.c

@ -97,11 +97,12 @@ main() @@ -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() @@ -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 };

2
wscript

@ -55,7 +55,7 @@ def configure(conf): @@ -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',

Loading…
Cancel
Save