Version 11.0.0
All Classes Functions Variables Typedefs Enumerations Enumerator Modules Pages
Packing and Unpacking Data

WiredTiger's data packing uses format strings similar to those specified in the Python struct module: http://docs.python.org/library/struct

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:

CharacterByte orderSizeAlignment
.big-endianpackednone
>big-endianstandardnone
<little-endianstandardnone
@nativenativenative

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.

Note: little-endian format not yet supported in WiredTiger.

The remaining characters in the format string specify the type of each field to be packed into or unpacked from a byte array. See Column types for the list of supported types.

Code samples

The code below is taken from the complete example program ex_pack.c. It demonstrates how to pack three integer values into a buffer and then unpack them again.

size_t size;
char buf[50];
error_check(wiredtiger_struct_size(session, &size, "iii", 42, 1000, -9));
if (size > sizeof(buf)) {
/* Allocate a bigger buffer. */
}
error_check(wiredtiger_struct_pack(session, buf, size, "iii", 42, 1000, -9));
error_check(wiredtiger_struct_unpack(session, buf, size, "iii", &i, &j, &k));
wiredtiger_struct_unpack
int wiredtiger_struct_unpack(WT_SESSION *session, const void *buffer, size_t len, const char *format,...)
Unpack a structure from a buffer.
wiredtiger_struct_size
int wiredtiger_struct_size(WT_SESSION *session, size_t *lenp, const char *format,...)
Calculate the size required to pack a structure.
wiredtiger_struct_pack
int wiredtiger_struct_pack(WT_SESSION *session, void *buffer, size_t len, const char *format,...)
Pack a structure into a buffer.