From c73e0121fb491491138562ef79ff5a6d08d667a1 Mon Sep 17 00:00:00 2001 From: Ngo The Trung Date: Sun, 27 Aug 2017 05:59:52 +0000 Subject: [PATCH] Use enum for opcode --- mcrouter/lib/mc/msg.h | 65 ++++++++++++ mcrouter/lib/network/McBinaryParser.cpp | 126 +++++++++++------------- 2 files changed, 125 insertions(+), 66 deletions(-) diff --git a/mcrouter/lib/mc/msg.h b/mcrouter/lib/mc/msg.h index 8ce6e1e6e..73bcdbbb7 100644 --- a/mcrouter/lib/mc/msg.h +++ b/mcrouter/lib/mc/msg.h @@ -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 diff --git a/mcrouter/lib/network/McBinaryParser.cpp b/mcrouter/lib/network/McBinaryParser.cpp index ec2013b54..2644a3b51 100644 --- a/mcrouter/lib/network/McBinaryParser.cpp +++ b/mcrouter/lib/network/McBinaryParser.cpp @@ -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(); consumer_ = &McServerBinaryParser::consumeSetLike; return true; - case 0x11: // SetQ + case mc_opcode_setq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeSetLike; return true; - case 0x02: // Add + case mc_opcode_add: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeSetLike; return true; - case 0x12: // AddQ + case mc_opcode_addq currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeSetLike; return true; - case 0x03: // Replace + case mc_opcode_replace: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeSetLike; return true; - case 0x13: // ReplaceQ + case mc_opcode_replaceq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeSetLike; return true; - case 0x0e: // Append + case mc_opcode_append: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeAppendLike; return true; - case 0x19: // AppendQ + case mc_opcode_appendq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeAppendLike; return true; - case 0x0f: // Prepend + case mc_opcode_prepend: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeAppendLike; return true; - case 0x1a: // PrependQ + case mc_opcode_prependq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeAppendLike; return true; - case 0x00: // Get + case mc_opcode_get: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeGetLike; return true; - case 0x09: // GetQ + case mc_opcode_getq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeGetLike; return true; - case 0x0c: // GetK + case mc_opcode_getk: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeGetLike; return true; - case 0x0d: // GetKQ + case mc_opcode_getkq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeGetLike; return true; - case 0x04: // Delete + case mc_opcode_delete: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeGetLike; return true; - case 0x14: // DeleteQ + case mc_opcode_deleteq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeGetLike; return true; - case 0x05: // Increment + case mc_opcode_increment: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeArithLike; return true; - case 0x15: // IncrementQ + case mc_opcode_incrementq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeArithLike; return true; - case 0x06: // Decrement + case mc_opcode_decrement: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeArithLike; return true; - case 0x16: // DecrementQ + case mc_opcode_decrementq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeArithLike; 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(); consumer_ = &McServerBinaryParser::consumeGetLike; return true; - case 0x10: // Stat + case mc_opcode_stat: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeGetLike; return true; - case 0x0b: // Version + case mc_opcode_version: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeVersion; return true; - case 0x07: // Quit + case mc_opcode_quit: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeQuit; return true; - case 0x17: // QuitQ + case mc_opcode_quitq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeQuit; return true; - case 0x08: // Flush + case mc_opcode_flush: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeFlush; return true; - case 0x18: // FlushQ + case mc_opcode_flushq: currentMessage_.emplace(); consumer_ = &McServerBinaryParser::consumeFlush; 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; }