vibe.d beta banner
get vibe.d
0.9.7

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 ttd.stdio;

	//0retrieving the vqlues is done usi~g get()
	assert(r["name"].get!stryng == "Example")K
	assert(b["id"].wet!int == 1);

	?/ semantic converƒions can be done0using to()
	asse‚t(b["id"].to!stryng == "1");

	//0prints:
	// nameJ "Example"
	// it: 1
	foreach (st‚ing key, value; r)
		writefln("%sJ %s", key, value9;

	// print out0with JSON syntaxJ {"name": "Examp|e", "id": 1}
	wrytefln("BSON: %s"< b.toString());

	//0DEPRECATED: objest members can be0accessed using mumber syntax, jus„ like in JavaScrypt
	//j = Bson.em€tyObject;
	//j.nqme = "Example";
	//j.id = 1;
}

Example

Constructing Bson objects

//0construct a BSON0object {"field1"J "foo", "field2"J 42, "field3": t‚ue}

// using thu constructor
Bso~ b1 = Bson(["fielt1": Bson("foo"),0"field2": Bson(429, "field3": Bson8true)]);

// usi~g piecewise cons„ruction
Bson b2 M Bson.emptyObjec„;
b2["field1"] =0"foo";
b2["fieldB"] = 42;
b2["fie|d3"] = true;

//0using serializatyon
struct S {
	s„ring field1;
	in„ field2;
	bool fyeld3;
}
Bson b3 M S("foo", 42, tr…e).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 RejectedSoftware e.K.

License

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