Commit 231b35af authored by zhujiashun's avatar zhujiashun

Make RedisRequestBase be member of RedisRequest

parent 7e5b6dad
...@@ -317,12 +317,12 @@ void ProcessRpcRequest(InputMessageBase* msg_base) { ...@@ -317,12 +317,12 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
SampledRequest* sample = AskToBeSampled(); SampledRequest* sample = AskToBeSampled();
if (sample) { if (sample) {
sample->set_service_name(request_meta.service_name()); sample->meta.set_service_name(request_meta.service_name());
sample->set_method_name(request_meta.method_name()); sample->meta.set_method_name(request_meta.method_name());
sample->set_compress_type((CompressType)meta.compress_type()); sample->meta.set_compress_type((CompressType)meta.compress_type());
sample->set_protocol_type(PROTOCOL_BAIDU_STD); sample->meta.set_protocol_type(PROTOCOL_BAIDU_STD);
sample->set_attachment_size(meta.attachment_size()); sample->meta.set_attachment_size(meta.attachment_size());
sample->set_authentication_data(meta.authentication_data()); sample->meta.set_authentication_data(meta.authentication_data());
sample->request = msg->payload; sample->request = msg->payload;
sample->submit(start_parse_us); sample->submit(start_parse_us);
} }
......
...@@ -345,15 +345,15 @@ void ProcessHuluRequest(InputMessageBase* msg_base) { ...@@ -345,15 +345,15 @@ void ProcessHuluRequest(InputMessageBase* msg_base) {
const CompressType req_cmp_type = Hulu2CompressType((HuluCompressType)meta.compress_type()); const CompressType req_cmp_type = Hulu2CompressType((HuluCompressType)meta.compress_type());
SampledRequest* sample = AskToBeSampled(); SampledRequest* sample = AskToBeSampled();
if (sample) { if (sample) {
sample->set_service_name(meta.service_name()); sample->meta.set_service_name(meta.service_name());
sample->set_method_index(meta.method_index()); sample->meta.set_method_index(meta.method_index());
sample->set_compress_type(req_cmp_type); sample->meta.set_compress_type(req_cmp_type);
sample->set_protocol_type(PROTOCOL_HULU_PBRPC); sample->meta.set_protocol_type(PROTOCOL_HULU_PBRPC);
sample->set_user_data(meta.user_data()); sample->meta.set_user_data(meta.user_data());
if (meta.has_user_message_size() if (meta.has_user_message_size()
&& static_cast<size_t>(meta.user_message_size()) < msg->payload.size()) { && static_cast<size_t>(meta.user_message_size()) < msg->payload.size()) {
size_t attachment_size = msg->payload.size() - meta.user_message_size(); size_t attachment_size = msg->payload.size() - meta.user_message_size();
sample->set_attachment_size(attachment_size); sample->meta.set_attachment_size(attachment_size);
} }
sample->request = msg->payload; sample->request = msg->payload;
sample->submit(start_parse_us); sample->submit(start_parse_us);
......
...@@ -322,9 +322,9 @@ void ProcessSofaRequest(InputMessageBase* msg_base) { ...@@ -322,9 +322,9 @@ void ProcessSofaRequest(InputMessageBase* msg_base) {
SampledRequest* sample = AskToBeSampled(); SampledRequest* sample = AskToBeSampled();
if (sample) { if (sample) {
sample->set_method_name(meta.method()); sample->meta.set_method_name(meta.method());
sample->set_compress_type(req_cmp_type); sample->meta.set_compress_type(req_cmp_type);
sample->set_protocol_type(PROTOCOL_SOFA_PBRPC); sample->meta.set_protocol_type(PROTOCOL_SOFA_PBRPC);
sample->request = msg->payload; sample->request = msg->payload;
sample->submit(start_parse_us); sample->submit(start_parse_us);
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#ifndef BRPC_PROGRESSIVE_ATTACHMENT_H #ifndef BRPC_PROGRESSIVE_ATTACHMENT_H
#define BRPC_PROGRESSIVE_ATTACHMENT_H #define BRPC_PROGRESSIVE_ATTACHMENT_H
#include <google/protobuf/stubs/callback.h>
#include "butil/atomicops.h" #include "butil/atomicops.h"
#include "butil/iobuf.h" #include "butil/iobuf.h"
#include "butil/endpoint.h" // butil::EndPoint #include "butil/endpoint.h" // butil::EndPoint
......
...@@ -24,13 +24,12 @@ namespace brpc { ...@@ -24,13 +24,12 @@ 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");
RedisRequest::RedisRequest() RedisRequest::RedisRequest()
: ::google::protobuf::Message() {
: RedisRequestBase() {
SharedCtor(); SharedCtor();
} }
RedisRequest::RedisRequest(const RedisRequest& from) RedisRequest::RedisRequest(const RedisRequest& from)
: RedisRequestBase() { : ::google::protobuf::Message() {
SharedCtor(); SharedCtor();
MergeFrom(from); MergeFrom(from);
} }
...@@ -46,14 +45,10 @@ RedisRequest::~RedisRequest() { ...@@ -46,14 +45,10 @@ RedisRequest::~RedisRequest() {
} }
void RedisRequest::SharedDtor() { void RedisRequest::SharedDtor() {
if (this != default_instance_) {
}
} }
void RedisRequest::SetCachedSize(int size) const { void RedisRequest::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size; _cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
} }
RedisRequest* RedisRequest::New() const { RedisRequest* RedisRequest::New() const {
...@@ -84,9 +79,7 @@ void RedisRequest::SerializeWithCachedSizes( ...@@ -84,9 +79,7 @@ void RedisRequest::SerializeWithCachedSizes(
int RedisRequest::ByteSize() const { int RedisRequest::ByteSize() const {
int total_size = _buf.size(); int total_size = _buf.size();
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size; _cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size; return total_size;
} }
...@@ -206,6 +199,22 @@ bool RedisRequest::SerializeTo(butil::IOBuf* buf) const { ...@@ -206,6 +199,22 @@ bool RedisRequest::SerializeTo(butil::IOBuf* buf) const {
return true; return true;
} }
const ::google::protobuf::Descriptor* RedisRequest::descriptor() {
return _base.GetDescriptor();
}
const RedisRequest& RedisRequest::default_instance() {
static RedisRequest req;
return req;
}
::google::protobuf::Metadata RedisRequest::GetMetadata() const {
::google::protobuf::Metadata metadata;
metadata.descriptor = _base.GetDescriptor();
metadata.reflection = _base.GetReflection();
return metadata;
}
void RedisRequest::Print(std::ostream& os) const { void RedisRequest::Print(std::ostream& os) const {
butil::IOBuf cp = _buf; butil::IOBuf cp = _buf;
butil::IOBuf seg; butil::IOBuf seg;
...@@ -232,12 +241,12 @@ std::ostream& operator<<(std::ostream& os, const RedisRequest& r) { ...@@ -232,12 +241,12 @@ std::ostream& operator<<(std::ostream& os, const RedisRequest& r) {
} }
RedisResponse::RedisResponse() RedisResponse::RedisResponse()
: RedisResponseBase() { : ::google::protobuf::Message() {
SharedCtor(); SharedCtor();
} }
RedisResponse::RedisResponse(const RedisResponse& from) RedisResponse::RedisResponse(const RedisResponse& from)
: RedisResponseBase() { : ::google::protobuf::Message() {
SharedCtor(); SharedCtor();
MergeFrom(from); MergeFrom(from);
} }
...@@ -253,8 +262,6 @@ RedisResponse::~RedisResponse() { ...@@ -253,8 +262,6 @@ RedisResponse::~RedisResponse() {
} }
void RedisResponse::SharedDtor() { void RedisResponse::SharedDtor() {
if (this != default_instance_) {
}
} }
void RedisResponse::SetCachedSize(int size) const { void RedisResponse::SetCachedSize(int size) const {
...@@ -363,6 +370,22 @@ void RedisResponse::Swap(RedisResponse* other) { ...@@ -363,6 +370,22 @@ void RedisResponse::Swap(RedisResponse* other) {
} }
} }
const ::google::protobuf::Descriptor* RedisResponse::descriptor() {
return _base.GetDescriptor();
}
const RedisResponse& RedisResponse::default_instance() {
static RedisResponse res;
return res;
}
::google::protobuf::Metadata RedisResponse::GetMetadata() const {
::google::protobuf::Metadata metadata;
metadata.descriptor = _base.GetDescriptor();
metadata.reflection = _base.GetReflection();
return metadata;
}
// =================================================================== // ===================================================================
ParseError RedisResponse::ConsumePartialIOBuf(butil::IOBuf& buf, int reply_count) { ParseError RedisResponse::ConsumePartialIOBuf(butil::IOBuf& buf, int reply_count) {
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <string> #include <string>
#include <google/protobuf/message.h>
#include <google/protobuf/generated_message_reflection.h> // dynamic_cast_if_available #include <google/protobuf/generated_message_reflection.h> // dynamic_cast_if_available
#include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge #include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge
...@@ -42,7 +43,7 @@ namespace brpc { ...@@ -42,7 +43,7 @@ namespace brpc {
// if (!cntl.Failed()) { // if (!cntl.Failed()) {
// LOG(INFO) << response.reply(0); // LOG(INFO) << response.reply(0);
// } // }
class RedisRequest : public RedisRequestBase { class RedisRequest : public ::google::protobuf::Message {
public: public:
RedisRequest(); RedisRequest();
virtual ~RedisRequest(); virtual ~RedisRequest();
...@@ -119,6 +120,10 @@ public: ...@@ -119,6 +120,10 @@ public:
::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::io::CodedOutputStream* output) const;
::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;
...@@ -132,12 +137,13 @@ private: ...@@ -132,12 +137,13 @@ 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
static RedisRequestBase _base;
}; };
// 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 RedisResponseBase { class RedisResponse : public ::google::protobuf::Message {
public: public:
RedisResponse(); RedisResponse();
virtual ~RedisResponse(); virtual ~RedisResponse();
...@@ -185,6 +191,10 @@ public: ...@@ -185,6 +191,10 @@ 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();
...@@ -195,6 +205,7 @@ private: ...@@ -195,6 +205,7 @@ private:
butil::Arena _arena; butil::Arena _arena;
int _nreply; int _nreply;
mutable int _cached_size_; mutable int _cached_size_;
static RedisResponseBase _base;
}; };
std::ostream& operator<<(std::ostream& os, const RedisRequest&); std::ostream& operator<<(std::ostream& os, const RedisRequest&);
......
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