Skip to content

Commit

Permalink
Use enum for opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngo The Trung authored and Ngo-The-Trung committed Aug 27, 2018
1 parent efd375b commit c73e012
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 66 deletions.
65 changes: 65 additions & 0 deletions mcrouter/lib/mc/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,69 @@ const char* mc_req_err_to_string(const mc_req_err_t err);
*/
const char* mc_res_to_response_string(const mc_res_t result);

typedef enum mc_opcode_e : uint8_t {
mc_opcode_noop = 0x0a,
mc_opcode_set = 0x01,
mc_opcode_setq = 0x11,
mc_opcode_add = 0x02,
mc_opcode_addq = 0x12,
mc_opcode_replace = 0x03,
mc_opcode_replaceq = 0x13,
mc_opcode_append = 0x0e,
mc_opcode_appendq = 0x19,
mc_opcode_prepend = 0x0f,
mc_opcode_prependq = 0x1a,
mc_opcode_get = 0x00,
mc_opcode_getq = 0x09,
mc_opcode_getk = 0x0c,
mc_opcode_getkq = 0x0d,
mc_opcode_delete = 0x04,
mc_opcode_deleteq = 0x14,
mc_opcode_increment = 0x05,
mc_opcode_incrementq = 0x15,
mc_opcode_decrement = 0x06,
mc_opcode_decrementq = 0x16,
mc_opcode_touch = 0x1c,
mc_opcode_gat = 0x1d,
mc_opcode_gatq = 0x1e,
mc_opcode_stat = 0x10,
mc_opcode_version = 0x0b,
mc_opcode_quit = 0x07,
mc_opcode_quitq = 0x17,
mc_opcode_flush = 0x08,
mc_opcode_flushq = 0x18,
// SASL commands
mc_opcode_sasllistmechs = 0x20,
mc_opcode_saslauth = 0x21,
mc_opcode_saslstep = 0x22,
// Range commands
mc_opcode_rset = 0x31,
mc_opcode_rsetq = 0x32,
mc_opcode_rappend = 0x33,
mc_opcode_rappendq = 0x34,
mc_opcode_rprepend = 0x35,
mc_opcode_rprependq = 0x36,
mc_opcode_rget = 0x30,
mc_opcode_rdelete = 0x37,
mc_opcode_rdeleteq = 0x38,
mc_opcode_rincr = 0x39,
mc_opcode_rincrq = 0x3a,
mc_opcode_rdecr = 0x3b,
mc_opcode_rdecrq = 0x3c,
// v1.6 proposed commands
mc_opcode_setvbucket = 0x3d,
mc_opcode_tapvbucketset = 0x45,
mc_opcode_getvbucket = 0x3e,
mc_opcode_tapdelete = 0x42,
mc_opcode_verbosity = 0x1b,
mc_opcode_tapflush = 0x43,
mc_opcode_delvbucket = 0x3f,
mc_opcode_tapconnect = 0x40,
mc_opcode_tapmutation = 0x41,
mc_opcode_tapopaque = 0x44,
mc_opcode_tapcheckpointstart = 0x46,
mc_opcode_tapcheckpointend = 0x47,
} mc_opcode_t;


__END_DECLS
126 changes: 60 additions & 66 deletions mcrouter/lib/network/McBinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,154 +89,148 @@ bool McServerBinaryParser::parseHeader(const char * bytes) {

// TODO validate command constraint (i.e. no extras, no value)
switch (getOpCode()) {
case 0x0a: // No-op
return false;

case 0x01: // Set
case mc_opcode_set:
currentMessage_.emplace<McSetRequest>();
consumer_ = &McServerBinaryParser::consumeSetLike<McSetRequest, false>;
return true;
case 0x11: // SetQ
case mc_opcode_setq:
currentMessage_.emplace<McSetRequest>();
consumer_ = &McServerBinaryParser::consumeSetLike<McSetRequest, true>;
return true;
case 0x02: // Add
case mc_opcode_add:
currentMessage_.emplace<McAddRequest>();
consumer_ = &McServerBinaryParser::consumeSetLike<McAddRequest, false>;
return true;
case 0x12: // AddQ
case mc_opcode_addq
currentMessage_.emplace<McAddRequest>();
consumer_ = &McServerBinaryParser::consumeSetLike<McAddRequest, true>;
return true;
case 0x03: // Replace
case mc_opcode_replace:
currentMessage_.emplace<McReplaceRequest>();
consumer_ = &McServerBinaryParser::consumeSetLike<McReplaceRequest, false>;
return true;
case 0x13: // ReplaceQ
case mc_opcode_replaceq:
currentMessage_.emplace<McReplaceRequest>();
consumer_ = &McServerBinaryParser::consumeSetLike<McReplaceRequest, true>;
return true;
case 0x0e: // Append
case mc_opcode_append:
currentMessage_.emplace<McAppendRequest>();
consumer_ = &McServerBinaryParser::consumeAppendLike<McAppendRequest, false>;
return true;
case 0x19: // AppendQ
case mc_opcode_appendq:
currentMessage_.emplace<McAppendRequest>();
consumer_ = &McServerBinaryParser::consumeAppendLike<McAppendRequest, true>;
return true;
case 0x0f: // Prepend
case mc_opcode_prepend:
currentMessage_.emplace<McPrependRequest>();
consumer_ = &McServerBinaryParser::consumeAppendLike<McPrependRequest, false>;
return true;
case 0x1a: // PrependQ
case mc_opcode_prependq:
currentMessage_.emplace<McPrependRequest>();
consumer_ = &McServerBinaryParser::consumeAppendLike<McPrependRequest, true>;
return true;
case 0x00: // Get
case mc_opcode_get:
currentMessage_.emplace<McGetRequest>();
consumer_ = &McServerBinaryParser::consumeGetLike<McGetRequest, false, false>;
return true;
case 0x09: // GetQ
case mc_opcode_getq:
currentMessage_.emplace<McGetRequest>();
consumer_ = &McServerBinaryParser::consumeGetLike<McGetRequest, true, false>;
return true;
case 0x0c: // GetK
case mc_opcode_getk:
currentMessage_.emplace<McGetRequest>();
consumer_ = &McServerBinaryParser::consumeGetLike<McGetRequest, false, true>;
return true;
case 0x0d: // GetKQ
case mc_opcode_getkq:
currentMessage_.emplace<McGetRequest>();
consumer_ = &McServerBinaryParser::consumeGetLike<McGetRequest, true, true>;
return true;
case 0x04: // Delete
case mc_opcode_delete:
currentMessage_.emplace<McDeleteRequest>();
consumer_ = &McServerBinaryParser::consumeGetLike<McDeleteRequest, false, false>;
return true;
case 0x14: // DeleteQ
case mc_opcode_deleteq:
currentMessage_.emplace<McDeleteRequest>();
consumer_ = &McServerBinaryParser::consumeGetLike<McDeleteRequest, true, false>;
return true;
case 0x05: // Increment
case mc_opcode_increment:
currentMessage_.emplace<McIncrRequest>();
consumer_ = &McServerBinaryParser::consumeArithLike<McIncrRequest, false>;
return true;
case 0x15: // IncrementQ
case mc_opcode_incrementq:
currentMessage_.emplace<McIncrRequest>();
consumer_ = &McServerBinaryParser::consumeArithLike<McIncrRequest, true>;
return true;
case 0x06: // Decrement
case mc_opcode_decrement:
currentMessage_.emplace<McDecrRequest>();
consumer_ = &McServerBinaryParser::consumeArithLike<McDecrRequest, false>;
return true;
case 0x16: // DecrementQ
case mc_opcode_decrementq:
currentMessage_.emplace<McDecrRequest>();
consumer_ = &McServerBinaryParser::consumeArithLike<McDecrRequest, true>;
return true;
case 0x1c: // Touch
case 0x1d: // GAT
case 0x1e: // GATQ
case mc_opcode_touch:
case mc_opcode_gat:
case mc_opcode_gatq:
currentMessage_.emplace<McTouchRequest>();
consumer_ = &McServerBinaryParser::consumeGetLike<McTouchRequest, false, false>;
return true;
case 0x10: // Stat
case mc_opcode_stat:
currentMessage_.emplace<McStatsRequest>();
consumer_ = &McServerBinaryParser::consumeGetLike<McStatsRequest, false, false>;
return true;
case 0x0b: // Version
case mc_opcode_version:
currentMessage_.emplace<McVersionRequest>();
consumer_ = &McServerBinaryParser::consumeVersion;
return true;
case 0x07: // Quit
case mc_opcode_quit:
currentMessage_.emplace<McQuitRequest>();
consumer_ = &McServerBinaryParser::consumeQuit<false>;
return true;
case 0x17: // QuitQ
case mc_opcode_quitq:
currentMessage_.emplace<McQuitRequest>();
consumer_ = &McServerBinaryParser::consumeQuit<true>;
return true;
case 0x08: // Flush
case mc_opcode_flush:
currentMessage_.emplace<McFlushAllRequest>();
consumer_ = &McServerBinaryParser::consumeFlush<false>;
return true;
case 0x18: // FlushQ
case mc_opcode_flushq:
currentMessage_.emplace<McFlushAllRequest>();
consumer_ = &McServerBinaryParser::consumeFlush<true>;
return true;
/*
case 0x20: // SASL list mechs
case 0x21: // SASL Auth
case 0x22: // SASL Step
// Range operations, not implemented in memcached itself
case 0x31: // RSet
case 0x32: // RSetQ
case 0x33: // RAppend
case 0x34: // RAppendQ
case 0x35: // RPrepend
case 0x36: // RPrependQ
case 0x30: // RGet
case 0x37: // RDelete
case 0x38: // RDeleteQ
case 0x39: // RIncr
case 0x3a: // RIncrQ
case 0x3b: // RDecr
case 0x3c: // RDecrQ
case mc_opcode_noop:
// SASL commands
case mc_opcode_sasllistmechs:
case mc_opcode_saslauth:
case mc_opcode_saslstep:
// Range commands
case mc_opcode_rset:
case mc_opcode_rsetq:
case mc_opcode_rappend:
case mc_opcode_rappendq:
case mc_opcode_rprepend:
case mc_opcode_rprependq:
case mc_opcode_rget:
case mc_opcode_rdelete:
case mc_opcode_rdeleteq:
case mc_opcode_rincr:
case mc_opcode_rincrq:
case mc_opcode_rdecr:
case mc_opcode_rdecrq:
// v1.6 proposed commands
case 0x3d: // Set VBucket *
case 0x45: // TAP VBucket Set *
case 0x3e: // Get VBucket *
case 0x42: // TAP Delete *
case 0x1b: // Verbosity *
case 0x43: // TAP Flush *
case 0x3f: // Del VBucket *
case 0x40: // TAP Connect *
case 0x41: // TAP Mutation *
case 0x44: // TAP Opaque *
case 0x46: // TAP Checkpoint Start *
case 0x47: // TAP Checkpoint End *
*/
case mc_opcode_setvbucket:
case mc_opcode_tapvbucketset:
case mc_opcode_getvbucket:
case mc_opcode_tapdelete:
case mc_opcode_verosity:
case mc_opcode_tapflush:
case mc_opcode_delvbucket:
case mc_opcode_tapconnect:
case mc_opcode_tapmutation:
case mc_opcode_tapopaque:
case mc_opcode_tapcheckpointstart:
case mc_opcode_tapcheckpointend::
default:
return false;
}
Expand Down

0 comments on commit c73e012

Please sign in to comment.