vibe.d beta banner
get vibe.d
0.7.30

Module vibe.data.bson

BSON serialization and value handling.

Example

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;
}

Example

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();

Functions

Name Description
deserializeBson Deserializes a BSON value into the destination variable.
fromBsonData
serializeToBson Serializes the given value to BSON.
toBigEndianData
toBsonData

Structs

Name Description
Bson Represents a BSON value.
BsonBinData Represents a BSON binary data value (Bson.Type.binData).
BsonDate Represents a BSON date value (Bson.Type.date).
BsonObjectID Represents a BSON object id (Bson.Type.binData).
BsonRegex Represents a BSON regular expression value (Bson.Type.regex).
BsonSerializer Serializes to an in-memory BSON representation.
BsonTimestamp Represents a BSON timestamp value (Bson.Type.timestamp).

Aliases

Name Type Description
bdata_t immutable(ubyte)[]
Authors

Sönke Ludwig

Copyright

© 2012-2015 RejectedSoftware e.K.

License

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