Skip to content

Instantly share code, notes, and snippets.

@begeekmyfriend
Created February 2, 2015 14:48
Show Gist options
  • Save begeekmyfriend/f483d6acfd2ac33b274b to your computer and use it in GitHub Desktop.
Save begeekmyfriend/f483d6acfd2ac33b274b to your computer and use it in GitHub Desktop.
Message enum and string pair
#define MSG_CODEC(ACTION) \
ACTION( UNKNOWN, ""/* unknown */ ) \
ACTION( REQ_GET, "get " ) \
ACTION( REQ_GETS, "gets " ) \
ACTION( REQ_DELETE, "delete " ) \
ACTION( REQ_CAS, "cas " ) \
ACTION( REQ_SET, "set " ) \
ACTION( REQ_ADD, "add " ) \
ACTION( REQ_REPLACE, "replace " ) \
ACTION( REQ_APPEND, "append " ) \
ACTION( REQ_PREPEND, "prepend " ) \
ACTION( REQ_INCR, "incr " ) \
ACTION( REQ_DECR, "decr " ) \
ACTION( REQ_VERSION, "version " ) \
ACTION( REQ_QUIT, "quit " ) \
ACTION( RSP_NUM, "" /* na */ ) \
ACTION( RSP_VALUE, "VALUE " ) \
ACTION( RSP_END, "END\r\n" ) \
ACTION( RSP_STORED, "STORED\r\n" ) \
ACTION( RSP_NOT_STORED, "NOT_STORED\r\n" ) \
ACTION( RSP_EXISTS, "EXISTS\r\n" ) \
ACTION( RSP_NOT_FOUND, "NOT_FOUND\r\n" ) \
ACTION( RSP_DELETED, "DELETED\r\n" ) \
ACTION( RSP_CLIENT_ERROR, "CLIENT_ERROR " ) \
ACTION( RSP_SERVER_ERROR, "SERVER_ERROR " ) \
ACTION( RSP_VERSION, "VERSION fatcache\r\n" ) \
ACTION( CRLF, "\r\n" /* empty */ ) \
ACTION( EMPTY, "" /* empty */ ) \
#define DEFINE_ACTION(_hash, _name) MSG_##_hash,
typedef enum msg_type {
MSG_CODEC( DEFINE_ACTION )
MSG_SENTINEL
} msg_type_t;
#undef DEFINE_ACTION
#define DEFINE_ACTION(_hash, _name) (_name),
struct char *msg_strings[] = {
MSG_CODEC( DEFINE_ACTION )
null_string
};
#undef DEFINE_ACTION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment