/usr/share/gtk-doc/html/gnet/gnet-pack.html is in libgnet-dev 2.0.8-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Pack</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="index.html" title="GNet Network Library Reference Manual">
<link rel="up" href="libgnet-reference.html" title="GNet Library Reference">
<link rel="prev" href="gnet-base64.html" title="Base64">
<link rel="next" href="gnet-md5.html" title="MD5">
<meta name="generator" content="GTK-Doc V1.8 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="chapter" href="gnet-overview.html" title="GNet Overview">
<link rel="chapter" href="gnet-developers.html" title="GNet for developers">
<link rel="chapter" href="gnet-examples.html" title="GNet Examples">
<link rel="chapter" href="libgnet-reference.html" title="GNet Library Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="gnet-base64.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="libgnet-reference.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GNet Network Library Reference Manual</th>
<td><a accesskey="n" href="gnet-md5.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id387992" class="shortcut">Top</a>
 | 
<a href="#id388589" class="shortcut">Description</a></nobr></td></tr>
</table>
<div class="refentry" lang="en">
<a name="gnet-pack"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>
<a name="id387992"></a><span class="refentrytitle">Pack</span>
</h2>
<p>Pack — Byte packing and unpacking functions</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">
#include <gnet.h>
gint <a href="gnet-pack.html" title="Pack">gnet_pack</a> (const gchar *format,
gchar *buffer,
const gint length,
...);
gint <a href="gnet-pack.html#gnet-pack-strdup">gnet_pack_strdup</a> (const gchar *format,
gchar **bufferp,
...);
gint <a href="gnet-pack.html#gnet-vpack">gnet_vpack</a> (const gchar *format,
gchar *buffer,
const gint length,
va_list args);
gint <a href="gnet-pack.html#gnet-calcsize">gnet_calcsize</a> (const gchar *format,
...);
gint <a href="gnet-pack.html#gnet-vcalcsize">gnet_vcalcsize</a> (const gchar *format,
va_list args);
gint <a href="gnet-pack.html#gnet-unpack">gnet_unpack</a> (const gchar *format,
const gchar *buffer,
gint length,
...);
gint <a href="gnet-pack.html#gnet-vunpack">gnet_vunpack</a> (const gchar *format,
const gchar *buffer,
gint length,
va_list args);
</pre>
</div>
<div class="refsect1" lang="en">
<a name="id388589"></a><h2>Description</h2>
<p>
The pack module provides functions for converting data into bytes
("packing") and converting bytes to data ("unpacking"). For example,
two integers and a string may be packed into a buffer to be transfered
over the network. These functions are similar to the ones in Python
and Perl.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id388606"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="id388616"></a><h3>
<a name="gnet-pack"></a>gnet_pack ()</h3>
<a class="indexterm" name="id388628"></a><pre class="programlisting">gint gnet_pack (const gchar *format,
gchar *buffer,
const gint length,
...);</pre>
<p>
Writes <em class="parameter"><code>Varargs</code></em> to <em class="parameter"><code>buffer</code></em>. <em class="parameter"><code>format</code></em> is a string that describes
the <em class="parameter"><code>Varargs</code></em> and how they are to be packed. This string is a list
of characters, each describing the type of an argument in
<em class="parameter"><code>Varargs</code></em>.
</p>
<p>
An example:
</p>
<p>
</p>
<div class="informalexample"><pre class="programlisting">
char buf[5];
int myint = 42;
int mybyte = 23;
gnet_pack("!ib", buf, sizeof(buf), myint, mybyte);
/* Now buf is { 42, 0, 0, 0, 23 }; */
</pre></div>
<p>
</p>
<p>
As a shortcut, most types can be prefixed by an integer to specify
how many times the type is repeated. For example, "4i2b" is
equivalent to "iiiibb". This repeat argument is refered below to
as REPEAT.
</p>
<p>
Native byte order and sizes are used by default. If the first
character of <em class="parameter"><code>format</code></em> is < then little endian order and standard
sizes are used. If the first character is > or !, then big endian
(or network) order and standard size are used. Standard sizes are
1 byte for chars, 2 bytes for shorts, and 4 bytes for ints and
longs.
</p>
<p>
The types:
</p>
<p>
x is a NULL character. It can be used for padding. It does not
correspond to an argument in <em class="parameter"><code>Varargs</code></em>.
</p>
<p>
b/B is a signed/unsigned char.
</p>
<p>
h/H is a signed/unsigned short.
</p>
<p>
i/I is a signed/unsigned int.
</p>
<p>
l/L is a signed/unsigned long.
</p>
<p>
f/D is a float/double (always native order/size).
</p>
<p>
v is a void pointer (always native size).
</p>
<p>
s is a zero-terminated string.
</p>
<p>
S is a zero-padded string of maximum length REPEAT. We write
up-to a NULL character or REPEAT characters, whichever comes
first. We then write NULL characters up to a total of REPEAT
characters. Special case: if REPEAT is not specified, we write
the string as a non-NULL-terminated string (note that it can't be
unpacked easily then).
</p>
<p>
r is a byte array of NEXT bytes. NEXT is the next argument passed
to <a href="gnet-pack.html" title="Pack"><code class="function">gnet_pack()</code></a> and is a gint.
</p>
<p>
R is a byte array of REPEAT bytes. REPEAT must be specified.
</p>
<p>
p is a Pascal string. The string passed is a NULL-termiated
string of less than 256 character. The string writen is a
non-NULL-terminated string with a byte before the string storing
the string length. REPEAT is repeat.
</p>
<p>
Mnemonics: (B)yte, s(H)ort, (I)nteger, (F)loat, (D)ouble, (V)oid
pointer, (S)tring, (R)aw
</p>
<p>
Pack was inspired by Python's and Perl's pack. It is more like
Python's than Perl's. Note that in GNet, a repeat of 0 does not
align the data (as in Python).</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><span class="term"><em class="parameter"><code>format</code></em> :</span></td>
<td> pack data format
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>buffer</code></em> :</span></td>
<td> buffer to pack to
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>length</code></em> :</span></td>
<td> length of <em class="parameter"><code>buffer</code></em>
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>...</code></em> :</span></td>
<td> variables to pack from
</td>
</tr>
<tr>
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
<td> number of bytes packed; -1 on error.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id388899"></a><h3>
<a name="gnet-pack-strdup"></a>gnet_pack_strdup ()</h3>
<a class="indexterm" name="id388911"></a><pre class="programlisting">gint gnet_pack_strdup (const gchar *format,
gchar **bufferp,
...);</pre>
<p>
Writes <em class="parameter"><code>Varargs</code></em> into a buffer pointed to by <em class="parameter"><code>bufferp</code></em>. The buffer
is allocated by the function and is caller owned. See <a href="gnet-pack.html" title="Pack"><code class="function">gnet_pack()</code></a>
for more information.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><span class="term"><em class="parameter"><code>format</code></em> :</span></td>
<td> pack data format
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>bufferp</code></em> :</span></td>
<td> pointer to a buffer (buffer is caller owned)
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>...</code></em> :</span></td>
<td> variables to pack from
</td>
</tr>
<tr>
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
<td> bytes packed; -1 on error.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id389029"></a><h3>
<a name="gnet-vpack"></a>gnet_vpack ()</h3>
<a class="indexterm" name="id389041"></a><pre class="programlisting">gint gnet_vpack (const gchar *format,
gchar *buffer,
const gint length,
va_list args);</pre>
<p>
Var arg interface to <a href="gnet-pack.html" title="Pack"><code class="function">gnet_pack()</code></a>. See <a href="gnet-pack.html" title="Pack"><code class="function">gnet_pack()</code></a> for more
information.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><span class="term"><em class="parameter"><code>format</code></em> :</span></td>
<td> pack data format
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>buffer</code></em> :</span></td>
<td> buffer to pack to
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>length</code></em> :</span></td>
<td> length of <em class="parameter"><code>buffer</code></em>
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>args</code></em> :</span></td>
<td> var args
</td>
</tr>
<tr>
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
<td> bytes packed; -1 on error.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id389190"></a><h3>
<a name="gnet-calcsize"></a>gnet_calcsize ()</h3>
<a class="indexterm" name="id389202"></a><pre class="programlisting">gint gnet_calcsize (const gchar *format,
...);</pre>
<p>
Calculates the size of the buffer needed to pack <em class="parameter"><code>Varargs</code></em> by the
given format. See <a href="gnet-pack.html" title="Pack"><code class="function">gnet_pack()</code></a> for more information.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><span class="term"><em class="parameter"><code>format</code></em> :</span></td>
<td> pack data format
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>...</code></em> :</span></td>
<td> variables
</td>
</tr>
<tr>
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
<td> number of bytes required to pack; -1 on error.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id389293"></a><h3>
<a name="gnet-vcalcsize"></a>gnet_vcalcsize ()</h3>
<a class="indexterm" name="id389305"></a><pre class="programlisting">gint gnet_vcalcsize (const gchar *format,
va_list args);</pre>
<p>
Var arg interface to <a href="gnet-pack.html#gnet-calcsize"><code class="function">gnet_calcsize()</code></a>. See <a href="gnet-pack.html#gnet-calcsize"><code class="function">gnet_calcsize()</code></a> for
additional information.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><span class="term"><em class="parameter"><code>format</code></em> :</span></td>
<td> pack data format
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>args</code></em> :</span></td>
<td> var args
</td>
</tr>
<tr>
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
<td> number of bytes required to pack; -1 on error.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id389407"></a><h3>
<a name="gnet-unpack"></a>gnet_unpack ()</h3>
<a class="indexterm" name="id389419"></a><pre class="programlisting">gint gnet_unpack (const gchar *format,
const gchar *buffer,
gint length,
...);</pre>
<p>
Reads the data in <em class="parameter"><code>buffer</code></em> into <em class="parameter"><code>Varargs</code></em>. <em class="parameter"><code>format</code></em> is a string that
describes the <em class="parameter"><code>Varargs</code></em> and how they are to be packed. This string
is a list of characters, each describing the type of an argument
in <em class="parameter"><code>Varargs</code></em>.
</p>
<p>
An example:
</p>
<p>
</p>
<div class="informalexample"><pre class="programlisting">
char buf[5] = { 42, 0, 0, 0, 23 };
int myint;
int mybyte;
gnet_unpack("!ib", buf, sizeof(buf), &myint, &mybyte);
/* Now myint is 42 and mybyte is 23 */
</pre></div>
<p>
</p>
<p>
In unpack, the arguments must be pointers to the appropriate type.
Strings and byte arrays are allocated dynamicly (by <code class="function">g_new()</code>). The
caller is responsible for <code class="function">g_free()</code>-ing it.
</p>
<p>
As a shortcut, most types can be prefixed by an integer to specify
how many times the type is repeated. For example, "4i2b" is
equivalent to "iiiibb". This repeat argument is refered below to
as REPEAT.
</p>
<p>
The types:
</p>
<p>
x is a pad byte. The byte is skipped and not stored. We do not
check its value.
</p>
<p>
b/B is a signed/unsigned char.
</p>
<p>
h/H is a signed/unsigned short.
</p>
<p>
i/I is a signed/unsigned int.
</p>
<p>
l/L is a signed/unsigned long.
</p>
<p>
f/D is a float/double (always native order/size).
v is a void pointer (always native size).
</p>
<p>
s is a zero-terminated string.
</p>
<p>
S is a zero-padded string of length REPEAT. We read REPEAT
characters or until a NULL character. Any remaining characters
are filled in with 0's. REPEAT must be specified.
</p>
<p>
r is a byte array of NEXT bytes. NEXT is the next argument and is
a gint. REPEAT is repeat.
</p>
<p>
R is a byte array of REPEAT bytes. REPEAT must be specified.
</p>
<p>
p is a Pascal string. The first byte read is the length of the
string and the string follows. The unpacked string will be a
normal, NULL-terminated string. REPEAT is repeat.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><span class="term"><em class="parameter"><code>format</code></em> :</span></td>
<td> unpack data format
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>buffer</code></em> :</span></td>
<td> buffer to unpack from
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>length</code></em> :</span></td>
<td> length of <em class="parameter"><code>buffer</code></em>
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>...</code></em> :</span></td>
<td> addresses of variables to unpack to
</td>
</tr>
<tr>
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
<td> number of bytes unpacked; -1 on error. The bytes are
unpacked to the variables pointed to by the <em class="parameter"><code>Varargs</code></em>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id389673"></a><h3>
<a name="gnet-vunpack"></a>gnet_vunpack ()</h3>
<a class="indexterm" name="id389685"></a><pre class="programlisting">gint gnet_vunpack (const gchar *format,
const gchar *buffer,
gint length,
va_list args);</pre>
<p>
Var arg interface to <a href="gnet-pack.html#gnet-unpack"><code class="function">gnet_unpack()</code></a>. See <a href="gnet-pack.html#gnet-unpack"><code class="function">gnet_unpack()</code></a> for more
information.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><span class="term"><em class="parameter"><code>format</code></em> :</span></td>
<td> unpack data format
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>buffer</code></em> :</span></td>
<td> buffer to unpack from
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>length</code></em> :</span></td>
<td> length of <em class="parameter"><code>buffer</code></em>
</td>
</tr>
<tr>
<td><span class="term"><em class="parameter"><code>args</code></em> :</span></td>
<td> var args
</td>
</tr>
<tr>
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
<td> number of bytes packed; -1 on error.
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
</div>
</body>
</html>
|