Пример #1
0
        /// <summary>
        /// Main method - serialize document. Uses ByteWriter
        /// </summary>
        public byte[] Serialize(BsonDocument doc)
        {
            var count  = doc.GetBytesCount(true);
            var writer = new ByteWriter(count);

            this.WriteDocument(writer, doc);

            return(writer.Buffer);
        }
Пример #2
0
        /// <summary>
        /// Main method - serialize document. Uses ByteWriter
        /// </summary>
        public byte[] Serialize(BsonDocument doc)
        {
            var count = doc.GetBytesCount(true);
            var writer = new ByteWriter(count);

            this.WriteDocument(writer, doc);

            return writer.Buffer;
        }
Пример #3
0
        /// <summary>
        /// Write a bson document
        /// </summary>
        public void WriteDocument(ByteWriter writer, BsonDocument doc)
        {
            writer.Write(doc.GetBytesCount(false));

            foreach (var key in doc.Keys)
            {
                this.WriteElement(writer, key, doc[key] ?? BsonValue.Null);
            }

            writer.Write((byte)0x00);
        }
Пример #4
0
        /// <summary>
        /// Write a bson document
        /// </summary>
        public void WriteDocument(ByteWriter writer, BsonDocument doc)
        {
            writer.Write(doc.GetBytesCount(false));

            foreach (var key in doc.Keys)
            {
                this.WriteElement(writer, key, doc[key] ?? BsonValue.Null);
            }

            writer.Write((byte)0x00);
        }
Пример #5
0
        /// <summary>
        /// Serialize BsonDocument into a binary array
        /// </summary>
        public static byte[] Serialize(BsonDocument doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            var buffer = new byte[doc.GetBytesCount(true)];

            using (var writer = new BufferWriter(buffer))
            {
                writer.WriteDocument(doc, false);
            }

            return(buffer);
        }