Esempio n. 1
0
        public void WriteEndOnProperty_Close()
        {
            MemoryStream   ms     = new MemoryStream();
            BsonDataWriter writer = new BsonDataWriter(ms);

            writer.WriteStartObject();
            writer.WritePropertyName("Blah");
            writer.Close();

            Assert.AreEqual("0B-00-00-00-0A-42-6C-61-68-00-00", (BitConverter.ToString(ms.ToArray())));
        }
Esempio n. 2
0
 private static byte[] SerializeObject(object data)
 {
     using (var bw = new MemoryStream())
     {
         var writer     = new BsonDataWriter(bw);
         var serializer = new JsonSerializer();
         serializer.TypeNameHandling = TypeNameHandling.Objects;
         serializer.Serialize(writer, data);
         writer.Close();
         bw.TryGetBuffer(out var result);
         return(result.Array);
     }
 }
Esempio n. 3
0
        private byte[] PackBosn(byte[] bs)
        {
            ShareData shareData = new ShareData
            {
                Type    = "Image",
                ImgData = bs
            };
            MemoryStream   ms             = new MemoryStream();
            BsonDataWriter bsonDataWriter = new BsonDataWriter(ms);
            JsonSerializer jsonSerializer = new JsonSerializer();

            jsonSerializer.Serialize(bsonDataWriter, shareData);
            byte[] res = ms.ToArray();
            bsonDataWriter.Close();
            return(res);
        }
Esempio n. 4
0
        public void CloseOutput()
        {
            MemoryStream   ms     = new MemoryStream();
            BsonDataWriter writer = new BsonDataWriter(ms);

            Assert.IsTrue(ms.CanRead);
            writer.Close();
            Assert.IsFalse(ms.CanRead);

            ms     = new MemoryStream();
            writer = new BsonDataWriter(ms)
            {
                CloseOutput = false
            };

            Assert.IsTrue(ms.CanRead);
            writer.Close();
            Assert.IsTrue(ms.CanRead);
        }