public void TestReadStringValue() { byte[] buf = HexToBytes("050000007465737400"); MemoryStream ms = new MemoryStream(buf); BsonReader reader = new BsonReader(ms); String str = reader.ReadLenString(); Assert.AreEqual(buf.Length, reader.Position); Assert.AreEqual("test", (String)str); }
private string WriteAndReadLenString(string val) { MemoryStream ms = new MemoryStream(); BsonWriter bs = new BsonWriter(ms); BinaryWriter w = new BinaryWriter(ms); int byteCount = bs.CalculateSize(val,false); w.Write(byteCount); bs.WriteString(val); ms.Seek(0,SeekOrigin.Begin); BsonReader reader = new BsonReader(ms); return reader.ReadLenString(); }