本文整理汇总了C#中BsonBinarySubType类的典型用法代码示例。如果您正苦于以下问题:C# BsonBinarySubType类的具体用法?C# BsonBinarySubType怎么用?C# BsonBinarySubType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonBinarySubType类属于命名空间,在下文中一共展示了BsonBinarySubType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadBinaryData
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
public override void ReadBinaryData(
out byte[] bytes,
out BsonBinarySubType subType
) {
if (disposed) { ThrowObjectDisposedException(); }
VerifyBsonType("ReadBinaryData", BsonType.Binary);
int size = ReadSize();
subType = (BsonBinarySubType) buffer.ReadByte();
if (subType == BsonBinarySubType.OldBinary) {
// sub type OldBinary has two sizes (for historical reasons)
int size2 = ReadSize();
if (size2 != size - 4) {
throw new FileFormatException("Binary sub type OldBinary has inconsistent sizes");
}
size = size2;
if (settings.FixOldBinarySubTypeOnInput) {
subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
}
}
bytes = buffer.ReadBytes(size);
state = BsonReadState.Type;
}
示例2: WriteBinaryData
/// <summary>
/// Writes a BSON binary data element to the writer.
/// </summary>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
public override void WriteBinaryData(
byte[] bytes,
BsonBinarySubType subType
) {
var guidRepresentation = (subType == BsonBinarySubType.UuidStandard) ? GuidRepresentation.Standard : GuidRepresentation.Unspecified;
WriteBinaryData(bytes, subType, guidRepresentation);
}
示例3: WriteBinaryData
/// <summary>
/// Writes a BSON binary data element to the writer.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
public override void WriteBinaryData(
string name,
byte[] bytes,
BsonBinarySubType subType
) {
WriteName(name);
WriteBinaryData(bytes, subType);
}
示例4: ReadJson_should_return_expected_result_when_using_native_json_reader
public void ReadJson_should_return_expected_result_when_using_native_json_reader(string json, string nullableHexBytes, BsonBinarySubType subType)
{
var subject = new BsonBinaryDataConverter();
var expectedResult = nullableHexBytes == null ? null : new BsonBinaryData(BsonUtils.ParseHexString(nullableHexBytes), subType);
var result = ReadJsonUsingNativeJsonReader<BsonBinaryData>(subject, json);
result.Should().Be(expectedResult);
}
开发者ID:rstam,项目名称:mongo-csharp-driver-jsondotnet-original,代码行数:9,代码来源:BsonBinaryDataConverterTests.cs
示例5: ReadBinaryData
/// <summary>
/// Reads BSON binary data from the reader.
/// </summary>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
public override void ReadBinaryData(
out byte[] bytes,
out BsonBinarySubType subType
) {
if (disposed) { ThrowObjectDisposedException(); }
VerifyBsonType("ReadBinaryData", BsonType.Binary);
state = GetNextState();
var binaryData = currentValue.AsBsonBinaryData;
bytes = binaryData.Bytes;
subType = binaryData.SubType;
}
示例6: ReadBinaryData
/// <summary>
/// Reads BSON binary data from the reader.
/// </summary>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
public override void ReadBinaryData(
out byte[] bytes,
out BsonBinarySubType subType,
out GuidRepresentation guidRepresentation)
{
if (Disposed) { ThrowObjectDisposedException(); }
VerifyBsonType("ReadBinaryData", BsonType.Binary);
State = GetNextState();
var binaryData = _currentValue.AsBsonBinaryData;
bytes = binaryData.Bytes;
subType = binaryData.SubType;
guidRepresentation = binaryData.GuidRepresentation;
}
示例7: WriteBinaryData
public override void WriteBinaryData(
byte[] bytes,
BsonBinarySubType subType
)
{
if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (state != BsonWriterState.Value) {
var message = string.Format("WriteBinaryData cannot be called when State is: {0}", state);
throw new InvalidOperationException(message);
}
WriteValue(new BsonBinaryData(bytes, subType));
state = GetNextState();
}
示例8: WriteBinaryData
/// <summary>
/// Writes BSON binary data to the writer.
/// </summary>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
public override void WriteBinaryData(
byte[] bytes,
BsonBinarySubType subType
) {
if (disposed) { throw new ObjectDisposedException("JsonWriter"); }
if (state != BsonWriterState.Value && state != BsonWriterState.Initial) {
var message = string.Format("WriteBinaryData cannot be called when State is: {0}", state);
throw new InvalidOperationException(message);
}
WriteStartDocument();
WriteString("$binary", Convert.ToBase64String(bytes));
WriteString("$type", ((int) subType).ToString("x2"));
WriteEndDocument();
state = GetNextState();
}
示例9: WriteBinaryData
/// <summary>
/// Writes BSON binary data to the writer.
/// </summary>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
public override void WriteBinaryData(
byte[] bytes,
BsonBinarySubType subType,
GuidRepresentation guidRepresentation // ignored for now (until we figure out how to represent this in the generated JSON)
) {
if (disposed) { throw new ObjectDisposedException("JsonWriter"); }
if (state != BsonWriterState.Value && state != BsonWriterState.Initial) {
ThrowInvalidState("WriteBinaryData", BsonWriterState.Value, BsonWriterState.Initial);
}
if (settings.OutputMode == JsonOutputMode.Shell) {
WriteNameHelper(name);
textWriter.Write("new BinData({0}, \"{1}\")", (int) subType, Convert.ToBase64String(bytes));
} else {
WriteStartDocument();
WriteString("$binary", Convert.ToBase64String(bytes));
WriteString("$type", ((int) subType).ToString("x2"));
WriteEndDocument();
}
state = GetNextState();
}
示例10: WriteBinaryData
/// <summary>
/// Writes BSON binary data to the writer.
/// </summary>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
public override void WriteBinaryData(
byte[] bytes,
BsonBinarySubType subType
) {
if (disposed) { throw new ObjectDisposedException("JsonWriter"); }
if (state != BsonWriterState.Value && state != BsonWriterState.Initial) {
var message = string.Format("WriteBinaryData cannot be called when State is: {0}", state);
throw new InvalidOperationException(message);
}
if (settings.OutputMode == JsonOutputMode.Shell) {
WriteNameHelper(name);
textWriter.Write("new BinData({0}, \"{1}\")", (int) subType, Convert.ToBase64String(bytes));
} else {
WriteStartDocument();
WriteString("$binary", Convert.ToBase64String(bytes));
WriteString("$type", ((int) subType).ToString("x2"));
WriteEndDocument();
}
state = GetNextState();
}
示例11: ReadBinaryData
public abstract void ReadBinaryData(
string name,
out byte[] bytes,
out BsonBinarySubType subType
);
示例12: WriteBinaryData
/// <summary>
/// Writes a BSON binary data element to the writer.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
public abstract void WriteBinaryData(
string name,
byte[] bytes,
BsonBinarySubType subType
);
示例13: WriteBinaryData
/// <summary>
/// Writes BSON binary data to the writer.
/// </summary>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
/// <param name="guidRepresentation">The respresentation for Guids.</param>
public abstract void WriteBinaryData(byte[] bytes, BsonBinarySubType subType, GuidRepresentation guidRepresentation);
示例14: WriteBinaryData
/// <summary>
/// Writes BSON binary data to the writer.
/// </summary>
/// <param name="bytes">The binary data.</param>
/// <param name="subType">The binary data subtype.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
public override void WriteBinaryData(
byte[] bytes,
BsonBinarySubType subType,
GuidRepresentation guidRepresentation)
{
if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
{
ThrowInvalidState("WriteBinaryData", BsonWriterState.Value, BsonWriterState.Initial);
}
if (_jsonWriterSettings.OutputMode == JsonOutputMode.Shell)
{
WriteNameHelper(Name);
switch (subType)
{
case BsonBinarySubType.UuidLegacy:
case BsonBinarySubType.UuidStandard:
if (bytes.Length != 16)
{
var message = string.Format("Length of binary subtype {0} must be 16, not {1}.", subType, bytes.Length);
throw new ArgumentException(message);
}
if (subType == BsonBinarySubType.UuidLegacy && guidRepresentation == GuidRepresentation.Standard)
{
throw new ArgumentException("GuidRepresentation for binary subtype UuidLegacy must not be Standard.");
}
if (subType == BsonBinarySubType.UuidStandard && guidRepresentation != GuidRepresentation.Standard)
{
var message = string.Format("GuidRepresentation for binary subtype UuidStandard must be Standard, not {0}.", guidRepresentation);
throw new ArgumentException(message);
}
if (_jsonWriterSettings.ShellVersion >= new Version(2, 0, 0))
{
if (guidRepresentation == GuidRepresentation.Unspecified)
{
var s = BsonUtils.ToHexString(bytes);
var parts = new string[]
{
s.Substring(0, 8),
s.Substring(8, 4),
s.Substring(12, 4),
s.Substring(16, 4),
s.Substring(20, 12)
};
_textWriter.Write("HexData({0}, \"{1}\")", (int)subType, string.Join("-", parts));
}
else
{
string uuidConstructorName;
switch (guidRepresentation)
{
case GuidRepresentation.CSharpLegacy: uuidConstructorName = "CSUUID"; break;
case GuidRepresentation.JavaLegacy: uuidConstructorName = "JUUID"; break;
case GuidRepresentation.PythonLegacy: uuidConstructorName = "PYUUID"; break;
case GuidRepresentation.Standard: uuidConstructorName = "UUID"; break;
default: throw new BsonInternalException("Unexpected GuidRepresentation");
}
var guid = GuidConverter.FromBytes(bytes, guidRepresentation);
_textWriter.Write("{0}(\"{1}\")", uuidConstructorName, guid.ToString());
}
}
else
{
_textWriter.Write("new BinData({0}, \"{1}\")", (int)subType, Convert.ToBase64String(bytes));
}
break;
default:
_textWriter.Write("new BinData({0}, \"{1}\")", (int)subType, Convert.ToBase64String(bytes));
break;
}
}
else
{
WriteStartDocument();
WriteString("$binary", Convert.ToBase64String(bytes));
WriteString("$type", ((int)subType).ToString("x2"));
WriteEndDocument();
}
State = GetNextState();
}
示例15: WriteBinaryData
public void WriteBinaryData(
byte[] bytes,
BsonBinarySubType subType,
GuidRepresentation guidRepresentation)
{
var binaryData = new BsonBinaryData(bytes, subType, guidRepresentation);
WriteBinaryData(binaryData);
}