BSON-XS
view release on metacpan or search on metacpan
bson/bson-iter.c view on Meta::CPAN
*
* Advances @iter to the next field of the underlying BSON document.
* If all fields have been exhausted, then %false is returned.
*
* It is a programming error to use @iter after this function has
* returned false.
*
* Returns:
* true if the iter was advanced to the next record.
* otherwise false and @iter should be considered invalid.
*
* Side effects:
* @iter may be invalidated.
*
*--------------------------------------------------------------------------
*/
bool
bson_iter_next (bson_iter_t *iter) /* INOUT */
{
uint32_t bson_type;
const char *key;
bool unsupported;
return _bson_iter_next_internal (iter, &key, &bson_type, &unsupported);
}
/*
*--------------------------------------------------------------------------
*
* bson_iter_binary --
*
* Retrieves the BSON_TYPE_BINARY field. The subtype is stored in
* @subtype. The length of @binary in bytes is stored in @binary_len.
*
* @binary should not be modified or freed and is only valid while
* @iter's bson_t is valid and unmodified.
*
* Parameters:
* @iter: A bson_iter_t
* @subtype: A location for the binary subtype.
* @binary_len: A location for the length of @binary.
* @binary: A location for a pointer to the binary data.
*
* Returns:
* None.
*
* Side effects:
* None.
*
*--------------------------------------------------------------------------
*/
void
bson_iter_binary (const bson_iter_t *iter, /* IN */
bson_subtype_t *subtype, /* OUT */
uint32_t *binary_len, /* OUT */
const uint8_t **binary) /* OUT */
{
bson_subtype_t backup;
BSON_ASSERT (iter);
BSON_ASSERT (!binary || binary_len);
if (ITER_TYPE (iter) == BSON_TYPE_BINARY) {
if (!subtype) {
subtype = &backup;
}
*subtype = (bson_subtype_t) *(iter->raw + iter->d2);
if (binary) {
memcpy (binary_len, (iter->raw + iter->d1), sizeof (*binary_len));
*binary_len = BSON_UINT32_FROM_LE (*binary_len);
*binary = iter->raw + iter->d3;
if (*subtype == BSON_SUBTYPE_BINARY_DEPRECATED) {
*binary_len -= sizeof (int32_t);
*binary += sizeof (int32_t);
}
}
return;
}
if (binary) {
*binary = NULL;
}
if (binary_len) {
*binary_len = 0;
}
if (subtype) {
*subtype = BSON_SUBTYPE_BINARY;
}
}
/*
*--------------------------------------------------------------------------
*
* bson_iter_bool --
*
* Retrieves the current field of type BSON_TYPE_BOOL.
*
* Returns:
* true or false, dependent on bson document.
*
* Side effects:
* None.
*
*--------------------------------------------------------------------------
*/
bool
bson_iter_bool (const bson_iter_t *iter) /* IN */
{
BSON_ASSERT (iter);
if (ITER_TYPE (iter) == BSON_TYPE_BOOL) {
return bson_iter_bool_unsafe (iter);
}
return false;
}
( run in 0.979 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )