Skip to content

Commit

Permalink
Make RedisRequest derived from RedisRequestBase
Browse files Browse the repository at this point in the history
  • Loading branch information
zyearn committed Jun 20, 2019
1 parent 1eeee3d commit 7e5b6da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 192 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ set(PROTO_FILES idl_options.proto
brpc/policy/sofa_pbrpc_meta.proto
brpc/policy/mongo.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)
set(PROTOC_FLAGS ${PROTOC_FLAGS} -I${PROTOBUF_INCLUDE_DIR})
compile_proto(PROTO_HDRS PROTO_SRCS ${PROJECT_BINARY_DIR}
Expand Down
162 changes: 6 additions & 156 deletions src/brpc/redis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,123 +14,23 @@

// Authors: Ge,Jun (gejun@baidu.com)

#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <algorithm>
#include <gflags/gflags.h>
#include <google/protobuf/stubs/once.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 <butil/status.h>
#include "brpc/redis.h"
#include "brpc/redis_command.h"


namespace brpc {

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()
: ::google::protobuf::Message() {
SharedCtor();
}

void RedisRequest::InitAsDefaultInstance() {
: RedisRequestBase() {
SharedCtor();
}

RedisRequest::RedisRequest(const RedisRequest& from)
: ::google::protobuf::Message() {
: RedisRequestBase() {
SharedCtor();
MergeFrom(from);
}
Expand All @@ -155,19 +55,6 @@ void RedisRequest::SetCachedSize(int size) const {
_cached_size_ = size;
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 {
return new RedisRequest;
Expand Down Expand Up @@ -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) {
if (_has_error) {
return false;
Expand Down Expand Up @@ -352,21 +231,13 @@ std::ostream& operator<<(std::ostream& os, const RedisRequest& r) {
return os;
}

// ===================================================================

#ifndef _MSC_VER
#endif // !_MSC_VER

RedisResponse::RedisResponse()
: ::google::protobuf::Message() {
: RedisResponseBase() {
SharedCtor();
}

void RedisResponse::InitAsDefaultInstance() {
}

RedisResponse::RedisResponse(const RedisResponse& from)
: ::google::protobuf::Message() {
: RedisResponseBase() {
SharedCtor();
MergeFrom(from);
}
Expand All @@ -389,19 +260,6 @@ void RedisResponse::SharedDtor() {
void RedisResponse::SetCachedSize(int size) const {
_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 {
return new RedisResponse;
Expand Down Expand Up @@ -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) {
Expand Down
42 changes: 7 additions & 35 deletions src/brpc/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@
#define BRPC_REDIS_H

#include <string>
#include <google/protobuf/stubs/common.h>

#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include "google/protobuf/descriptor.pb.h"
#include <google/protobuf/generated_message_reflection.h> // dynamic_cast_if_available
#include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge

#include "butil/iobuf.h"
#include "butil/strings/string_piece.h"
#include "butil/arena.h"
#include "redis_reply.h"
#include "parse_result.h"

#include "brpc/redis_base.pb.h"
#include "brpc/redis_reply.h"
#include "brpc/parse_result.h"

namespace brpc {

Expand All @@ -46,7 +42,7 @@ namespace brpc {
// if (!cntl.Failed()) {
// LOG(INFO) << response.reply(0);
// }
class RedisRequest : public ::google::protobuf::Message {
class RedisRequest : public RedisRequestBase {
public:
RedisRequest();
virtual ~RedisRequest();
Expand Down Expand Up @@ -124,10 +120,6 @@ class RedisRequest : public ::google::protobuf::Message {
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
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;

private:
Expand All @@ -140,20 +132,12 @@ class RedisRequest : public ::google::protobuf::Message {
bool _has_error; // previous AddCommand had error
butil::IOBuf _buf; // the serialized request.
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.
// Notice that a RedisResponse instance may contain multiple replies
// due to pipelining.
class RedisResponse : public ::google::protobuf::Message {
class RedisResponse : public RedisResponseBase {
public:
RedisResponse();
virtual ~RedisResponse();
Expand Down Expand Up @@ -201,10 +185,6 @@ class RedisResponse : public ::google::protobuf::Message {
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }

static const ::google::protobuf::Descriptor* descriptor();
static const RedisResponse& default_instance();
::google::protobuf::Metadata GetMetadata() const;

private:
void SharedCtor();
void SharedDtor();
Expand All @@ -215,14 +195,6 @@ class RedisResponse : public ::google::protobuf::Message {
butil::Arena _arena;
int _nreply;
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&);
Expand Down
7 changes: 7 additions & 0 deletions src/brpc/redis_base.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax="proto2";
import "google/protobuf/descriptor.proto";

package brpc;

message RedisRequestBase {}
message RedisResponseBase {}

0 comments on commit 7e5b6da

Please sign in to comment.