Skip to content

Commit

Permalink
[Refactor] Clean up BinprotGenericCommand
Browse files Browse the repository at this point in the history
Change-Id: I30f73ec2939721f03abd8b93785b90889486bc74
Reviewed-on: https://review.couchbase.org/c/kv_engine/+/174775
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Jim Walker <jim@couchbase.com>
  • Loading branch information
trondn committed May 16, 2022
1 parent 7153591 commit c383154
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
23 changes: 4 additions & 19 deletions protocol/connection/client_mcbp_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,12 @@ void BinprotGenericCommand::encode(std::vector<uint8_t>& buf) const {
}

BinprotGenericCommand::BinprotGenericCommand(cb::mcbp::ClientOpcode opcode,
const std::string& key_,
const std::string& value_)
std::string key_,
std::string value_)
: BinprotCommandT() {
setOp(opcode);
setKey(key_);
setValue(value_);
}

BinprotGenericCommand::BinprotGenericCommand(cb::mcbp::ClientOpcode opcode,
const std::string& key_)
: BinprotCommandT() {
setOp(opcode);
setKey(key_);
}

BinprotGenericCommand::BinprotGenericCommand(cb::mcbp::ClientOpcode opcode)
: BinprotCommandT() {
setOp(opcode);
}

BinprotGenericCommand::BinprotGenericCommand() : BinprotCommandT() {
setKey(std::move(key_));
setValue(std::move(value_));
}

BinprotGenericCommand& BinprotGenericCommand::setValue(std::string value_) {
Expand Down
21 changes: 13 additions & 8 deletions protocol/connection/client_mcbp_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,28 @@ class BinprotCommandT : public BinprotCommand {
*/
class BinprotGenericCommand : public BinprotCommandT<BinprotGenericCommand> {
public:
BinprotGenericCommand() : BinprotCommandT() {
}
explicit BinprotGenericCommand(cb::mcbp::ClientOpcode opcode)
: BinprotGenericCommand(opcode, {}) {
}
BinprotGenericCommand(cb::mcbp::ClientOpcode opcode, std::string key_)
: BinprotGenericCommand(opcode, std::move(key_), {}) {
}
BinprotGenericCommand(cb::mcbp::ClientOpcode opcode,
const std::string& key_,
const std::string& value_);
BinprotGenericCommand(cb::mcbp::ClientOpcode opcode,
const std::string& key_);
explicit BinprotGenericCommand(cb::mcbp::ClientOpcode opcode);
BinprotGenericCommand();
std::string key_,
std::string value_);

BinprotGenericCommand& setValue(std::string value_);
BinprotGenericCommand& setExtras(const std::vector<uint8_t>& buf);
BinprotGenericCommand& setExtras(std::string_view buf);

// Use for setting a simple value as an extras
template <typename T>
BinprotGenericCommand& setExtrasValue(T value) {
BinprotGenericCommand& setExtrasValue(T ext) {
std::vector<uint8_t> buf;
buf.resize(sizeof(T));
memcpy(buf.data(), &value, sizeof(T));
memcpy(buf.data(), &ext, sizeof(T));
return setExtras(buf);
}

Expand Down

0 comments on commit c383154

Please sign in to comment.