MongoDB.Bson.IO.BsonBinaryWriter.WriteBytes C# (CSharp) Method

WriteBytes() public method

Writes BSON binary data to the writer.
public WriteBytes ( byte bytes ) : void
bytes byte The bytes.
return void
        public override void WriteBytes(byte[] bytes)
        {
            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
            if (State != BsonWriterState.Value)
            {
                ThrowInvalidState("WriteBytes", BsonWriterState.Value);
            }

            _buffer.WriteByte((byte)BsonType.Binary);
            WriteNameHelper();
            _buffer.WriteInt32(bytes.Length);
            _buffer.WriteByte((byte)BsonBinarySubType.Binary);
            _buffer.WriteBytes(bytes);

            State = GetNextState();
        }

Usage Example

Exemplo n.º 1
0
 public void Test1ChunkPlus1()
 {
     var stream = new MemoryStream();
     using (var bsonWriter = new BsonBinaryWriter(stream))
     {
         bsonWriter.WriteStartDocument();
         bsonWriter.WriteBytes("Data", new byte[16 * 1024 - 15]);
         bsonWriter.WriteEndDocument();
         bsonWriter.Close();
     }
 }