/* Copyright 2010-2016 MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace MongoDB.Bson.IO
{
///
/// Contains extension methods for IBsonWriter.
///
public static class IBsonWriterExtensions
{
///
/// Writes a BSON binary data element to the writer.
///
/// The writer.
/// The name of the element.
/// The binary data.
public static void WriteBinaryData(this IBsonWriter writer, string name, BsonBinaryData binaryData)
{
writer.WriteName(name);
writer.WriteBinaryData(binaryData);
}
///
/// Writes a BSON Boolean element to the writer.
///
/// The writer.
/// The name of the element.
/// The Boolean value.
public static void WriteBoolean(this IBsonWriter writer, string name, bool value)
{
writer.WriteName(name);
writer.WriteBoolean(value);
}
///
/// Writes a BSON binary data element to the writer.
///
/// The writer.
/// The name of the element.
/// The bytes.
public static void WriteBytes(this IBsonWriter writer, string name, byte[] bytes)
{
writer.WriteName(name);
writer.WriteBytes(bytes);
}
///
/// Writes a BSON DateTime element to the writer.
///
/// The writer.
/// The name of the element.
/// The number of milliseconds since the Unix epoch.
public static void WriteDateTime(this IBsonWriter writer, string name, long value)
{
writer.WriteName(name);
writer.WriteDateTime(value);
}
///
/// Writes a BSON Decimal128 element to the writer.
///
/// The writer.
/// The name of the element.
/// The value.
public static void WriteDecimal128(this IBsonWriter writer, string name, Decimal128 value)
{
writer.WriteName(name);
writer.WriteDecimal128(value);
}
///
/// Writes a BSON Double element to the writer.
///
/// The writer.
/// The name of the element.
/// The Double value.
public static void WriteDouble(this IBsonWriter writer, string name, double value)
{
writer.WriteName(name);
writer.WriteDouble(value);
}
///
/// Writes a BSON Int32 element to the writer.
///
/// The writer.
/// The name of the element.
/// The Int32 value.
public static void WriteInt32(this IBsonWriter writer, string name, int value)
{
writer.WriteName(name);
writer.WriteInt32(value);
}
///
/// Writes a BSON Int64 element to the writer.
///
/// The writer.
/// The name of the element.
/// The Int64 value.
public static void WriteInt64(this IBsonWriter writer, string name, long value)
{
writer.WriteName(name);
writer.WriteInt64(value);
}
///
/// Writes a BSON JavaScript element to the writer.
///
/// The writer.
/// The name of the element.
/// The JavaScript code.
public static void WriteJavaScript(this IBsonWriter writer, string name, string code)
{
writer.WriteName(name);
writer.WriteJavaScript(code);
}
///
/// Writes a BSON JavaScript element to the writer (call WriteStartDocument to start writing the scope).
///
/// The writer.
/// The name of the element.
/// The JavaScript code.
public static void WriteJavaScriptWithScope(this IBsonWriter writer, string name, string code)
{
writer.WriteName(name);
writer.WriteJavaScriptWithScope(code);
}
///
/// Writes a BSON MaxKey element to the writer.
///
/// The writer.
/// The name of the element.
public static void WriteMaxKey(this IBsonWriter writer, string name)
{
writer.WriteName(name);
writer.WriteMaxKey();
}
///
/// Writes a BSON MinKey element to the writer.
///
/// The writer.
/// The name of the element.
public static void WriteMinKey(this IBsonWriter writer, string name)
{
writer.WriteName(name);
writer.WriteMinKey();
}
///
/// Writes a BSON null element to the writer.
///
/// The writer.
/// The name of the element.
public static void WriteNull(this IBsonWriter writer, string name)
{
writer.WriteName(name);
writer.WriteNull();
}
///
/// Writes a BSON ObjectId element to the writer.
///
/// The writer.
/// The name of the element.
/// The ObjectId.
public static void WriteObjectId(this IBsonWriter writer, string name, ObjectId objectId)
{
writer.WriteName(name);
writer.WriteObjectId(objectId);
}
///
/// Writes a raw BSON array.
///
/// The writer.
/// The name.
/// The byte buffer containing the raw BSON array.
public static void WriteRawBsonArray(this IBsonWriter writer, string name, IByteBuffer slice)
{
writer.WriteName(name);
writer.WriteRawBsonArray(slice);
}
///
/// Writes a raw BSON document.
///
/// The writer.
/// The name.
/// The byte buffer containing the raw BSON document.
public static void WriteRawBsonDocument(this IBsonWriter writer, string name, IByteBuffer slice)
{
writer.WriteName(name);
writer.WriteRawBsonDocument(slice);
}
///
/// Writes a BSON regular expression element to the writer.
///
/// The writer.
/// The name of the element.
/// A BsonRegularExpression.
public static void WriteRegularExpression(this IBsonWriter writer, string name, BsonRegularExpression regex)
{
writer.WriteName(name);
writer.WriteRegularExpression(regex);
}
///
/// Writes the start of a BSON array element to the writer.
///
/// The writer.
/// The name of the element.
public static void WriteStartArray(this IBsonWriter writer, string name)
{
writer.WriteName(name);
writer.WriteStartArray();
}
///
/// Writes the start of a BSON document element to the writer.
///
/// The writer.
/// The name of the element.
public static void WriteStartDocument(this IBsonWriter writer, string name)
{
writer.WriteName(name);
writer.WriteStartDocument();
}
///
/// Writes a BSON String element to the writer.
///
/// The writer.
/// The name of the element.
/// The String value.
public static void WriteString(this IBsonWriter writer, string name, string value)
{
writer.WriteName(name);
writer.WriteString(value);
}
///
/// Writes a BSON Symbol element to the writer.
///
/// The writer.
/// The name of the element.
/// The symbol.
public static void WriteSymbol(this IBsonWriter writer, string name, string value)
{
writer.WriteName(name);
writer.WriteSymbol(value);
}
///
/// Writes a BSON timestamp element to the writer.
///
/// The writer.
/// The name of the element.
/// The combined timestamp/increment value.
public static void WriteTimestamp(this IBsonWriter writer, string name, long value)
{
writer.WriteName(name);
writer.WriteTimestamp(value);
}
///
/// Writes a BSON undefined element to the writer.
///
/// The writer.
/// The name of the element.
public static void WriteUndefined(this IBsonWriter writer, string name)
{
writer.WriteName(name);
writer.WriteUndefined();
}
}
}