Skip to content

Latest commit

 

History

History
93 lines (69 loc) · 1.73 KB

README.md

File metadata and controls

93 lines (69 loc) · 1.73 KB

Ordered Data Exchange

A hierarchical data management and serialisation library written in ANSI C, with a focus on simplicity, security and efficiency.

Installation

git clone https://github.com/Swarthe/ode

Include the header files src/*.h where they are needed, and compile the source files src/*.c together with your project.

You may optionally modify src/ode_alloc.h to use your preferred allocator.

Usage

Error checking is omitted for the sake of brevity.

Root object initialisation

ode_t *data;

We can create an empty object

data = ode_create("root", -1);

Or read its contents from serialised data.

data = ode_deserial(buffer, buffer_size);

Storage & manipulation of data

Adding subordinate objects:

ode_add(data, "test1", -1);
ode_add(ode_get1(data, "test1", -1), "test2", 5);

Storing and modifying data:

ode_t *sub;

sub = ode_add(data, "emptyobj", -1);
ode_mod(sub, ODE_VALUE, "testval", -1);
ode_mod(sub, ODE_NAME, "objwithval", -1);

Removing data:

sub = ode_get(data, "test1", "test2", (char *) NULL);
ode_zero(sub, &bzero);      /* Optional */
ode_del(sub);

Data usage

We can obtain data directly

puts(ode_getstr(data, ODE_NAME));
fwrite(ode_getstr(data, ODE_NAME), 1, ode_getlen(data, ODE_NAME), stdout);

Or by iterating through subordinates.

ode_t *o;

for (o = ode_iter(data, NULL); o; o = ode_iter(data, o))
    puts(ode_getstr(o, ODE_NAME));

Finalisation

Serialising data for future use:

char *buffer;
size_t buffer_size;

buffer = ode_serial(data, &buffer_size);

Freeing all data:

ode_del(data);

License

This library is free software and subject to the MIT license. See LICENSE.txt for more information.