本文整理汇总了C#中BsonBinarySubType类的典型用法代码示例。如果您正苦于以下问题:C# BsonBinarySubType类的具体用法?C# BsonBinarySubType怎么用?C# BsonBinarySubType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonBinarySubType类属于命名空间,在下文中一共展示了BsonBinarySubType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:swiggin1,项目名称:mongo-csharp-driver,代码行数:26,代码来源:BsonBinaryReader.cs
示例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);
}
开发者ID:dalinhuang,项目名称:tdcodes,代码行数:12,代码来源:BsonBaseWriter.cs
示例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);
}
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:14,代码来源:BsonBaseWriter.cs
示例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;
}
开发者ID:dmitrikas,项目名称:mongo-csharp-driver,代码行数:16,代码来源:JsonReader.cs
示例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;
}
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:19,代码来源:JsonReader.cs
示例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();
}
开发者ID:jenrom,项目名称:mongo-csharp-driver,代码行数:14,代码来源:BsonDocumentWriter.cs
示例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();
}
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:22,代码来源:JsonWriter.cs
示例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();
}
开发者ID:simi--,项目名称:mongo-csharp-driver,代码行数:28,代码来源:JsonWriter.cs
示例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();
}
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:27,代码来源:JsonWriter.cs
示例11: ReadBinaryData
public abstract void ReadBinaryData(
string name,
out byte[] bytes,
out BsonBinarySubType subType
);
开发者ID:kolupaev,项目名称:mongo-csharp-driver,代码行数:5,代码来源:BsonReader.cs
示例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
);
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:11,代码来源:BsonWriter.cs
示例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);
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonWriter.cs
示例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();
}
开发者ID:abel,项目名称:sinan,代码行数:88,代码来源:JsonWriter.cs
示例15: WriteBinaryData
public void WriteBinaryData(
byte[] bytes,
BsonBinarySubType subType,
GuidRepresentation guidRepresentation)
{
var binaryData = new BsonBinaryData(bytes, subType, guidRepresentation);
WriteBinaryData(binaryData);
}
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:8,代码来源:BsonWriter.cs
示例16: 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("BsonDocumentWriter"); }
if (_state != BsonWriterState.Value)
{
ThrowInvalidState("WriteBinaryData", BsonWriterState.Value);
}
WriteValue(new BsonBinaryData(bytes, subType, guidRepresentation));
_state = GetNextState();
}
开发者ID:moonreplace,项目名称:mongo-csharp-driver,代码行数:17,代码来源:BsonDocumentWriter.cs
示例17: GuidToString
private string GuidToString(BsonBinarySubType subType, byte[] bytes, GuidRepresentation guidRepresentation)
{
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 (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)
};
return string.Format("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);
return string.Format("{0}(\"{1}\")", uuidConstructorName, guid.ToString());
}
}
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:45,代码来源:JsonWriter.cs
示例18: WriteBinaryData
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
/// <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("BsonBinaryWriter"); }
if (state != BsonWriterState.Value) {
var message = string.Format("WriteBinaryData cannot be called when State is: {0}", state);
throw new InvalidOperationException(message);
}
buffer.WriteByte((byte) BsonType.Binary);
WriteNameHelper();
if (subType == BsonBinarySubType.OldBinary && settings.FixOldBinarySubTypeOnOutput) {
subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
}
if (subType == BsonBinarySubType.OldBinary) {
// sub type OldBinary has two sizes (for historical reasons)
buffer.WriteInt32(bytes.Length + 4);
buffer.WriteByte((byte) subType);
buffer.WriteInt32(bytes.Length);
} else {
buffer.WriteInt32(bytes.Length);
buffer.WriteByte((byte) subType);
}
buffer.WriteBytes(bytes);
state = GetNextState();
}
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:34,代码来源:BsonBinaryWriter.cs
示例19: TestBinaryData
public void TestBinaryData(string json, byte[] expectedBytes, BsonBinarySubType expectedSubType)
{
using (var reader = new JsonReader(json))
{
var result = reader.ReadBinaryData();
result.Should().Be(new BsonBinaryData(expectedBytes, expectedSubType));
reader.IsAtEndOfFile().Should().BeTrue();
}
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:10,代码来源:JsonReaderTests.cs
示例20: ReadBinaryData
/// <summary>
/// Reads a BSON binary data element from the reader.
/// </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 ReadBinaryData(
string name,
out byte[] bytes,
out BsonBinarySubType subType
) {
VerifyName(name);
ReadBinaryData(out bytes, out subType);
}
开发者ID:emiaj,项目名称:mongo-csharp-driver,代码行数:14,代码来源:BsonBaseReader.cs
注:本文中的BsonBinarySubType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论