The Issue
Currently replies to the find and getMore commands and queries in mongod and mongos explicitly construct the respond message. This gives flexibility in enforcing size restrictions and managing memory but is error prone, not flexible and can not support multiple output formats required for different wired versions.
The Goal
- Provide a uniform approach to constructing all messages that are sent out
as an OP_REPLY or OP_COMMANDREPLY.
- Implement run time transformation of the message to any version of the output wired protocol.
Proposed Implementation
Refactor existing ReplyBuilderInterface and derived classes.
Add a new class
template <class SizePolicy>
|
class ReplyMessage: private SizePolicy {
|
that will be used to construct a message. Its a policy host that can be customized with different policy for size checks, initial buffer size, and
other properties known at the compile time.
Refactor ReplyBuilderInterface for building the reply of the desired type from ReplyMessage.
The intended usage is
// build a message
|
ReplyMessage<SizeCheckingPolicy> reply;
|
...
|
reply.addOutputDocument(doc);
|
...
|
auto builder = rpc::makeReplyBuilder(protocol);
|
auto message = builder->build(reply);
|
|