本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.Bson.BsonReader.ReadAsBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BsonReader.ReadAsBytes方法的具体用法?C# BsonReader.ReadAsBytes怎么用?C# BsonReader.ReadAsBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Imports.Newtonsoft.Json.Bson.BsonReader
的用法示例。
在下文中一共展示了BsonReader.ReadAsBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadBytes
public void ReadBytes()
{
byte[] data = HexToBytes("2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-02-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc);
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
Assert.AreEqual(true, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("a", reader.Value);
Assert.AreEqual(typeof(string), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("b", reader.Value);
Assert.AreEqual(typeof(string), reader.ValueType);
byte[] encodedStringData = reader.ReadAsBytes();
Assert.IsNotNull(encodedStringData);
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(encodedStringData, reader.Value);
Assert.AreEqual(typeof(byte[]), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsFalse(reader.Read());
Assert.AreEqual(JsonToken.None, reader.TokenType);
string decodedString = Encoding.UTF8.GetString(encodedStringData, 0, encodedStringData.Length);
Assert.AreEqual("Hello world!", decodedString);
}
示例2: GuidsShouldBeProperlyDeserialised_AsBytes_ReadAhead
public void GuidsShouldBeProperlyDeserialised_AsBytes_ReadAhead()
{
Guid g = new Guid("822C0CE6-CC42-4753-A3C3-26F0684A4B88");
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartObject();
writer.WritePropertyName("TheGuid");
writer.WriteValue(g);
writer.WriteEndObject();
writer.Flush();
byte[] bytes = ms.ToArray();
BsonReader reader = new BsonReader(new MemoryStream(bytes));
Assert.IsTrue(reader.Read());
Assert.IsTrue(reader.Read());
CollectionAssert.AreEquivalent(g.ToByteArray(), reader.ReadAsBytes());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(typeof(byte[]), reader.ValueType);
CollectionAssert.AreEquivalent(g.ToByteArray(), (byte[])reader.Value);
Assert.IsTrue(reader.Read());
Assert.IsFalse(reader.Read());
JsonSerializer serializer = new JsonSerializer();
serializer.MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead;
BytesTestClass b = serializer.Deserialize<BytesTestClass>(new BsonReader(new MemoryStream(bytes)));
CollectionAssert.AreEquivalent(g.ToByteArray(), b.TheGuid);
}