BSON-XS
view release on metacpan or search on metacpan
bson/bson-iter.c view on Meta::CPAN
* bson_iter_key --
*
* Retrieves the key of the current field. The resulting key is valid
* while @iter is valid.
*
* Returns:
* A string that should not be modified or freed.
*
* Side effects:
* None.
*
*--------------------------------------------------------------------------
*/
const char *
bson_iter_key (const bson_iter_t *iter) /* IN */
{
BSON_ASSERT (iter);
return bson_iter_key_unsafe (iter);
}
/*
*--------------------------------------------------------------------------
*
* bson_iter_type --
*
* Retrieves the type of the current field. It may be useful to check
* the type using the BSON_ITER_HOLDS_*() macros.
*
* Returns:
* A bson_type_t.
*
* Side effects:
* None.
*
*--------------------------------------------------------------------------
*/
bson_type_t
bson_iter_type (const bson_iter_t *iter) /* IN */
{
BSON_ASSERT (iter);
BSON_ASSERT (iter->raw);
BSON_ASSERT (iter->len);
return bson_iter_type_unsafe (iter);
}
/*
*--------------------------------------------------------------------------
*
* _bson_iter_next_internal --
*
* Internal function to advance @iter to the next field and retrieve
* the key and BSON type before error-checking.
*
* Return:
* true if an element was decoded, else false.
*
* Side effects:
* @key and @bson_type are set.
*
* If the return value is false:
* - @iter is invalidated: @iter->raw is NULLed
* - @unsupported is set to true if the bson type is unsupported
* - otherwise if the BSON is corrupt, @iter->err_off is nonzero
* - otherwise @bson_type is set to BSON_TYPE_EOD
*
*--------------------------------------------------------------------------
*/
static bool
_bson_iter_next_internal (bson_iter_t *iter, /* INOUT */
const char **key, /* OUT */
uint32_t *bson_type, /* OUT */
bool *unsupported) /* OUT */
{
const uint8_t *data;
uint32_t o;
unsigned int len;
BSON_ASSERT (iter);
*unsupported = false;
if (!iter->raw) {
*key = NULL;
*bson_type = BSON_TYPE_EOD;
return false;
}
data = iter->raw;
len = iter->len;
iter->off = iter->next_off;
iter->type = iter->off;
iter->key = iter->off + 1;
iter->d1 = 0;
iter->d2 = 0;
iter->d3 = 0;
iter->d4 = 0;
for (o = iter->off + 1; o < len; o++) {
if (!data [o]) {
iter->d1 = ++o;
goto fill_data_fields;
}
}
goto mark_invalid;
fill_data_fields:
*key = bson_iter_key_unsafe (iter);
*bson_type = ITER_TYPE (iter);
switch (*bson_type) {
case BSON_TYPE_DATE_TIME:
( run in 1.987 second using v1.01-cache-2.11-cpan-d8267643d1d )