Commit 7e5b6dad authored by zhujiashun's avatar zhujiashun

Make RedisRequest derived from RedisRequestBase

parent 1eeee3d0
...@@ -371,7 +371,8 @@ set(PROTO_FILES idl_options.proto ...@@ -371,7 +371,8 @@ set(PROTO_FILES idl_options.proto
brpc/policy/sofa_pbrpc_meta.proto brpc/policy/sofa_pbrpc_meta.proto
brpc/policy/mongo.proto brpc/policy/mongo.proto
brpc/trackme.proto brpc/trackme.proto
brpc/streaming_rpc_meta.proto) brpc/streaming_rpc_meta.proto
brpc/redis_base.proto)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/output/include/brpc) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/output/include/brpc)
set(PROTOC_FLAGS ${PROTOC_FLAGS} -I${PROTOBUF_INCLUDE_DIR}) set(PROTOC_FLAGS ${PROTOC_FLAGS} -I${PROTOBUF_INCLUDE_DIR})
compile_proto(PROTO_HDRS PROTO_SRCS ${PROJECT_BINARY_DIR} compile_proto(PROTO_HDRS PROTO_SRCS ${PROJECT_BINARY_DIR}
......
...@@ -14,123 +14,23 @@ ...@@ -14,123 +14,23 @@
// Authors: Ge,Jun (gejun@baidu.com) // Authors: Ge,Jun (gejun@baidu.com)
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <algorithm>
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include <google/protobuf/stubs/once.h> #include <butil/status.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
#include "butil/string_printf.h"
#include "butil/macros.h"
#include "brpc/controller.h"
#include "brpc/redis.h" #include "brpc/redis.h"
#include "brpc/redis_command.h" #include "brpc/redis_command.h"
namespace brpc { namespace brpc {
DEFINE_bool(redis_verbose_crlf2space, false, "[DEBUG] Show \\r\\n as a space"); DEFINE_bool(redis_verbose_crlf2space, false, "[DEBUG] Show \\r\\n as a space");
// Internal implementation detail -- do not call these.
void protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl();
void protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto();
void protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto();
void protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto();
namespace {
const ::google::protobuf::Descriptor* RedisRequest_descriptor_ = NULL;
const ::google::protobuf::Descriptor* RedisResponse_descriptor_ = NULL;
} // namespace
void protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto() {
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"baidu/rpc/redis_base.proto");
GOOGLE_CHECK(file != NULL);
RedisRequest_descriptor_ = file->message_type(0);
RedisResponse_descriptor_ = file->message_type(1);
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
inline void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
RedisRequest_descriptor_, &RedisRequest::default_instance());
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
RedisResponse_descriptor_, &RedisResponse::default_instance());
}
} // namespace
void protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto() {
delete RedisRequest::default_instance_;
delete RedisResponse::default_instance_;
}
void protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
#if GOOGLE_PROTOBUF_VERSION >= 3002000
::google::protobuf::internal::InitProtobufDefaults();
#else
::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
#endif
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\032baidu/rpc/redis_base.proto\022\tbaidu.rpc\032"
" google/protobuf/descriptor.proto\"\016\n\014Red"
"isRequest\"\017\n\rRedisResponseB\003\200\001\001", 111);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"baidu/rpc/redis_base.proto", &protobuf_RegisterTypes);
RedisRequest::default_instance_ = new RedisRequest();
RedisResponse::default_instance_ = new RedisResponse();
RedisRequest::default_instance_->InitAsDefaultInstance();
RedisResponse::default_instance_->InitAsDefaultInstance();
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto);
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_once);
void protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto() {
::google::protobuf::GoogleOnceInit(
&protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_once,
&protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_baidu_2frpc_2fredis_5fbase_2eproto {
StaticDescriptorInitializer_baidu_2frpc_2fredis_5fbase_2eproto() {
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto();
}
} static_descriptor_initializer_baidu_2frpc_2fredis_5fbase_2eproto_;
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
RedisRequest::RedisRequest() RedisRequest::RedisRequest()
: ::google::protobuf::Message() {
SharedCtor();
}
void RedisRequest::InitAsDefaultInstance() { : RedisRequestBase() {
SharedCtor();
} }
RedisRequest::RedisRequest(const RedisRequest& from) RedisRequest::RedisRequest(const RedisRequest& from)
: ::google::protobuf::Message() { : RedisRequestBase() {
SharedCtor(); SharedCtor();
MergeFrom(from); MergeFrom(from);
} }
...@@ -155,19 +55,6 @@ void RedisRequest::SetCachedSize(int size) const { ...@@ -155,19 +55,6 @@ void RedisRequest::SetCachedSize(int size) const {
_cached_size_ = size; _cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END(); GOOGLE_SAFE_CONCURRENT_WRITES_END();
} }
const ::google::protobuf::Descriptor* RedisRequest::descriptor() {
protobuf_AssignDescriptorsOnce();
return RedisRequest_descriptor_;
}
const RedisRequest& RedisRequest::default_instance() {
if (default_instance_ == NULL) {
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto();
}
return *default_instance_;
}
RedisRequest* RedisRequest::default_instance_ = NULL;
RedisRequest* RedisRequest::New() const { RedisRequest* RedisRequest::New() const {
return new RedisRequest; return new RedisRequest;
...@@ -246,14 +133,6 @@ void RedisRequest::Swap(RedisRequest* other) { ...@@ -246,14 +133,6 @@ void RedisRequest::Swap(RedisRequest* other) {
} }
} }
::google::protobuf::Metadata RedisRequest::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = RedisRequest_descriptor_;
metadata.reflection = NULL;
return metadata;
}
bool RedisRequest::AddCommand(const butil::StringPiece& command) { bool RedisRequest::AddCommand(const butil::StringPiece& command) {
if (_has_error) { if (_has_error) {
return false; return false;
...@@ -352,21 +231,13 @@ std::ostream& operator<<(std::ostream& os, const RedisRequest& r) { ...@@ -352,21 +231,13 @@ std::ostream& operator<<(std::ostream& os, const RedisRequest& r) {
return os; return os;
} }
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
RedisResponse::RedisResponse() RedisResponse::RedisResponse()
: ::google::protobuf::Message() { : RedisResponseBase() {
SharedCtor(); SharedCtor();
} }
void RedisResponse::InitAsDefaultInstance() {
}
RedisResponse::RedisResponse(const RedisResponse& from) RedisResponse::RedisResponse(const RedisResponse& from)
: ::google::protobuf::Message() { : RedisResponseBase() {
SharedCtor(); SharedCtor();
MergeFrom(from); MergeFrom(from);
} }
...@@ -389,19 +260,6 @@ void RedisResponse::SharedDtor() { ...@@ -389,19 +260,6 @@ void RedisResponse::SharedDtor() {
void RedisResponse::SetCachedSize(int size) const { void RedisResponse::SetCachedSize(int size) const {
_cached_size_ = size; _cached_size_ = size;
} }
const ::google::protobuf::Descriptor* RedisResponse::descriptor() {
protobuf_AssignDescriptorsOnce();
return RedisResponse_descriptor_;
}
const RedisResponse& RedisResponse::default_instance() {
if (default_instance_ == NULL) {
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto();
}
return *default_instance_;
}
RedisResponse* RedisResponse::default_instance_ = NULL;
RedisResponse* RedisResponse::New() const { RedisResponse* RedisResponse::New() const {
return new RedisResponse; return new RedisResponse;
...@@ -505,14 +363,6 @@ void RedisResponse::Swap(RedisResponse* other) { ...@@ -505,14 +363,6 @@ void RedisResponse::Swap(RedisResponse* other) {
} }
} }
::google::protobuf::Metadata RedisResponse::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = RedisResponse_descriptor_;
metadata.reflection = NULL;
return metadata;
}
// =================================================================== // ===================================================================
ParseError RedisResponse::ConsumePartialIOBuf(butil::IOBuf& buf, int reply_count) { ParseError RedisResponse::ConsumePartialIOBuf(butil::IOBuf& buf, int reply_count) {
......
...@@ -18,20 +18,16 @@ ...@@ -18,20 +18,16 @@
#define BRPC_REDIS_H #define BRPC_REDIS_H
#include <string> #include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_util.h> #include <google/protobuf/generated_message_reflection.h> // dynamic_cast_if_available
#include <google/protobuf/repeated_field.h> #include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include "google/protobuf/descriptor.pb.h"
#include "butil/iobuf.h" #include "butil/iobuf.h"
#include "butil/strings/string_piece.h" #include "butil/strings/string_piece.h"
#include "butil/arena.h" #include "butil/arena.h"
#include "redis_reply.h" #include "brpc/redis_base.pb.h"
#include "parse_result.h" #include "brpc/redis_reply.h"
#include "brpc/parse_result.h"
namespace brpc { namespace brpc {
...@@ -46,7 +42,7 @@ namespace brpc { ...@@ -46,7 +42,7 @@ namespace brpc {
// if (!cntl.Failed()) { // if (!cntl.Failed()) {
// LOG(INFO) << response.reply(0); // LOG(INFO) << response.reply(0);
// } // }
class RedisRequest : public ::google::protobuf::Message { class RedisRequest : public RedisRequestBase {
public: public:
RedisRequest(); RedisRequest();
virtual ~RedisRequest(); virtual ~RedisRequest();
...@@ -124,10 +120,6 @@ public: ...@@ -124,10 +120,6 @@ public:
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; } int GetCachedSize() const { return _cached_size_; }
static const ::google::protobuf::Descriptor* descriptor();
static const RedisRequest& default_instance();
::google::protobuf::Metadata GetMetadata() const;
void Print(std::ostream&) const; void Print(std::ostream&) const;
private: private:
...@@ -140,20 +132,12 @@ private: ...@@ -140,20 +132,12 @@ private:
bool _has_error; // previous AddCommand had error bool _has_error; // previous AddCommand had error
butil::IOBuf _buf; // the serialized request. butil::IOBuf _buf; // the serialized request.
mutable int _cached_size_; // ByteSize mutable int _cached_size_; // ByteSize
friend void protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl();
friend void protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto();
friend void protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto();
friend void protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto();
void InitAsDefaultInstance();
static RedisRequest* default_instance_;
}; };
// Response from Redis. // Response from Redis.
// Notice that a RedisResponse instance may contain multiple replies // Notice that a RedisResponse instance may contain multiple replies
// due to pipelining. // due to pipelining.
class RedisResponse : public ::google::protobuf::Message { class RedisResponse : public RedisResponseBase {
public: public:
RedisResponse(); RedisResponse();
virtual ~RedisResponse(); virtual ~RedisResponse();
...@@ -201,10 +185,6 @@ public: ...@@ -201,10 +185,6 @@ public:
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; } int GetCachedSize() const { return _cached_size_; }
static const ::google::protobuf::Descriptor* descriptor();
static const RedisResponse& default_instance();
::google::protobuf::Metadata GetMetadata() const;
private: private:
void SharedCtor(); void SharedCtor();
void SharedDtor(); void SharedDtor();
...@@ -215,14 +195,6 @@ private: ...@@ -215,14 +195,6 @@ private:
butil::Arena _arena; butil::Arena _arena;
int _nreply; int _nreply;
mutable int _cached_size_; mutable int _cached_size_;
friend void protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl();
friend void protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto();
friend void protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto();
friend void protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto();
void InitAsDefaultInstance();
static RedisResponse* default_instance_;
}; };
std::ostream& operator<<(std::ostream& os, const RedisRequest&); std::ostream& operator<<(std::ostream& os, const RedisRequest&);
......
syntax="proto2";
import "google/protobuf/descriptor.proto";
package brpc;
message RedisRequestBase {}
message RedisResponseBase {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment