vibe.d beta banner
get vibe.d
0.10.0

Asynchronous I/O that doesn’t get in your way, written in D

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

NameDescription
deserializeBson(dst, src) Deserializes a BSON value into the destination variable.
fromBsonData(v)
serializeToBson(value, buffer) Serializes the given value to BSON.
toBigEndianData(v)
toBsonData(v)

Structs

NameDescription
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

NameTypeDescription
bdata_t immutable(ubyte)[]
Authors

Sönke Ludwig

Copyright

© 2012-2015 Sönke Ludwig

License

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