Loading...
Searching...
No Matches
Appending
BSON

Functions to append various kinds of elements to existing BSON objects. More...

Collaboration diagram for Appending:

## Functions

gboolean | bson_append_string (bson *b, const gchar *name, const gchar *val, gint32 length)
| Append a string to a BSON object.
gboolean | bson_append_double (bson *b, const gchar *name, gdouble d)
| Append a double to a BSON object.
gboolean | bson_append_document (bson *b, const gchar *name, const bson *doc)
| Append a BSON document to a BSON object.
gboolean | bson_append_array (bson *b, const gchar *name, const bson *array)
| Append a BSON array to a BSON object.
gboolean | bson_append_binary (bson *b, const gchar *name, bson_binary_subtype subtype, const guint8 *data, gint32 size)
| Append a BSON binary blob to a BSON object.
gboolean | bson_append_oid (bson *b, const gchar *name, const guint8 *oid)
| Append an ObjectID to a BSON object.
gboolean | bson_append_boolean (bson *b, const gchar *name, gboolean value)
| Append a boolean to a BSON object.
gboolean | bson_append_utc_datetime (bson *b, const gchar *name, gint64 ts)
| Append an UTC datetime to a BSON object.
gboolean | bson_append_null (bson *b, const gchar *name)
| Append a NULL value to a BSON object.
gboolean | bson_append_regex (bson *b, const gchar *name, const gchar *regexp, const gchar *options)
| Append a regexp object to a BSON object.
gboolean | bson_append_javascript (bson *b, const gchar *name, const gchar *js, gint32 len)
| Append Javascript code to a BSON object.
gboolean | bson_append_symbol (bson *b, const gchar *name, const gchar *symbol, gint32 len)
| Append a symbol to a BSON object.
gboolean | bson_append_javascript_w_scope (bson *b, const gchar *name, const gchar *js, gint32 len, const bson *scope)
| Append Javascript code (with scope) to a BSON object.
gboolean | bson_append_int32 (bson *b, const gchar *name, gint32 i)
| Append a 32-bit integer to a BSON object.
gboolean | bson_append_timestamp (bson *b, const gchar *name, gint64 ts)
| Append a timestamp to a BSON object.
gboolean | bson_append_int64 (bson *b, const gchar *name, gint64 i)
| Append a 64-bit integer to a BSON object.

## Detailed Description

Functions to append various kinds of elements to existing BSON objects.

Every such function expects the BSON object to be open, and will return FALSE immediately if it finds that the object has had bson_finish() called on it before.

The only way to append to a finished BSON object is to clone it with bson_new_from_data(), and append to the newly created object.

## Function Documentation

## bson_append_array()

gboolean bson_append_array | ( | bson * | b,
|  | const gchar * | name,
|  | const bson * | array )

Append a BSON array to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  array | is the BSON array to append.

Note
  array MUST be a finished BSON document.
  The difference between plain documents and arrays - as far as this library is concerned, and apart from the type - is that array keys must be numbers in increasing order. However, no extra care is taken to verify that: it is the responsibility of the caller to set the array up appropriately.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_binary()

gboolean bson_append_binary | ( | bson * | b,
|  | const gchar * | name,
|  | bson_binary_subtype | subtype,
|  | const guint8 * | data,
|  | gint32 | size )

Append a BSON binary blob to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  subtype | is the BSON binary subtype to use.
  data | is a pointer to the blob data.
  size | is the size of the blob.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_boolean()

gboolean bson_append_boolean | ( | bson * | b,
|  | const gchar * | name,
|  | gboolean | value )

Append a boolean to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  value | is the boolean value to append.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_document()

gboolean bson_append_document | ( | bson * | b,
|  | const gchar * | name,
|  | const bson * | doc )

Append a BSON document to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  doc | is the BSON document to append.

Note
  doc MUST be a finished BSON document.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_double()

gboolean bson_append_double | ( | bson * | b,
|  | const gchar * | name,
|  | gdouble | d )

Append a double to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  d | is the double value to append.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_int32()

gboolean bson_append_int32 | ( | bson * | b,
|  | const gchar * | name,
|  | gint32 | i )

Append a 32-bit integer to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  i | is the integer to append.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_int64()

gboolean bson_append_int64 | ( | bson * | b,
|  | const gchar * | name,
|  | gint64 | i )

Append a 64-bit integer to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  i | is the integer to append.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_javascript()

gboolean bson_append_javascript | ( | bson * | b,
|  | const gchar * | name,
|  | const gchar * | js,
|  | gint32 | len )

Append Javascript code to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  js | is the javascript code as a C string.
  len | is the length of the code, use -1 to use the full length of the string supplised in js.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_javascript_w_scope()

gboolean bson_append_javascript_w_scope | ( | bson * | b,
|  | const gchar * | name,
|  | const gchar * | js,
|  | gint32 | len,
|  | const bson * | scope )

Append Javascript code (with scope) to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  js | is the javascript code as a C string.
  len | is the length of the code, use -1 to use the full length of the string supplied in js.
  scope | is scope to evaluate the javascript code in.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_null()

gboolean bson_append_null | ( | bson * | b,
|  | const gchar * | name )

Append a NULL value to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_oid()

gboolean bson_append_oid | ( | bson * | b,
|  | const gchar * | name,
|  | const guint8 * | oid )

Append an ObjectID to a BSON object.

ObjectIDs are 12 byte values, the first four being a timestamp in big endian byte order, the next three a machine ID, then two bytes for the PID, and finally three bytes of sequence number, in big endian byte order again.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  oid | is the ObjectID to append.

Note
  The OID must be 12 bytes long, and formatting it appropriately is the responsiblity of the caller.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_regex()

gboolean bson_append_regex | ( | bson * | b,
|  | const gchar * | name,
|  | const gchar * | regexp,
|  | const gchar * | options )

Append a regexp object to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  regexp | is the regexp string itself.
  options | represents the regexp options, serialised to a string.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_string()

gboolean bson_append_string | ( | bson * | b,
|  | const gchar * | name,
|  | const gchar * | val,
|  | gint32 | length )

Append a string to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  val | is the value to append.
  length | is the length of value. Use -1 to use the full string supplied as name.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_symbol()

gboolean bson_append_symbol | ( | bson * | b,
|  | const gchar * | name,
|  | const gchar * | symbol,
|  | gint32 | len )

Append a symbol to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  symbol | is the symbol to append.
  len | is the length of the code, use -1 to use the full length of the string supplised in symbol.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_timestamp()

gboolean bson_append_timestamp | ( | bson * | b,
|  | const gchar * | name,
|  | gint64 | ts )

Append a timestamp to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  ts | is the timestamp to append.

Note
  The ts param should consists of 4 bytes of increment, followed by 4 bytes of timestamp. It is the responsibility of the caller to set the variable up appropriately.

Returns
  TRUE on success, FALSE otherwise.

## bson_append_utc_datetime()

gboolean bson_append_utc_datetime | ( | bson * | b,
|  | const gchar * | name,
|  | gint64 | ts )

Append an UTC datetime to a BSON object.

Parameters

  b | is the BSON object to append to.
  name | is the key name.
  ts | is the UTC timestamp: the number of milliseconds since the Unix epoch.

Returns
  TRUE on success, FALSE otherwise.