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) {
SampledRequest* sample = AskToBeSampled();
if (sample) {
sample->set_service_name(request_meta.service_name());
sample->set_method_name(request_meta.method_name());
sample->set_compress_type((CompressType)meta.compress_type());
sample->set_protocol_type(PROTOCOL_BAIDU_STD);
sample->set_attachment_size(meta.attachment_size());
sample->set_authentication_data(meta.authentication_data());
sample->meta.set_service_name(request_meta.service_name());
sample->meta.set_method_name(request_meta.method_name());
sample->meta.set_compress_type((CompressType)meta.compress_type());
sample->meta.set_protocol_type(PROTOCOL_BAIDU_STD);
sample->meta.set_attachment_size(meta.attachment_size());
sample->meta.set_authentication_data(meta.authentication_data());
sample->request = msg->payload;
sample->submit(start_parse_us);
}
......
......@@ -345,15 +345,15 @@ void ProcessHuluRequest(InputMessageBase* msg_base) {
const CompressType req_cmp_type = Hulu2CompressType((HuluCompressType)meta.compress_type());
SampledRequest* sample = AskToBeSampled();
if (sample) {
sample->set_service_name(meta.service_name());
sample->set_method_index(meta.method_index());
sample->set_compress_type(req_cmp_type);
sample->set_protocol_type(PROTOCOL_HULU_PBRPC);
sample->set_user_data(meta.user_data());
sample->meta.set_service_name(meta.service_name());
sample->meta.set_method_index(meta.method_index());
sample->meta.set_compress_type(req_cmp_type);
sample->meta.set_protocol_type(PROTOCOL_HULU_PBRPC);
sample->meta.set_user_data(meta.user_data());
if (meta.has_user_message_size()
&& static_cast<size_t>(meta.user_message_size()) < msg->payload.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->submit(start_parse_us);
......
......@@ -322,9 +322,9 @@ void ProcessSofaRequest(InputMessageBase* msg_base) {
SampledRequest* sample = AskToBeSampled();
if (sample) {
sample->set_method_name(meta.method());
sample->set_compress_type(req_cmp_type);
sample->set_protocol_type(PROTOCOL_SOFA_PBRPC);
sample->meta.set_method_name(meta.method());
sample->meta.set_compress_type(req_cmp_type);
sample->meta.set_protocol_type(PROTOCOL_SOFA_PBRPC);
sample->request = msg->payload;
sample->submit(start_parse_us);
}
......
......@@ -17,6 +17,7 @@
#ifndef BRPC_PROGRESSIVE_ATTACHMENT_H
#define BRPC_PROGRESSIVE_ATTACHMENT_H
#include <google/protobuf/stubs/callback.h>
#include "butil/atomicops.h"
#include "butil/iobuf.h"
#include "butil/endpoint.h" // butil::EndPoint
......
......@@ -24,13 +24,12 @@ namespace brpc {
DEFINE_bool(redis_verbose_crlf2space, false, "[DEBUG] Show \\r\\n as a space");
RedisRequest::RedisRequest()
: RedisRequestBase() {
: ::google::protobuf::Message() {
SharedCtor();
}
RedisRequest::RedisRequest(const RedisRequest& from)
: RedisRequestBase() {
: ::google::protobuf::Message() {
SharedCtor();
MergeFrom(from);
}
......@@ -46,14 +45,10 @@ RedisRequest::~RedisRequest() {
}
void RedisRequest::SharedDtor() {
if (this != default_instance_) {
}
}
void RedisRequest::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
RedisRequest* RedisRequest::New() const {
......@@ -84,9 +79,7 @@ void RedisRequest::SerializeWithCachedSizes(
int RedisRequest::ByteSize() const {
int total_size = _buf.size();
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size;
}
......@@ -206,6 +199,22 @@ bool RedisRequest::SerializeTo(butil::IOBuf* buf) const {
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 {
butil::IOBuf cp = _buf;
butil::IOBuf seg;
......@@ -232,12 +241,12 @@ std::ostream& operator<<(std::ostream& os, const RedisRequest& r) {
}
RedisResponse::RedisResponse()
: RedisResponseBase() {
: ::google::protobuf::Message() {
SharedCtor();
}
RedisResponse::RedisResponse(const RedisResponse& from)
: RedisResponseBase() {
: ::google::protobuf::Message() {
SharedCtor();
MergeFrom(from);
}
......@@ -253,8 +262,6 @@ RedisResponse::~RedisResponse() {
}
void RedisResponse::SharedDtor() {
if (this != default_instance_) {
}
}
void RedisResponse::SetCachedSize(int size) const {
......@@ -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) {
......
......@@ -19,6 +19,7 @@
#include <string>
#include <google/protobuf/message.h>
#include <google/protobuf/generated_message_reflection.h> // dynamic_cast_if_available
#include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge
......@@ -42,7 +43,7 @@ namespace brpc {
// if (!cntl.Failed()) {
// LOG(INFO) << response.reply(0);
// }
class RedisRequest : public RedisRequestBase {
class RedisRequest : public ::google::protobuf::Message {
public:
RedisRequest();
virtual ~RedisRequest();
......@@ -119,6 +120,10 @@ public:
::google::protobuf::io::CodedOutputStream* output) const;
::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;
......@@ -132,12 +137,13 @@ private:
bool _has_error; // previous AddCommand had error
butil::IOBuf _buf; // the serialized request.
mutable int _cached_size_; // ByteSize
static RedisRequestBase _base;
};
// Response from Redis.
// Notice that a RedisResponse instance may contain multiple replies
// due to pipelining.
class RedisResponse : public RedisResponseBase {
class RedisResponse : public ::google::protobuf::Message {
public:
RedisResponse();
virtual ~RedisResponse();
......@@ -185,6 +191,10 @@ public:
::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();
......@@ -195,6 +205,7 @@ private:
butil::Arena _arena;
int _nreply;
mutable int _cached_size_;
static RedisResponseBase _base;
};
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