mirror of
https://github.com/troydhanson/tpl.git
synced 2024-12-26 07:31:09 +08:00
147 lines
3.4 KiB
HTML
147 lines
3.4 KiB
HTML
<!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">
|
|
<img src="banner.png" alt="easy data storage and retrieval in C" />
|
|
</div> <!-- banner -->
|
|
|
|
<div id="topnav">
|
|
<a href="http://github.com/troydhanson/tpl">GitHub page</a> >
|
|
tpl home
|
|
|
|
</div> <!-- topnav -->
|
|
|
|
<hr />
|
|
<div id="mid">
|
|
|
|
<div id="nav">
|
|
|
|
|
|
<h2>documentation</h2>
|
|
<div><a href="userguide.html">user guide</a></div>
|
|
|
|
<h2>activity</h2>
|
|
<div><a href="ChangeLog.html">ChangeLog</a></div>
|
|
|
|
<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>
|
|
|
|
<h2>license</h2>
|
|
<div><a href="license.html">BSD revised</a></div>
|
|
|
|
<h2>developer</h2>
|
|
<div>Troy D. Hanson</div>
|
|
<div><a href="http://troydhanson.github.io/">my projects</a></div>
|
|
|
|
|
|
|
|
</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)", &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);
|
|
}
|
|
</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)", &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);
|
|
}
|
|
</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>
|