vibe.data.bson

BSON serialization and value handling.

Public Imports

vibe.data.json
public import vibe.data.json;
Undocumented in source.

Members

Aliases

bdata_t
alias bdata_t = immutable(ubyte)[]
Undocumented in source.

Functions

fromBsonData
T fromBsonData(ubyte[] v)
Undocumented in source. Be warned that the author may not have intended to support it.
serializeToBson
Bson serializeToBson(T value, ubyte[] buffer)

Serializes the given value to BSON.

toBigEndianData
ubyte[] toBigEndianData(T v)
Undocumented in source. Be warned that the author may not have intended to support it.
toBsonData
ubyte[] toBsonData(T v)
Undocumented in source. Be warned that the author may not have intended to support it.

Structs

Bson
struct Bson

Represents a BSON value.

BsonBinData
struct BsonBinData

Represents a BSON binary data value (Bson.Type.binData).

BsonDate
struct BsonDate

Represents a BSON date value (Bson.Type.date).

BsonObjectID
struct BsonObjectID

Represents a BSON object id (Bson.Type.binData).

BsonRegex
struct BsonRegex

Represents a BSON regular expression value (Bson.Type.regex).

BsonSerializer
struct BsonSerializer

Serializes to an in-memory BSON representation.

BsonTimestamp
struct BsonTimestamp

Represents a BSON timestamp value (Bson.Type.timestamp).

Templates

deserializeBson
template deserializeBson(T)
Undocumented in source.
isBsonSerializable
template isBsonSerializable(T)

private

Examples

void manipulateBson(Bson b)
{
	import std.stdio;

	// retrieving the values is done using get()
	assert(b["name"].get!string == "Example");
	assert(b["id"].get!int == 1);

	// semantic conversions can be done using to()
	assert(b["id"].to!string == "1");

	// prints:
	// name: "Example"
	// id: 1
	foreach (string key, value; b)
		writefln("%s: %s", key, value);

	// print out with JSON syntax: {"name": "Example", "id": 1}
	writefln("BSON: %s", b.toString());

	// DEPRECATED: object members can be accessed using member syntax, just like in JavaScript
	//j = Bson.emptyObject;
	//j.name = "Example";
	//j.id = 1;
}

Constructing Bson objects

// construct a BSON object {"field1": "foo", "field2": 42, "field3": true}

// using the constructor
Bson b1 = Bson(["field1": Bson("foo"), "field2": Bson(42), "field3": Bson(true)]);

// using piecewise construction
Bson b2 = Bson.emptyObject;
b2["field1"] = "foo";
b2["field2"] = 42;
b2["field3"] = true;

// using serialization
struct S {
	string field1;
	int field2;
	bool field3;
}
Bson b3 = S("foo", 42, true).serializeToBson();

Meta

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.

Authors

Sönke Ludwig