jamesge commented on a change in pull request #972: Redis server protocol
URL: https://github.com/apache/incubator-brpc/pull/972#discussion_r360761555
##########
File path: src/brpc/redis_reply.cpp
##########
@@ -37,12 +39,65 @@ const char* RedisReplyTypeToString(RedisReplyType type) {
}
}
+bool RedisReply::SerializeTo(butil::IOBufAppender* appender) {
+ switch (_type) {
+ case REDIS_REPLY_ERROR:
+ // fall through
+ case REDIS_REPLY_STATUS:
+ appender->push_back((_type == REDIS_REPLY_ERROR)? '-' : '+');
+ if (_length < (int)sizeof(_data.short_str)) {
+ appender->append(_data.short_str, _length);
+ } else {
+ appender->append(_data.long_str, _length);
+ }
+ appender->append("\r\n", 2);
+ break;
+ case REDIS_REPLY_INTEGER:
+ appender->push_back(':');
+ appender->append_decimal(_data.integer);
+ appender->append("\r\n", 2);
+ break;
+ case REDIS_REPLY_STRING:
+ appender->push_back('$');
+ appender->append_decimal(_length);
+ appender->append("\r\n", 2);
+ if (_length != npos) {
+ if (_length < (int)sizeof(_data.short_str)) {
+ appender->append(_data.short_str, _length);
+ } else {
+ appender->append(_data.long_str, _length);
+ }
+ appender->append("\r\n", 2);
+ }
+ break;
+ case REDIS_REPLY_ARRAY:
+ appender->push_back('*');
+ appender->append_decimal(_length);
+ appender->append("\r\n", 2);
+ if (_length != npos) {
+ for (int i = 0; i < _length; ++i) {
+ if (!_data.array.replies[i].SerializeTo(appender)) {
+ return false;
+ }
+ }
+ }
+ break;
+ case REDIS_REPLY_NIL:
+ LOG(ERROR) << "Do you forget to call SetXXX()?";
+ return false;
+ default:
Review comment:
完整列出所有enums的switch内不要含default,写到外面去。上面的break都可以直接return true
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]