Version 3.1.0
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. Only the default big-endian, packed format is currently supported.

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));