Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extract TypeCode to BinarySubtype.

  • Loading branch information...
commit f1c3511cebe2f3302daf17539fdf4dc18f7178ae 1 parent e457311
@lanwin lanwin authored
View
1  source/MongoDB.Tests/MongoDB.Tests.csproj
@@ -142,6 +142,7 @@
<None Include="Test-Data\tests.charreads.txt" />
<None Include="Test-Data\tests.reads.txt" />
<None Include="Test-Data\tests.smallreads.txt" />
+ <Compile Include="UnitTests\TestMongoRegex.cs" />
<Compile Include="UnitTests\TestOid.cs" />
<Compile Include="UnitTests\TestOidGenerator.cs" />
<Compile Include="UnitTests\Bson\TestBsonWriter.cs" />
View
12 source/MongoDB.Tests/UnitTests/TestBinary.cs
@@ -10,14 +10,14 @@ public class TestBinary
public void CanCreateBinary(){
var binary = new Binary();
Assert.IsNull(binary.Bytes);
- Assert.AreEqual(Binary.TypeCode.Unknown, binary.Subtype);
+ Assert.AreEqual(BinarySubtype.Unknown, binary.Subtype);
}
[Test]
public void CanCreateBinaryFromNull(){
var binary = new Binary(null);
Assert.IsNull(binary.Bytes);
- Assert.AreEqual(Binary.TypeCode.General, binary.Subtype);
+ Assert.AreEqual(BinarySubtype.General, binary.Subtype);
}
[Test]
@@ -25,15 +25,15 @@ public class TestBinary
var bytes = new byte[] { 10 };
var binary = new Binary(bytes);
Assert.AreEqual(bytes,binary.Bytes);
- Assert.AreEqual(Binary.TypeCode.General, binary.Subtype);
+ Assert.AreEqual(BinarySubtype.General, binary.Subtype);
}
[Test]
public void CanCreateBinaryFromBytesAndSubtype(){
var bytes = new byte[] {10};
- var binary = new Binary(bytes,Binary.TypeCode.UserDefined);
+ var binary = new Binary(bytes,BinarySubtype.UserDefined);
Assert.AreEqual(bytes, binary.Bytes);
- Assert.AreEqual(Binary.TypeCode.UserDefined, binary.Subtype);
+ Assert.AreEqual(BinarySubtype.UserDefined, binary.Subtype);
}
[Test]
@@ -55,7 +55,7 @@ public class TestBinary
[Test]
public void CanBeCloned(){
- var binarySource = new Binary(new byte[] {10, 20}, Binary.TypeCode.UserDefined);
+ var binarySource = new Binary(new byte[] {10, 20}, BinarySubtype.UserDefined);
var binaryDest = binarySource.Clone() as Binary;
Assert.IsNotNull(binaryDest);
Assert.AreEqual(binarySource.Bytes,binaryDest.Bytes);
View
2  source/MongoDB.Tests/UnitTests/Util/TestJsonUtils.cs
@@ -134,7 +134,7 @@ public class TestJsonUtils
[Test]
public void TestSerializeDocWithBinary(){
var doc = new Document(){{"b", new Binary(){Bytes = new byte[]{0,1,2,3,4},
- Subtype = Binary.TypeCode.General}}};
+ Subtype = BinarySubtype.General}}};
Assert.AreEqual(@"{ ""b"": { ""$binary"": ""AAECAwQ="", ""$type"" : 2 } }",
JsonFormatter.Serialize(doc));
}
View
25 source/MongoDB/Binary.cs
@@ -9,25 +9,6 @@ namespace MongoDB
public class Binary : IEquatable<Binary>, ICloneable, IEnumerable<byte>
{
/// <summary>
- /// </summary>
- public enum TypeCode : byte
- {
- /// <summary>
- /// </summary>
- Unknown = 0,
- /// <summary>
- /// </summary>
- General = 2,
- // Uuid = 3 is now replaced by Guid
- /// <summary>
- /// </summary>
- Md5 = 5,
- /// <summary>
- /// </summary>
- UserDefined = 80
- }
-
- /// <summary>
/// Initializes a new instance of the <see cref = "Binary" /> class.
/// </summary>
public Binary()
@@ -41,7 +22,7 @@ public Binary()
public Binary(byte[] bytes)
{
Bytes = bytes;
- Subtype = TypeCode.General;
+ Subtype = BinarySubtype.General;
}
/// <summary>
@@ -49,7 +30,7 @@ public Binary(byte[] bytes)
/// </summary>
/// <param name = "bytes">The bytes.</param>
/// <param name = "subtype">The subtype.</param>
- public Binary(byte[] bytes, TypeCode subtype)
+ public Binary(byte[] bytes, BinarySubtype subtype)
{
Bytes = bytes;
Subtype = subtype;
@@ -65,7 +46,7 @@ public Binary(byte[] bytes, TypeCode subtype)
/// Gets or sets the subtype.
/// </summary>
/// <value>The subtype.</value>
- public TypeCode Subtype { get; set; }
+ public BinarySubtype Subtype { get; set; }
/// <summary>
/// Creates a new object that is a copy of the current instance.
View
21 source/MongoDB/BinarySubtype.cs
@@ -0,0 +1,21 @@
+namespace MongoDB
+{
+ /// <summary>
+ /// </summary>
+ public enum BinarySubtype : byte
+ {
+ /// <summary>
+ /// </summary>
+ Unknown = 0,
+ /// <summary>
+ /// </summary>
+ General = 2,
+ // Uuid = 3 is now replaced by Guid
+ /// <summary>
+ /// </summary>
+ Md5 = 5,
+ /// <summary>
+ /// </summary>
+ UserDefined = 80
+ }
+}
View
4 source/MongoDB/Bson/BsonReader.cs
@@ -334,7 +334,7 @@ public BsonReader(Stream stream, BsonReaderSettings settings)
Position += 4;
var subtype = _reader.ReadByte();
Position ++;
- if(subtype == (byte)Binary.TypeCode.General){
+ if(subtype == (byte)BinarySubtype.General){
size = _reader.ReadInt32();
Position += 4;
}
@@ -348,7 +348,7 @@ public BsonReader(Stream stream, BsonReaderSettings settings)
return new Binary{
Bytes = bytes,
- Subtype = (Binary.TypeCode)subtype
+ Subtype = (BinarySubtype)subtype
};
}
View
4 source/MongoDB/Bson/BsonWriter.cs
@@ -143,7 +143,7 @@ private void Write(Oid id)
/// <param name = "binary">The binary.</param>
private void Write(Binary binary)
{
- if(binary.Subtype == Binary.TypeCode.General)
+ if(binary.Subtype == BinarySubtype.General)
{
_writer.Write(binary.Bytes.Length + 4);
_writer.Write((byte)binary.Subtype);
@@ -421,7 +421,7 @@ public int CalculateSize(Binary binary)
{
var size = 4; //size int
size += 1; //subtype
- if(binary.Subtype == Binary.TypeCode.General)
+ if(binary.Subtype == BinarySubtype.General)
size += 4; //embedded size int
size += binary.Bytes.Length;
return size;
Please sign in to comment.
Something went wrong with that request. Please try again.