tpl/doc/index.html

147 lines
3.4 KiB
HTML
Raw Normal View History

2013-03-12 16:38:58 -04:00
<!DOCTYPE html
PUBLIC "-//W3C//DTD XTHML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="styles.css" />
<title>tpl home page</title>
</head>
<body>
<div id="banner">
2013-03-12 20:53:41 -04:00
<img src="banner.png" alt="easy data storage and retrieval in C" />
2013-03-12 16:38:58 -04:00
</div> <!-- banner -->
<div id="topnav">
2013-03-12 17:23:06 -04:00
<a href="http://github.com/troydhanson/tpl">GitHub page</a> &gt;
2013-03-12 16:38:58 -04:00
tpl home
2013-03-12 17:23:06 -04:00
2013-03-12 16:38:58 -04:00
</div> <!-- topnav -->
<hr />
<div id="mid">
<div id="nav">
<h2>documentation</h2>
2013-03-12 17:23:06 -04:00
<div><a href="userguide.html">user guide</a></div>
2013-03-12 16:38:58 -04:00
2013-03-12 17:23:06 -04:00
<h2>activity</h2>
2013-03-12 16:38:58 -04:00
<div><a href="ChangeLog.html">ChangeLog</a></div>
2013-03-12 17:23:06 -04:00
<h2>download</h2>
<h3>Linux, Windows, BSD, OS X</h3>
<div><a href=https://github.com/troydhanson/tpl/archive/master.zip>tpl-master.zip</a></div>
<div><a href=https://github.com/troydhanson/tpl>git clone</a></div>
2013-03-12 16:38:58 -04:00
<h2>license</h2>
<div><a href="license.html">BSD revised</a></div>
<h2>developer</h2>
<div>Troy D. Hanson</div>
2014-12-02 13:35:02 -05:00
<div><a href="http://troydhanson.github.io/">my projects</a></div>
2013-03-12 17:23:06 -04:00
2013-03-12 16:38:58 -04:00
</div> <!-- nav -->
<div id="main">
<div>
<div class="lead">Efficient serialization in C</div>
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.
</div>
<div>
<div class="lead">Express your data</div>
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 <em>A(is)</em>. 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.
</div>
<div class="listing">
<table summary="example of storing and reloading an integer array">
<tr>
<th>
Storing ids and usernames
</th>
<th>
Reloading ids and usernames
</th>
</tr>
<tr>
<td>
<div class="code">
<pre>
#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)", &amp;id, &amp;name);
for(name=names[0]; id &lt; 3; name=names[++id]) {
tpl_pack(tn,1);
}
tpl_dump(tn, TPL_FILE, "users.tpl");
tpl_free(tn);
}
</pre>
</div> <!-- code -->
</td>
<td>
<div class="code">
<pre>
#include "tpl.h"
int main(int argc, char *argv[]) {
tpl_node *tn;
int id;
char *name;
tn = tpl_map("A(is)", &amp;id, &amp;name);
tpl_load(tn, TPL_FILE, "users.tpl");
while ( tpl_unpack(tn,1) &gt; 0 ) {
printf("id %d, user %s\n", id, name);
free(name);
}
tpl_free(tn);
}
</pre>
</div> <!-- code -->
</td>
</tr>
</table>
</div> <!-- listing -->
<div>
<div class="lead">No library dependencies</div>
Tpl does not make your software dependent on any libraries. You can compile its
source code (one file) right into your program.
</div>
<div class="lead">For more information</div>
For a more thorough explanation and more examples, please read the
<a href="userguide.html">User Guide.</a>
</div> <!-- main -->
</div> <!-- mid -->
<hr />
<div id="footer">
</div> <!-- footer -->
</body>
</html>