SYNOPSIS

#include <bson.h>

void
bson_init (bson_t *bson);

bool
bson_init_static (bson_t        *bson,
                  const uint8_t *data,
                  uint32_t       length);

bson_t *
bson_new (void);

bson_t *
bson_new_from_data (const uint8_t *data,
                    uint32_t       length);

bson_t *
bson_sized_new (size_t size);

DESCRIPTION

The bson_init() function shall initialize a bson_t that is placed on the stack. This is equivalent to initializing a bson_t to BSON_INITIALIZER.

The bson_init_static() function shall shall initialize a read-only bson_t on the stack using the data provided. No copies of the data will be made and therefore must remain valid for the lifetime of the bson_t.

The bson_new() function shall create a new bson_t structure on the heap. It should be freed with bson_destroy() when it is no longer in use.

The bson_new_from_data() function shall create a new bson_t on the heap and copy the contents of data. This may be helpful when working with language bindings but is generally expected to be slower.

The bson_sized_new() function shall create a new bson_t on the heap with a preallocated buffer. This is useful if you have a good idea of the size of the resulting document.

bson_destroy() MUST be called when no longer using the bson_t.

RETURN VALUE

bson_init_static() will return TRUE if the bson_t was successfully initialized.

ERRORS

bson_init_static() and bson_new_from_data() can fail if the buffer length does not match the discovered length within the buffer.

SEE ALSO

AUTHORS

This page was written by MongoDB, Inc.