BSON-XS
view release on metacpan or search on metacpan
bson/bson.c view on Meta::CPAN
/*
*--------------------------------------------------------------------------
*
* bson_append_dbpointer --
*
* This BSON data type is DEPRECATED.
*
* Append a BSON dbpointer field to @bson.
*
* Returns:
* true if successful; otherwise false.
*
* Side effects:
* None.
*
*--------------------------------------------------------------------------
*/
bool
bson_append_dbpointer (bson_t *bson, /* IN */
const char *key, /* IN */
int key_length, /* IN */
const char *collection, /* IN */
const bson_oid_t *oid)
{
static const uint8_t type = BSON_TYPE_DBPOINTER;
uint32_t length;
uint32_t length_le;
BSON_ASSERT (bson);
BSON_ASSERT (key);
BSON_ASSERT (collection);
BSON_ASSERT (oid);
if (key_length < 0) {
key_length = (int)strlen (key);
}
length = (int)strlen (collection) + 1;
length_le = BSON_UINT32_TO_LE (length);
return _bson_append (bson, 6,
(1 + key_length + 1 + 4 + length + 12),
1, &type,
key_length, key,
1, &gZero,
4, &length_le,
length, collection,
12, oid);
}
/*
*--------------------------------------------------------------------------
*
* bson_append_document --
*
* Append a new field to @bson containing a BSON document.
*
* In general, using bson_append_document_begin() results in faster
* code and less memory fragmentation.
*
* Returns:
* true if successful; otherwise false.
*
* Side effects:
* None.
*
* See also:
* bson_append_document_begin().
*
*--------------------------------------------------------------------------
*/
bool
bson_append_document (bson_t *bson, /* IN */
const char *key, /* IN */
int key_length, /* IN */
const bson_t *value) /* IN */
{
static const uint8_t type = BSON_TYPE_DOCUMENT;
BSON_ASSERT (bson);
BSON_ASSERT (key);
BSON_ASSERT (value);
if (key_length < 0) {
key_length = (int)strlen (key);
}
return _bson_append (bson, 4,
(1 + key_length + 1 + value->len),
1, &type,
key_length, key,
1, &gZero,
value->len, _bson_data (value));
}
bool
bson_append_double (bson_t *bson,
const char *key,
int key_length,
double value)
{
static const uint8_t type = BSON_TYPE_DOUBLE;
BSON_ASSERT (bson);
BSON_ASSERT (key);
if (key_length < 0) {
key_length = (int)strlen (key);
}
#if BSON_BYTE_ORDER == BSON_BIG_ENDIAN
value = BSON_DOUBLE_TO_LE (value);
#endif
return _bson_append (bson, 4,
(1 + key_length + 1 + 8),
1, &type,
( run in 2.409 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )