sf.net summary page > tpl home

Efficient serialization in C
You can use tpl to store and reload your C data quickly and easily. Tpl works with files, memory buffers and file descriptors so it's suitable for use as a file format, IPC message format or any scenario where you need to store and retrieve your data.
Express your data
Just express the type of data you are working with as a tpl format string. For example, if you have a list of numeric ids and corresponding usernames, your format string is A(is). Map your C variables to the format string and then pack or unpack data. The format string lets you focus on your data, rather than the storage format.
Storing ids and usernames Reloading ids and usernames
#include "tpl.h"

int main(int argc, char *argv[]) {
    tpl_node *tn;
    int id=0;
    char *name, *names[] = { "joe", "bob", "cary" };

    tn = tpl_map("A(is)", &id, &name);

    for(name=names[0]; id < 3; name=names[++id]) {
        tpl_pack(tn,1);
    }

    tpl_dump(tn, TPL_FILE, "users.tpl");
    tpl_free(tn);
}
#include "tpl.h"

int main(int argc, char *argv[]) {
    tpl_node *tn;
    int id;
    char *name;

    tn = tpl_map("A(is)", &id, &name);
    tpl_load(tn, TPL_FILE, "users.tpl");

    while ( tpl_unpack(tn,1) > 0 ) {
        printf("id %d, user %s\n", id, name);
        free(name);
    }
    tpl_free(tn);
}
No library dependencies
Tpl does not make your software dependent on any libraries. You can compile its source code (one file) right into your program.
For more information
For a more thorough explanation and more examples, please read the User Guide.