protected override void WriteBody(BsonWriter writer) { writer.WriteValue(BsonDataType.Integer,0); writer.WriteString(this.FullCollectionName); writer.WriteValue(BsonDataType.Integer,this.Flags); writer.Write(Selector); writer.Write(Document); }
protected override void WriteBody(Stream stream) { BsonWriter writer = new BsonWriter(stream); writer.Write((int)0); writer.Write(this.FullCollectionName); writer.Write((int)0); selector.Write(writer); }
protected override void WriteBody(Stream stream) { BsonWriter writer = new BsonWriter(stream); writer.Write((int)0); writer.Write(this.FullCollectionName); foreach(BsonDocument bdoc in this.BsonDocuments){ bdoc.Write(writer); } }
protected override void WriteBody(Stream stream) { BsonWriter writer = new BsonWriter(stream); writer.Write(0); writer.Write(this.FullCollectionName); writer.Write(this.NumberToReturn); writer.Write(this.cursorID); writer.Flush(); }
protected override void WriteBody(Stream stream) { BsonWriter writer = new BsonWriter(stream); writer.Write(0); writer.Write(this.CursorIDs.Length); foreach(long id in this.CursorIDs){ writer.Write(id); } writer.Flush(); }
public void TestReadBigDocument() { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); Document expected = new Document(); expected.Append("str", "test") .Append("int", 45) .Append("long", (long)46) .Append("num", 4.5) .Append("date",DateTime.Today) .Append("_id", new OidGenerator().Generate()) .Append("code", new Code("return 1;")) .Append("subdoc", new Document().Append("a",1).Append("b",2)) .Append("array", new String[]{"a","b","c","d"}) .Append("codewscope", new CodeWScope("return 2;", new Document().Append("c",1))) .Append("binary", new Binary(new byte[]{0,1,2,3})) .Append("regex", new MongoRegex("[A-Z]")) .Append("minkey", MongoMinKey.Value) .Append("maxkey", MongoMaxKey.Value) ; writer.Write(expected); writer.Flush(); ms.Seek(0,SeekOrigin.Begin); BsonReader reader = new BsonReader(ms); Document doc = reader.Read(); Assert.IsNotNull(doc); }
public void TestReadBigDocument() { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); Document expected = new Document(); expected.Append("str", "test") .Append("int", 45) .Append("long", (long)46) .Append("num", 4.5) .Append("date", DateTime.Today) .Append("_id", new OidGenerator().Generate()) .Append("code", new Code("return 1;")) .Append("subdoc", new Document().Append("a", 1).Append("b", 2)) .Append("array", new String[] { "a", "b", "c", "d" }) .Append("codewscope", new CodeWScope("return 2;", new Document().Append("c", 1))) .Append("binary", new Binary(new byte[] { 0, 1, 2, 3 })) .Append("regex", new MongoRegex("[A-Z]")) .Append("minkey", MongoMinKey.Value) .Append("maxkey", MongoMaxKey.Value) ; writer.Write(expected); writer.Flush(); ms.Seek(0, SeekOrigin.Begin); BsonReader reader = new BsonReader(ms); Document doc = reader.Read(); Assert.IsNotNull(doc); }
private String ConvertDocToHex(Document doc) { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); writer.Write(doc); return(BitConverter.ToString(ms.ToArray()).Replace("-", "")); }
public void TestNullsDontThrowExceptionsExceptions() { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); Document doc = new Document().Append("n", null); try{ writer.Write(doc); }catch (NullReferenceException) { Assert.Fail("Null Reference Exception was thrown on trying to serialize a null value"); } }
protected Document WriteAndRead(Document source) { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); writer.Write(source); writer.Flush(); ms.Seek(0, SeekOrigin.Begin); BsonReader reader = new BsonReader(ms); return(reader.Read()); }
public void TestWriteDocument() { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); string expected = "1400000002746573740005000000746573740000"; Document doc = new Document().Append("test", "test"); writer.Write(doc); string hexdump = BitConverter.ToString(ms.ToArray()); hexdump = hexdump.Replace("-", ""); Assert.AreEqual(expected, hexdump); }
public void TestRoundTrip() { Document idoc = new Document(); idoc.Add("b", new Binary(new byte[] { (byte)1, (byte)2 })); MemoryStream stream = new MemoryStream(); BsonWriter writer = new BsonWriter(stream); writer.Write(idoc); stream.Seek(0, SeekOrigin.Begin); BsonReader reader = new BsonReader(stream); Document odoc = reader.Read(); Assert.AreEqual(idoc.ToString(), odoc.ToString()); }
public void TestDateUTC() { DateTime now = DateTime.UtcNow; MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); Document source = new Document(); source.Append("d",now); writer.Write(source); writer.Flush(); ms.Seek(0,SeekOrigin.Begin); BsonReader reader = new BsonReader(ms); Document copy = reader.Read(); DateTime then = (DateTime)copy["d"]; Assert.AreEqual(now.Hour,then.Hour, "Date did not round trip right."); }
public void TestBinaryRead() { string hex = "28000000075f6964004b1971811d8b0f00c0000000056461746100070000000203000000e188b400"; byte[] data = DecodeHex(hex); MemoryStream inmem = new MemoryStream(data); BsonReader inreader = new BsonReader(inmem); Document indoc = new Document(); indoc = inreader.Read(); MemoryStream outmem = new MemoryStream(); BsonWriter outwriter = new BsonWriter(outmem); outwriter.Write(indoc); byte[] outdata = outmem.ToArray(); String outhex = BitConverter.ToString(outdata); outhex = outhex.Replace("-", ""); Assert.AreEqual(hex, outhex.ToLower()); }
public void TestDBRef() { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); Document source = new Document(); source.Append("x",1).Append("ref",new DBRef("refs","ref1")); writer.Write(source); writer.Flush(); ms.Seek(0,SeekOrigin.Begin); BsonReader reader = new BsonReader(ms); Document copy = reader.Read(); Assert.IsTrue(copy.Contains("ref")); Assert.IsTrue(copy["ref"].GetType() == typeof(DBRef)); DBRef sref = (DBRef)source["ref"]; DBRef cref = (DBRef)copy["ref"]; Assert.AreEqual(sref.Id, cref.Id); }
public void TestWrite() { MemoryStream ms = new MemoryStream(); InsertMessage im = new InsertMessage(); im.FullCollectionName ="Tests.inserts"; Document doc = new Document(); Document[] docs = new Document[]{doc}; doc.Append("a","a"); doc.Append("b",1); im.Documents = docs; Assert.AreEqual(16,im.Header.MessageLength); BsonWriter2 bwriter = new BsonWriter2(ms); Assert.AreEqual(21,bwriter.CalculateSize(doc)); im.Write(ms); Byte[] bytes = ms.ToArray(); String hexdump = BitConverter.ToString(bytes); System.Console.WriteLine(hexdump); MemoryStream ms2 = new MemoryStream(); BsonWriter b = new BsonWriter(ms2); b.Write(im.Header.MessageLength); b.Write(im.Header.RequestId); b.Write(im.Header.ResponseTo); b.Write((int)im.Header.OpCode); b.Write((int)0); b.Write(im.FullCollectionName); BsonDocument bdoc = BsonConvert.From(doc); bdoc.Write(b); b.Flush(); String hexdump2 = BitConverter.ToString(ms2.ToArray()); System.Console.WriteLine(hexdump2); Assert.AreEqual(hexdump2,hexdump); Assert.AreEqual(bytes.Length,im.Header.MessageLength); }
/// <summary> /// Writes out a header and the chunk of documents. /// </summary> /// <param name="stream"></param> /// <param name="chunk"></param> protected void WriteChunk(Stream stream, MessageChunk chunk) { WriteHeader(new BinaryWriter(stream), chunk.Size); BsonWriter writer = new BsonWriter(stream); writer.WriteValue(BsonDataType.Integer,0); writer.WriteString(this.FullCollectionName); foreach(Document doc in chunk.Documents){ writer.Write(doc); } writer.Flush(); }
protected override void WriteBody(Stream stream) { BsonWriter writer = new BsonWriter(stream); writer.Write(this.Message); }
public void Write(BsonWriter writer) { writer.Write(this.Val.Length); writer.Write(this.Subtype); writer.Write(this.Val); }
protected Document WriteAndRead(Document source) { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); writer.Write(source); writer.Flush(); ms.Seek(0, SeekOrigin.Begin); BsonReader reader = new BsonReader(ms); return reader.Read(); }
public void Write(BsonWriter writer) { writer.Write(this.Val.Length + 1); writer.Write(this.Val); }
public void Write(BsonWriter writer) { writer.Write(this.Val.TypeNum); writer.Write(this.Name); this.Val.Write(writer); }
public void Write(BsonWriter writer) { writer.Write(this.Expression); writer.Write(this.Options); }
protected override void WriteBody(BsonWriter writer) { writer.WriteValue(BsonDataType.Integer,(int)this.Options); writer.WriteString(this.FullCollectionName); writer.WriteValue(BsonDataType.Integer,(int)this.NumberToSkip); writer.WriteValue(BsonDataType.Integer,(int)this.NumberToReturn); writer.Write(this.Query); if(this.ReturnFieldSelector != null){ writer.Write(this.ReturnFieldSelector); } }
protected override void WriteBody(Stream stream) { BsonWriter writer = new BsonWriter(stream); //TODO Implement Query Options (defaulting to none. writer.Write(0); writer.Write(this.FullCollectionName); writer.Write(this.numberToSkip); writer.Write(this.NumberToReturn); this.Query.Write(writer); if(this.ReturnFieldSelector != null) this.ReturnFieldSelector.Write(writer); writer.Flush(); }
private String ConvertDocToHex(Document doc) { MemoryStream ms = new MemoryStream(); BsonWriter writer = new BsonWriter(ms); writer.Write(doc); return BitConverter.ToString(ms.ToArray()).Replace("-",""); }
public void Write(BsonWriter writer) { writer.Write(this.Val); }
public void Write(BsonWriter writer) { //TODO Calling GetByteCount may be expensive. Possibly just do the same work write(String) does. writer.Write(encoding.GetByteCount(this.val) + 1); writer.Write(this.Val); }
public void Write(BsonWriter writer) { writer.Write(this.Size); //object size writer.Write(this.Val.Length + 1); //code size writer.Write(this.Val); this.Scope.Write(writer); }