summaryrefslogtreecommitdiff
path: root/src/mongo/rpc/reply_builder_interface.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/rpc/reply_builder_interface.h')
-rw-r--r--src/mongo/rpc/reply_builder_interface.h193
1 files changed, 94 insertions, 99 deletions
diff --git a/src/mongo/rpc/reply_builder_interface.h b/src/mongo/rpc/reply_builder_interface.h
index 7a36ab8b622..e97e3e7fe9b 100644
--- a/src/mongo/rpc/reply_builder_interface.h
+++ b/src/mongo/rpc/reply_builder_interface.h
@@ -35,110 +35,105 @@
#include "mongo/rpc/protocol.h"
namespace mongo {
- class BSONObj;
- class Message;
+class BSONObj;
+class Message;
namespace rpc {
- class DocumentRange;
+class DocumentRange;
+
+/**
+ * Constructs an RPC Reply.
+ */
+class ReplyBuilderInterface {
+ MONGO_DISALLOW_COPYING(ReplyBuilderInterface);
+
+public:
+ /**
+ * Reply builders must have their fields set in order as they are immediately written into
+ * the underlying message buffer. This enum represents the next field that can be written
+ * into the builder. Note that when the builder is in state 'kInputDocs', multiple input
+ * docs can be added. After the builder's done() method is called it is in state 'kDone',
+ * and no further methods can be called.
+ */
+ enum class State { kMetadata, kCommandReply, kOutputDocs, kDone };
+
+ virtual ~ReplyBuilderInterface() = default;
+
+ virtual ReplyBuilderInterface& setMetadata(BSONObj metadata) = 0;
+
+ /**
+ * Sets the raw command reply. This should probably not be used in favor of the
+ * variants that accept a Status or StatusWith.
+ */
+ virtual ReplyBuilderInterface& setRawCommandReply(BSONObj reply) = 0;
+
+ /**
+ * Sets the reply for this command. If an engaged StatusWith<BSONObj> is passed, the command
+ * reply will be set to the contained BSONObj, augmented with the element {ok, 1.0} if it
+ * does not already have an "ok" field. If a disengaged StatusWith<BSONObj> is passed, the
+ * command reply will be set to {ok: 0.0, code: <code of status>,
+ * errmsg: <reason of status>}
+ */
+ ReplyBuilderInterface& setCommandReply(StatusWith<BSONObj> commandReply);
+
+ /**
+ * Sets the reply for this command. The status parameter must be non-OK. The reply for
+ * this command will be set to an object containing all the fields in extraErrorInfo,
+ * augmented with {ok: 0.0} , {code: <code of status>}, and {errmsg: <reason of status>}.
+ * If any of the fields "ok", "code", or "errmsg" already exist in extraErrorInfo, they
+ * will be left as-is in the command reply. This use of this form is intended for
+ * interfacing with legacy code that adds additional data to a failed command reply and
+ * its use is discouraged in new code.
+ */
+ ReplyBuilderInterface& setCommandReply(Status nonOKStatus, BSONObj extraErrorInfo);
+
+ /**
+ * Add a range of output documents to the reply. This method can be called multiple times
+ * before calling done().
+ */
+ virtual ReplyBuilderInterface& addOutputDocs(DocumentRange outputDocs) = 0;
+
+ /**
+ * Add a single output document to the reply. This method can be called multiple times
+ * before calling done().
+ */
+ virtual ReplyBuilderInterface& addOutputDoc(BSONObj outputDoc) = 0;
+
+ /**
+ * Gets the state of the builder. As the builder will simply crash the process if it is ever
+ * put in an invalid state, it isn't neccessary to call this method for correctness. Rather
+ * it may be helpful to explicitly assert that the builder is in a certain state to make
+ * code that manipulates the builder more readable.
+ */
+ virtual State getState() const = 0;
+
+ /**
+ * Gets the protocol used to serialize this reply. This should be used for validity checks
+ * only - runtime behavior changes should be implemented with polymorphism.
+ */
+ virtual Protocol getProtocol() const = 0;
+
+ /**
+ * Resets the state of the builder to kMetadata and clears any data that was previously
+ * written.
+ */
+ virtual void reset() = 0;
/**
- * Constructs an RPC Reply.
+ * Returns available space in bytes, should be used to verify that the message have enough
+ * space for ouput documents.
*/
- class ReplyBuilderInterface {
- MONGO_DISALLOW_COPYING(ReplyBuilderInterface);
- public:
-
- /**
- * Reply builders must have their fields set in order as they are immediately written into
- * the underlying message buffer. This enum represents the next field that can be written
- * into the builder. Note that when the builder is in state 'kInputDocs', multiple input
- * docs can be added. After the builder's done() method is called it is in state 'kDone',
- * and no further methods can be called.
- */
- enum class State {
- kMetadata,
- kCommandReply,
- kOutputDocs,
- kDone
- };
-
- virtual ~ReplyBuilderInterface() = default;
-
- virtual ReplyBuilderInterface& setMetadata(BSONObj metadata) = 0;
-
- /**
- * Sets the raw command reply. This should probably not be used in favor of the
- * variants that accept a Status or StatusWith.
- */
- virtual ReplyBuilderInterface& setRawCommandReply(BSONObj reply) = 0;
-
- /**
- * Sets the reply for this command. If an engaged StatusWith<BSONObj> is passed, the command
- * reply will be set to the contained BSONObj, augmented with the element {ok, 1.0} if it
- * does not already have an "ok" field. If a disengaged StatusWith<BSONObj> is passed, the
- * command reply will be set to {ok: 0.0, code: <code of status>,
- * errmsg: <reason of status>}
- */
- ReplyBuilderInterface& setCommandReply(StatusWith<BSONObj> commandReply);
-
- /**
- * Sets the reply for this command. The status parameter must be non-OK. The reply for
- * this command will be set to an object containing all the fields in extraErrorInfo,
- * augmented with {ok: 0.0} , {code: <code of status>}, and {errmsg: <reason of status>}.
- * If any of the fields "ok", "code", or "errmsg" already exist in extraErrorInfo, they
- * will be left as-is in the command reply. This use of this form is intended for
- * interfacing with legacy code that adds additional data to a failed command reply and
- * its use is discouraged in new code.
- */
- ReplyBuilderInterface& setCommandReply(Status nonOKStatus, BSONObj extraErrorInfo);
-
- /**
- * Add a range of output documents to the reply. This method can be called multiple times
- * before calling done().
- */
- virtual ReplyBuilderInterface& addOutputDocs(DocumentRange outputDocs) = 0;
-
- /**
- * Add a single output document to the reply. This method can be called multiple times
- * before calling done().
- */
- virtual ReplyBuilderInterface& addOutputDoc(BSONObj outputDoc) = 0;
-
- /**
- * Gets the state of the builder. As the builder will simply crash the process if it is ever
- * put in an invalid state, it isn't neccessary to call this method for correctness. Rather
- * it may be helpful to explicitly assert that the builder is in a certain state to make
- * code that manipulates the builder more readable.
- */
- virtual State getState() const = 0;
-
- /**
- * Gets the protocol used to serialize this reply. This should be used for validity checks
- * only - runtime behavior changes should be implemented with polymorphism.
- */
- virtual Protocol getProtocol() const = 0;
-
- /**
- * Resets the state of the builder to kMetadata and clears any data that was previously
- * written.
- */
- virtual void reset() = 0;
-
- /**
- * Returns available space in bytes, should be used to verify that the message have enough
- * space for ouput documents.
- */
- virtual std::size_t availableSpaceForOutputDocs() const = 0;
-
- /**
- * Writes data then transfers ownership of the message to the caller. The behavior of
- * calling any methods on the builder is subsequently undefined.
- */
- virtual std::unique_ptr<Message> done() = 0;
-
- protected:
- ReplyBuilderInterface() = default;
- };
+ virtual std::size_t availableSpaceForOutputDocs() const = 0;
+
+ /**
+ * Writes data then transfers ownership of the message to the caller. The behavior of
+ * calling any methods on the builder is subsequently undefined.
+ */
+ virtual std::unique_ptr<Message> done() = 0;
+
+protected:
+ ReplyBuilderInterface() = default;
+};
} // namespace rpc
} // namespace mongo