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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>WiredTiger: Packing and Unpacking Data</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="wiredtiger.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><a href="http://wiredtiger.com/"><img alt="Logo" src="LogoFinal-header.png" alt="WiredTiger" /></a></td>
<td style="padding-left: 0.5em;">
<div id="projectname">
 <span id="projectnumber">Version 3.2.1</span>
</div>
<div id="projectbrief"><!-- 3.2.1 --></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="banner">
<a href="https://github.com/wiredtiger/wiredtiger">Fork me on GitHub</a>
<a class="last" href="http://groups.google.com/group/wiredtiger-users">Join my user group</a>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',false,false,'search.php','Search');
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('packing.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">Packing and Unpacking Data </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>WiredTiger's data packing uses format strings similar to those specified in the Python struct module: <a href="http://docs.python.org/library/struct">http://docs.python.org/library/struct</a></p>
<p>The first character of the format string can be used to indicate the byte order, size and alignment of the packed data, according to the following table:</p>
<table class="doxtable">
<tr>
<th>Character</th><th>Byte order</th><th>Size</th><th>Alignment </th></tr>
<tr>
<td><code>.</code></td><td>big-endian</td><td>packed</td><td>none </td></tr>
<tr>
<td><code>></code></td><td>big-endian</td><td>standard</td><td>none </td></tr>
<tr>
<td><code><</code></td><td>little-endian</td><td>standard</td><td>none </td></tr>
<tr>
<td><code>@</code></td><td>native</td><td>native</td><td>native </td></tr>
</table>
<p>If the first character is not one of these, '.' (big-endian, packed) is assumed: it naturally sorts in lexicographic order, and the packed format uses variable-sized encoding of values to reduce the data size.</p>
<p>Note: <b> little-endian format</b> not yet supported in WiredTiger. Only the default big-endian, packed format is currently supported.</p>
<p>The remaining characters in the format string specify the type of each field to be packed into or unpacked from a byte array. See <a class="el" href="schema.html#schema_column_types">Column types</a> for the list of supported types.</p>
<h1><a class="anchor" id="config_examples"></a>
Code samples</h1>
<p>The code below is taken from the complete example program <a class="el" href="ex_pack_8c-example.html">ex_pack.c</a>. It demonstrates how to pack three integer values into a buffer and then unpack them again.</p>
<div class="fragment"><div class="line"> <span class="keywordtype">size_t</span> size;</div><div class="line"> <span class="keywordtype">char</span> buf[50];</div><div class="line"></div><div class="line"> error_check(<a class="code" href="group__wt.html#ga156e7993d370495e1e52c29b2bb6b7d4">wiredtiger_struct_size</a>(session, &size, <span class="stringliteral">"iii"</span>, 42, 1000, -9));</div><div class="line"> <span class="keywordflow">if</span> (size > <span class="keyword">sizeof</span>(buf)) {</div><div class="line"> <span class="comment">/* Allocate a bigger buffer. */</span></div><div class="line"> }</div><div class="line"></div><div class="line"> error_check(<a class="code" href="group__wt.html#gab3d8a22e243360ece67baf33926d80fa">wiredtiger_struct_pack</a>(session, buf, size, <span class="stringliteral">"iii"</span>, 42, 1000, -9));</div><div class="line"></div><div class="line"> error_check(<a class="code" href="group__wt.html#ga7cdc8c688f2c15303188ed6999dcc1b4">wiredtiger_struct_unpack</a>(session, buf, size, <span class="stringliteral">"iii"</span>, &i, &j, &k));</div></div><!-- fragment --></div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="index.html">Reference Guide</a></li><li class="navelem"><a class="el" href="programming.html">Writing WiredTiger applications</a></li><li class="navelem"><a class="el" href="schema.html">Schema, Columns, Column Groups, Indices and Projections</a></li>
<li class="footer">Copyright (c) 2008-2019 MongoDB, Inc. All rights reserved. Contact <a href="mailto:info@wiredtiger.com">info@wiredtiger.com</a> for more information.</li>
</ul>
</div>
</body>
</html>
|