-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathex_pack_8c-example.html
170 lines (170 loc) · 11.5 KB
/
ex_pack_8c-example.html
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
<!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: ex_pack.c</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);
$(window).load(resizeHeight);
</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 2.8.0</span>
</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.9.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li><a href="community.html"><span>Community</span></a></li>
<li><a href="license.html"><span>License</span></a></li>
</ul>
</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('ex_pack_8c-example.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">ex_pack.c</div> </div>
</div><!--header-->
<div class="contents">
<p>Shows basic packing and unpacking of fields.</p>
<div class="fragment"><div class="line"><span class="comment">/*-</span></div>
<div class="line"><span class="comment"> * Public Domain 2014-2016 MongoDB, Inc.</span></div>
<div class="line"><span class="comment"> * Public Domain 2008-2014 WiredTiger, Inc.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * This is free and unencumbered software released into the public domain.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Anyone is free to copy, modify, publish, use, compile, sell, or</span></div>
<div class="line"><span class="comment"> * distribute this software, either in source code form or as a compiled</span></div>
<div class="line"><span class="comment"> * binary, for any purpose, commercial or non-commercial, and by any</span></div>
<div class="line"><span class="comment"> * means.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * In jurisdictions that recognize copyright laws, the author or authors</span></div>
<div class="line"><span class="comment"> * of this software dedicate any and all copyright interest in the</span></div>
<div class="line"><span class="comment"> * software to the public domain. We make this dedication for the benefit</span></div>
<div class="line"><span class="comment"> * of the public at large and to the detriment of our heirs and</span></div>
<div class="line"><span class="comment"> * successors. We intend this dedication to be an overt act of</span></div>
<div class="line"><span class="comment"> * relinquishment in perpetuity of all present and future rights to this</span></div>
<div class="line"><span class="comment"> * software under copyright law.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,</span></div>
<div class="line"><span class="comment"> * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span></div>
<div class="line"><span class="comment"> * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.</span></div>
<div class="line"><span class="comment"> * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR</span></div>
<div class="line"><span class="comment"> * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,</span></div>
<div class="line"><span class="comment"> * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR</span></div>
<div class="line"><span class="comment"> * OTHER DEALINGS IN THE SOFTWARE.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * ex_pack.c</span></div>
<div class="line"><span class="comment"> * This is an example demonstrating basic packing and unpacking of fields.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include <stdio.h></span></div>
<div class="line"><span class="preprocessor">#include <stdlib.h></span></div>
<div class="line"><span class="preprocessor">#include <string.h></span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include <wiredtiger.h></span></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *home;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span></div>
<div class="line">main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> <a name="_a0"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html">WT_CONNECTION</a> *conn;</div>
<div class="line"> <a name="_a1"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session;</div>
<div class="line"> <span class="keywordtype">int</span> i, j, k, ret;</div>
<div class="line"></div>
<div class="line"> <span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Create a clean test directory for this run of the test program if the</span></div>
<div class="line"><span class="comment"> * environment variable isn't already set (as is done by make check).</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> <span class="keywordflow">if</span> (getenv(<span class="stringliteral">"WIREDTIGER_HOME"</span>) == NULL) {</div>
<div class="line"> home = <span class="stringliteral">"WT_HOME"</span>;</div>
<div class="line"> ret = system(<span class="stringliteral">"rm -rf WT_HOME && mkdir WT_HOME"</span>);</div>
<div class="line"> } <span class="keywordflow">else</span></div>
<div class="line"> home = NULL;</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* Open a connection to the database, creating it if necessary. */</span></div>
<div class="line"> <span class="keywordflow">if</span> ((ret = <a name="a2"></a><a class="code" href="group__wt.html#ga9e6adae3fc6964ef837a62795c7840ed">wiredtiger_open</a>(home, NULL, <span class="stringliteral">"create"</span>, &conn)) != 0)</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">"Error connecting to %s: %s\n"</span>,</div>
<div class="line"> home, <a name="a3"></a><a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* Open a session for the current thread's work. */</span></div>
<div class="line"> <span class="keywordflow">if</span> ((ret = conn-><a name="a4"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#afc75c44ff4497627c59d9b6aaa64c9d8">open_session</a>(conn, NULL, NULL, &session)) != 0)</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">"Error opening a session on %s: %s\n"</span>,</div>
<div class="line"> home, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div>
<div class="line"></div>
<div class="line"> {</div>
<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"> ret = <a name="a5"></a><a class="code" href="group__wt.html#ga2460e8022f3c8c7cb5f274ec9f1764e6">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"> ret = <a name="a6"></a><a class="code" href="group__wt.html#ga58d055cb4d054715bebd58a2cb713b2d">wiredtiger_struct_pack</a>(session, buf, size, <span class="stringliteral">"iii"</span>, 42, 1000, -9);</div>
<div class="line"></div>
<div class="line"> ret = <a name="a7"></a><a class="code" href="group__wt.html#ga1db8298185374dbb61b398a4e9a3d1c8">wiredtiger_struct_unpack</a>(session, buf, size, <span class="stringliteral">"iii"</span>, &i, &j, &k);</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* Note: closing the connection implicitly closes open session(s). */</span></div>
<div class="line"> <span class="keywordflow">if</span> ((ret = conn-><a name="a8"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#af535c517df851eeac8ebf3594d40b545">close</a>(conn, NULL)) != 0)</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">"Error closing %s: %s\n"</span>,</div>
<div class="line"> home, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> (ret);</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Copyright (c) 2008-2016 MongoDB, Inc. All rights reserved. Contact <a href="mailto:[email protected]">[email protected]</a> for more information.</li>
</ul>
</div>
</body>
</html>