public override void WriteRawBsonDocument(IByteBuffer slice)
{
if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (State != BsonWriterState.Initial && State != BsonWriterState.Value && State != BsonWriterState.ScopeDocument && State != BsonWriterState.Done)
{
ThrowInvalidState("WriteRawBsonDocument", BsonWriterState.Initial, BsonWriterState.Value, BsonWriterState.ScopeDocument, BsonWriterState.Done);
}
if (State == BsonWriterState.Value)
{
_buffer.WriteByte((byte)BsonType.Document);
WriteNameHelper();
}
_buffer.ByteBuffer.WriteBytes(slice); // assumes byteBuffer is a valid raw BSON document
if (_context == null)
{
State = BsonWriterState.Done;
}
else
{
if (_context.ContextType == ContextType.JavaScriptWithScope)
{
BackpatchSize(); // size of the JavaScript with scope value
_context = _context.ParentContext;
}
State = GetNextState();
}
}