serializeToBson

Serializes the given value to BSON.

The following types of values are supported:

Bson
Used as-is
Json
Converted to BSON
BsonBinData
Converted to Bson.Type.binData
BsonObjectID
Converted to Bson.Type.objectID
BsonDate
Converted to Bson.Type.date
BsonTimestamp
Converted to Bson.Type.timestamp
BsonRegex
Converted to Bson.Type.regex
null
Converted to Bson.Type.null_
bool
Converted to Bson.Type.bool_
float, double
Converted to Bson.Type.double_
short, ushort, int, uint, long, ulong
Converted to Bson.Type.long_
string
Converted to Bson.Type.string
ubyte[]
Converted to Bson.Type.binData
T[]
Converted to Bson.Type.array
T[string]
Converted to Bson.Type.object
struct
Converted to Bson.Type.object
class
Converted to Bson.Type.object or Bson.Type.null_

All entries of an array or an associative array, as well as all R/W properties and all fields of a struct/class are recursively serialized using the same rules.

Fields ending with an underscore will have the last underscore stripped in the serialized output. This makes it possible to use fields with D keywords as their name by simply appending an underscore.

The following methods can be used to customize the serialization of structs/classes:

Bson toBson() const;
static T fromBson(Bson src);

Json toJson() const;
static T fromJson(Json src);

string toString() const;
static T fromString(string src);

The methods will have to be defined in pairs. The first pair that is implemented by the type will be used for serialization (i.e. toBson overrides toJson).

serializeToBson
(
T
)
(
auto ref T value
,
ubyte[] buffer = null
)

See Also

deserializeBson

Meta