SYNOPSIS

#include <bson.h>

#define BSON_ITER_HOLDS_CODE(iter) \
   (bson_iter_type ((iter)) == BSON_TYPE_CODE)

#define BSON_ITER_HOLDS_CODEWSCOPE(iter) \
   (bson_iter_type ((iter)) == BSON_TYPE_CODEWSCOPE)

const char *
bson_iter_code (const bson_iter_t *iter,
                uint32_t          *length);

const char *
bson_iter_codewscope (const bson_iter_t *iter,
                      uint32_t          *length,
                      uint32_t          *scope_len,
                      const uint8_t    **scope);

DESCRIPTION

The bson_iter_code() function shall retrieve the JavaScript contents of an element of type BSON_TYPE_CODE. You can check that a field is of type BSON_TYPE_CODE with bson_iter_type() or BSON_ITER_HOLDS_CODE().

The bson_iter_codewscope() function acts similar to bson_iter_code() except for BSON_TYPE_CODEWSCOPE elements. It also will provide a pointer to the buffer for scope, which can be loaded into a bson_t.

RETURN VALUE

A UTF-8 encoded string that should not be modified or freed. length will be set to the length of the return value in bytes.

ERRORS

It is a programming error to call bson_iter_code() on an element other than BSON_TYPE_CODE.

It is a programming error to call bson_iter_codewscope() on an element other than BSON_TYPE_CODEWSCOPE.

SEE ALSO

AUTHORS

This page was written by MongoDB, Inc.