Property definitions

mongodb $ NativeBSON :: defaultinit
# Wrapper for `bson_t`.
#
# All data manipulated by `mongoc` are BSON formated.
#
# The `bson_t` structure represents a BSON document.
# This structure manages the underlying BSON encoded buffer.
# For mutable documents, it can append new data to the document.
#
# See [`bson_t`](http://api.mongodb.org/libbson/current/bson_t.html).
extern class NativeBSON `{ bson_t * `}

	# Wrapper for `bson_new()`.
	#
	# The `bson_new()` function shall create a new `bson_t` structure on the heap.
	# It should be freed with `bson_destroy()` when it is no longer in use.
	new `{ return bson_new(); `}

	# Wrapper for `bson_new_from_json()`.
	#
	# The `bson_new_from_json()` function allocates and initialize a new `bson_t`
	# by parsing the JSON found in `data`.
	# Only a single JSON object may exist in data or an error will be set and
	# `NULL` returned.
	new from_json_string(data: CString) import set_mongoc_error `{
		bson_error_t error;
		bson_t *bson;
		bson = bson_new_from_json((uint8_t *)data, -1, &error);
		if(!bson) {
			NativeBSON_set_mongoc_error(bson, &error);
			return NULL;
		}
		return bson;
	`}

	# Wrapper for `bson_as_json()`.
	#
	# The `bson_as_json()` function shall encode bson as a JSON encoded UTF-8 string.
	# The caller is responsible for freeing the resulting UTF-8 encoded string
	# by calling `bson_free()` with the result.
	fun to_c_string: CString `{ return bson_as_json(self, NULL); `}

	# Wrapper for `bson_destroy()`.
	#
	# The `bson_destroy()` function shall free an allocated `bson_t` structure.
	# This function should always be called when you are done with a `bson_t`
	# unless otherwise specified.
	#
	# This instance should not be used beyond this point!
	fun destroy `{ bson_destroy(self); `}

	# Utility method to set `Sys.last_mongoc_error`.
	fun set_mongoc_error(err: BSONError) do sys.last_mongoc_error = err
end
lib/mongodb/native_mongodb.nit:28,1--80,3