Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
c2388562
Commit
c2388562
authored
7 years ago
by
wangxuefeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename ThriftBinary* to ThriftFramed*
parent
c332d839
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
99 additions
and
97 deletions
+99
-97
Makefile
Makefile
+1
-1
client.cpp
example/thrift_extension_c++/client.cpp
+1
-1
server.cpp
example/thrift_extension_c++/server.cpp
+7
-7
global.cpp
src/brpc/global.cpp
+4
-4
thrift_protocol.cpp
src/brpc/policy/thrift_protocol.cpp
+20
-20
thrift_protocol.h
src/brpc/policy/thrift_protocol.h
+6
-6
thrift_binary_message.cpp
src/brpc/thrift_binary_message.cpp
+34
-34
thrift_binary_message.h
src/brpc/thrift_binary_message.h
+14
-12
thrift_service.h
src/brpc/thrift_service.h
+10
-10
thrift_utils.h
src/butil/thrift_utils.h
+2
-2
No files found.
Makefile
View file @
c2388562
...
...
@@ -6,7 +6,7 @@ include config.mk
# 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8
# 3. Removed -Werror: Not block compilation for non-vital warnings, especially when the
# code is tested on newer systems. If the code is used in production, add -Werror back
CPPFLAGS
+=
-D
ENABLE_THRIFT_FRAMED_PROTOCOL
-D
BTHREAD_USE_FAST_PTHREAD_MUTEX
-D__const__
=
-D_GNU_SOURCE
-DUSE_SYMBOLIZE
-DNO_TCMALLOC
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
-DNDEBUG
-DBRPC_REVISION
=
\"
$(
shell
git rev-parse
--short
HEAD
)
\"
CPPFLAGS
+=
-DBTHREAD_USE_FAST_PTHREAD_MUTEX
-D__const__
=
-D_GNU_SOURCE
-DUSE_SYMBOLIZE
-DNO_TCMALLOC
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
-DNDEBUG
-DBRPC_REVISION
=
\"
$(
shell
git rev-parse
--short
HEAD
)
\"
CXXFLAGS
=
$(CPPFLAGS)
-O2
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-invalid-offsetof
-Wno-unused-parameter
-fno-omit-frame-pointer
-std
=
c++0x
CFLAGS
=
$(CPPFLAGS)
-O2
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-unused-parameter
-fno-omit-frame-pointer
DEBUG_CXXFLAGS
=
$
(
filter-out
-DNDEBUG
,
$(CXXFLAGS)
)
-DUNIT_TEST
-DBVAR_NOT_LINK_DEFAULT_VARIABLES
...
...
This diff is collapsed.
Click to expand it.
example/thrift_extension_c++/client.cpp
View file @
c2388562
...
...
@@ -90,7 +90,7 @@ int main(int argc, char* argv[]) {
<<
"Sending thrift requests at qps="
<<
g_latency_recorder
.
qps
(
1
)
<<
" latency="
<<
g_latency_recorder
.
latency
(
1
);
sleep
(
1
);
//
sleep(1);
}
...
...
This diff is collapsed.
Click to expand it.
example/thrift_extension_c++/server.cpp
View file @
c2388562
...
...
@@ -48,10 +48,10 @@ public:
// Adapt your own thrift-based protocol to use brpc
class
MyThriftProtocol
:
public
brpc
::
ThriftFramedService
{
public
:
void
ProcessThrift
Binary
Request
(
const
brpc
::
Server
&
,
void
ProcessThrift
Framed
Request
(
const
brpc
::
Server
&
,
brpc
::
Controller
*
cntl
,
const
brpc
::
Thrift
Binary
Message
&
request
,
brpc
::
Thrift
Binary
Message
*
response
,
const
brpc
::
Thrift
Framed
Message
&
request
,
brpc
::
Thrift
Framed
Message
*
response
,
brpc
::
ThriftFramedClosure
*
done
)
{
// This object helps you to call done->Run() in RAII style. If you need
// to process the request asynchronously, pass done_guard.release().
...
...
@@ -81,10 +81,10 @@ public:
// Adapt your own thrift-based protocol to use brpc
class
MyThriftProtocolAnother
:
public
brpc
::
ThriftFramedService
{
public
:
void
ProcessThrift
Binary
Request
(
const
brpc
::
Server
&
,
void
ProcessThrift
Framed
Request
(
const
brpc
::
Server
&
,
brpc
::
Controller
*
cntl
,
const
brpc
::
Thrift
Binary
Message
&
request
,
brpc
::
Thrift
Binary
Message
*
response
,
const
brpc
::
Thrift
Framed
Message
&
request
,
brpc
::
Thrift
Framed
Message
*
response
,
brpc
::
ThriftFramedClosure
*
done
)
{
// This object helps you to call done->Run() in RAII style. If you need
// to process the request asynchronously, pass done_guard.release().
...
...
@@ -97,7 +97,7 @@ public:
return
;
}
brpc
::
Thrift
Binary
Message
request_ref
=
request
;
brpc
::
Thrift
Framed
Message
request_ref
=
request
;
example
::
EchoRequest
*
req
=
request_ref
.
cast
<
example
::
EchoRequest
>
();
example
::
EchoResponse
*
res
=
response
->
cast
<
example
::
EchoResponse
>
();
...
...
This diff is collapsed.
Click to expand it.
src/brpc/global.cpp
View file @
c2388562
...
...
@@ -423,10 +423,10 @@ static void GlobalInitializeOrDieImpl() {
}
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
Protocol
thrift_binary_protocol
=
{
ParseThrift
Binary
Message
,
SerializeThrift
BinaryRequest
,
PackThriftBinary
Request
,
ProcessThrift
BinaryRequest
,
ProcessThriftBinary
Response
,
VerifyThrift
Binary
Request
,
NULL
,
NULL
,
Protocol
thrift_binary_protocol
=
{
ParseThrift
Framed
Message
,
SerializeThrift
FramedRequest
,
PackThriftFramed
Request
,
ProcessThrift
FramedRequest
,
ProcessThriftFramed
Response
,
VerifyThrift
Framed
Request
,
NULL
,
NULL
,
CONNECTION_TYPE_POOLED_AND_SHORT
,
"thrift"
};
if
(
RegisterProtocol
(
PROTOCOL_THRIFT
,
thrift_binary_protocol
)
!=
0
)
{
exit
(
1
);
...
...
This diff is collapsed.
Click to expand it.
src/brpc/policy/thrift_protocol.cpp
View file @
c2388562
...
...
@@ -192,7 +192,7 @@ void ThriftFramedClosure::SetMethodName(const std::string& full_method_name) {
namespace
policy
{
ParseResult
ParseThrift
Binary
Message
(
butil
::
IOBuf
*
source
,
ParseResult
ParseThrift
Framed
Message
(
butil
::
IOBuf
*
source
,
Socket
*
,
bool
/*read_eof*/
,
const
void
*
/*arg*/
)
{
char
header_buf
[
sizeof
(
thrift_binary_head_t
)
+
3
];
...
...
@@ -230,14 +230,14 @@ struct CallMethodInBackupThreadArgs {
ThriftFramedService
*
service
;
const
Server
*
server
;
Controller
*
controller
;
const
Thrift
Binary
Message
*
request
;
Thrift
Binary
Message
*
response
;
const
Thrift
Framed
Message
*
request
;
Thrift
Framed
Message
*
response
;
ThriftFramedClosure
*
done
;
};
static
void
CallMethodInBackupThread
(
void
*
void_args
)
{
CallMethodInBackupThreadArgs
*
args
=
(
CallMethodInBackupThreadArgs
*
)
void_args
;
args
->
service
->
ProcessThrift
Binary
Request
(
*
args
->
server
,
args
->
controller
,
args
->
service
->
ProcessThrift
Framed
Request
(
*
args
->
server
,
args
->
controller
,
*
args
->
request
,
args
->
response
,
args
->
done
);
delete
args
;
...
...
@@ -246,8 +246,8 @@ static void CallMethodInBackupThread(void* void_args) {
static
void
EndRunningCallMethodInPool
(
ThriftFramedService
*
service
,
const
Server
&
server
,
Controller
*
controller
,
const
Thrift
Binary
Message
&
request
,
Thrift
Binary
Message
*
response
,
const
Thrift
Framed
Message
&
request
,
Thrift
Framed
Message
*
response
,
ThriftFramedClosure
*
done
)
{
CallMethodInBackupThreadArgs
*
args
=
new
CallMethodInBackupThreadArgs
;
args
->
service
=
service
;
...
...
@@ -259,7 +259,7 @@ static void EndRunningCallMethodInPool(ThriftFramedService* service,
return
EndRunningUserCodeInPool
(
CallMethodInBackupThread
,
args
);
};
void
ProcessThrift
Binary
Request
(
InputMessageBase
*
msg_base
)
{
void
ProcessThrift
Framed
Request
(
InputMessageBase
*
msg_base
)
{
const
int64_t
start_parse_us
=
butil
::
cpuwide_time_us
();
...
...
@@ -302,8 +302,8 @@ void ProcessThriftBinaryRequest(InputMessageBase* msg_base) {
}
ThriftFramedClosure
*
thrift_done
=
new
(
space
)
ThriftFramedClosure
(
sub_space
);
Controller
*
cntl
=
&
(
thrift_done
->
_controller
);
Thrift
Binary
Message
*
req
=
&
(
thrift_done
->
_request
);
Thrift
Binary
Message
*
res
=
&
(
thrift_done
->
_response
);
Thrift
Framed
Message
*
req
=
&
(
thrift_done
->
_request
);
Thrift
Framed
Message
*
res
=
&
(
thrift_done
->
_response
);
req
->
head
=
*
req_head
;
msg
->
payload
.
swap
(
req
->
body
);
...
...
@@ -369,10 +369,10 @@ void ProcessThriftBinaryRequest(InputMessageBase* msg_base) {
span
->
AsParent
();
}
if
(
!
FLAGS_usercode_in_pthread
)
{
return
service
->
ProcessThrift
Binary
Request
(
*
server
,
cntl
,
*
req
,
res
,
thrift_done
);
return
service
->
ProcessThrift
Framed
Request
(
*
server
,
cntl
,
*
req
,
res
,
thrift_done
);
}
if
(
BeginRunningUserCode
())
{
service
->
ProcessThrift
Binary
Request
(
*
server
,
cntl
,
*
req
,
res
,
thrift_done
);
service
->
ProcessThrift
Framed
Request
(
*
server
,
cntl
,
*
req
,
res
,
thrift_done
);
return
EndRunningUserCodeInPlace
();
}
else
{
return
EndRunningCallMethodInPool
(
...
...
@@ -381,11 +381,11 @@ void ProcessThriftBinaryRequest(InputMessageBase* msg_base) {
}
void
ProcessThrift
Binary
Response
(
InputMessageBase
*
msg_base
)
{
void
ProcessThrift
Framed
Response
(
InputMessageBase
*
msg_base
)
{
const
int64_t
start_parse_us
=
butil
::
cpuwide_time_us
();
DestroyingPtr
<
MostCommonMessage
>
msg
(
static_cast
<
MostCommonMessage
*>
(
msg_base
));
// Fetch correlation id that we saved before in `PacThrift
Binary
Request'
// Fetch correlation id that we saved before in `PacThrift
Framed
Request'
const
CallId
cid
=
{
static_cast
<
uint64_t
>
(
msg
->
socket
()
->
correlation_id
())
};
Controller
*
cntl
=
NULL
;
const
int
rc
=
bthread_id_lock
(
cid
,
(
void
**
)
&
cntl
);
...
...
@@ -404,8 +404,8 @@ void ProcessThriftBinaryResponse(InputMessageBase* msg_base) {
span
->
set_start_parse_us
(
start_parse_us
);
}
// MUST be Thrift
BinaryMessage (checked in SerializeThriftBinary
Request)
Thrift
BinaryMessage
*
response
=
(
ThriftBinary
Message
*
)
cntl
->
response
();
// MUST be Thrift
FramedMessage (checked in SerializeThriftFramed
Request)
Thrift
FramedMessage
*
response
=
(
ThriftFramed
Message
*
)
cntl
->
response
();
const
int
saved_error
=
cntl
->
ErrorCode
();
if
(
response
!=
NULL
)
{
msg
->
meta
.
copy_to
(
&
response
->
head
,
sizeof
(
thrift_binary_head_t
));
...
...
@@ -506,7 +506,7 @@ void ProcessThriftBinaryResponse(InputMessageBase* msg_base) {
accessor
.
OnResponse
(
cid
,
saved_error
);
}
bool
VerifyThrift
Binary
Request
(
const
InputMessageBase
*
msg_base
)
{
bool
VerifyThrift
Framed
Request
(
const
InputMessageBase
*
msg_base
)
{
Server
*
server
=
(
Server
*
)
msg_base
->
arg
();
if
(
server
->
options
().
auth
)
{
LOG
(
WARNING
)
<<
"thrift does not support authentication"
;
...
...
@@ -515,14 +515,14 @@ bool VerifyThriftBinaryRequest(const InputMessageBase* msg_base) {
return
true
;
}
void
SerializeThrift
Binary
Request
(
butil
::
IOBuf
*
request_buf
,
Controller
*
cntl
,
void
SerializeThrift
Framed
Request
(
butil
::
IOBuf
*
request_buf
,
Controller
*
cntl
,
const
google
::
protobuf
::
Message
*
req_base
)
{
if
(
req_base
==
NULL
)
{
return
cntl
->
SetFailed
(
EREQUEST
,
"request is NULL"
);
}
ControllerPrivateAccessor
accessor
(
cntl
);
const
Thrift
BinaryMessage
*
req
=
(
const
ThriftBinary
Message
*
)
req_base
;
const
Thrift
FramedMessage
*
req
=
(
const
ThriftFramed
Message
*
)
req_base
;
thrift_binary_head_t
head
=
req
->
head
;
...
...
@@ -556,7 +556,7 @@ void SerializeThriftBinaryRequest(butil::IOBuf* request_buf, Controller* cntl,
xfer
+=
out_portocol
->
writeFieldBegin
(
"request"
,
::
apache
::
thrift
::
protocol
::
T_STRUCT
,
1
);
// request's write
Thrift
BinaryMessage
*
r
=
const_cast
<
ThriftBinary
Message
*>
(
req
);
Thrift
FramedMessage
*
r
=
const_cast
<
ThriftFramed
Message
*>
(
req
);
xfer
+=
r
->
write
(
out_portocol
.
get
());
// end request's write
...
...
@@ -583,7 +583,7 @@ void SerializeThriftBinaryRequest(butil::IOBuf* request_buf, Controller* cntl,
}
void
PackThrift
Binary
Request
(
void
PackThrift
Framed
Request
(
butil
::
IOBuf
*
packet_buf
,
SocketMessage
**
,
uint64_t
correlation_id
,
...
...
This diff is collapsed.
Click to expand it.
src/brpc/policy/thrift_protocol.h
View file @
c2388562
...
...
@@ -24,18 +24,18 @@ namespace brpc {
namespace
policy
{
// Parse binary protocol format of thrift framed
ParseResult
ParseThrift
Binary
Message
(
butil
::
IOBuf
*
source
,
Socket
*
socket
,
bool
read_eof
,
const
void
*
arg
);
ParseResult
ParseThrift
Framed
Message
(
butil
::
IOBuf
*
source
,
Socket
*
socket
,
bool
read_eof
,
const
void
*
arg
);
// Actions to a (client) request in thrift binary framed format
void
ProcessThrift
Binary
Request
(
InputMessageBase
*
msg
);
void
ProcessThrift
Framed
Request
(
InputMessageBase
*
msg
);
// Actions to a (server) response in thrift binary framed format
void
ProcessThrift
Binary
Response
(
InputMessageBase
*
msg
);
void
ProcessThrift
Framed
Response
(
InputMessageBase
*
msg
);
void
SerializeThrift
Binary
Request
(
butil
::
IOBuf
*
request_buf
,
Controller
*
controller
,
void
SerializeThrift
Framed
Request
(
butil
::
IOBuf
*
request_buf
,
Controller
*
controller
,
const
google
::
protobuf
::
Message
*
request
);
void
PackThrift
Binary
Request
(
void
PackThrift
Framed
Request
(
butil
::
IOBuf
*
packet_buf
,
SocketMessage
**
,
uint64_t
correlation_id
,
...
...
@@ -45,7 +45,7 @@ void PackThriftBinaryRequest(
const
Authenticator
*
);
// Verify authentication information in thrift binary format
bool
VerifyThrift
Binary
Request
(
const
InputMessageBase
*
msg
);
bool
VerifyThrift
Framed
Request
(
const
InputMessageBase
*
msg
);
}
// namespace policy
}
// namespace brpc
...
...
This diff is collapsed.
Click to expand it.
src/brpc/thrift_binary_message.cpp
View file @
c2388562
...
...
@@ -31,7 +31,7 @@
namespace
brpc
{
namespace
{
const
::
google
::
protobuf
::
Descriptor
*
Thrift
Binary
Message_descriptor_
=
NULL
;
const
::
google
::
protobuf
::
Descriptor
*
Thrift
Framed
Message_descriptor_
=
NULL
;
}
// namespace
...
...
@@ -41,7 +41,7 @@ void protobuf_AssignDesc_baidu_2frpc_2fthrift_binary_5fmessage_2eproto() {
::
google
::
protobuf
::
DescriptorPool
::
generated_pool
()
->
FindFileByName
(
"baidu/rpc/thrift_binary_message.proto"
);
GOOGLE_CHECK
(
file
!=
NULL
);
Thrift
Binary
Message_descriptor_
=
file
->
message_type
(
0
);
Thrift
Framed
Message_descriptor_
=
file
->
message_type
(
0
);
}
namespace
{
...
...
@@ -55,13 +55,13 @@ inline void protobuf_AssignDescriptorsOnce() {
void
protobuf_RegisterTypes
(
const
::
std
::
string
&
)
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
Thrift
BinaryMessage_descriptor_
,
&
ThriftBinary
Message
::
default_instance
());
Thrift
FramedMessage_descriptor_
,
&
ThriftFramed
Message
::
default_instance
());
}
}
// namespace
void
protobuf_ShutdownFile_baidu_2frpc_2fthrift_binary_5fmessage_2eproto
()
{
delete
Thrift
Binary
Message
::
default_instance_
;
delete
Thrift
Framed
Message
::
default_instance_
;
}
void
protobuf_AddDesc_baidu_2frpc_2fthrift_binary_5fmessage_2eproto_impl
()
{
...
...
@@ -77,8 +77,8 @@ void protobuf_AddDesc_baidu_2frpc_2fthrift_binary_5fmessage_2eproto_impl() {
"hriftBinaryMessage"
,
58
);
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedFile
(
"thrift_binary_message.proto"
,
&
protobuf_RegisterTypes
);
Thrift
BinaryMessage
::
default_instance_
=
new
ThriftBinary
Message
();
Thrift
Binary
Message
::
default_instance_
->
InitAsDefaultInstance
();
Thrift
FramedMessage
::
default_instance_
=
new
ThriftFramed
Message
();
Thrift
Framed
Message
::
default_instance_
->
InitAsDefaultInstance
();
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
protobuf_ShutdownFile_baidu_2frpc_2fthrift_binary_5fmessage_2eproto
);
}
...
...
@@ -103,59 +103,59 @@ struct StaticDescriptorInitializer_baidu_2frpc_2fthrift_binary_5fmessage_2eproto
#ifndef _MSC_VER
#endif // !_MSC_VER
Thrift
BinaryMessage
::
ThriftBinary
Message
()
Thrift
FramedMessage
::
ThriftFramed
Message
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
Thrift
Binary
Message
::
InitAsDefaultInstance
()
{
void
Thrift
Framed
Message
::
InitAsDefaultInstance
()
{
}
Thrift
BinaryMessage
::
ThriftBinaryMessage
(
const
ThriftBinary
Message
&
from
)
Thrift
FramedMessage
::
ThriftFramedMessage
(
const
ThriftFramed
Message
&
from
)
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
MergeFrom
(
from
);
}
void
Thrift
Binary
Message
::
SharedCtor
()
{
void
Thrift
Framed
Message
::
SharedCtor
()
{
memset
(
&
head
,
0
,
sizeof
(
head
));
}
Thrift
BinaryMessage
::~
ThriftBinary
Message
()
{
Thrift
FramedMessage
::~
ThriftFramed
Message
()
{
SharedDtor
();
if
(
thrift_raw_instance
&&
thrift_raw_instance_deleter
)
{
thrift_raw_instance_deleter
(
thrift_raw_instance
);
}
}
void
Thrift
Binary
Message
::
SharedDtor
()
{
void
Thrift
Framed
Message
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
const
::
google
::
protobuf
::
Descriptor
*
Thrift
Binary
Message
::
descriptor
()
{
const
::
google
::
protobuf
::
Descriptor
*
Thrift
Framed
Message
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
Thrift
Binary
Message_descriptor_
;
return
Thrift
Framed
Message_descriptor_
;
}
const
Thrift
BinaryMessage
&
ThriftBinary
Message
::
default_instance
()
{
const
Thrift
FramedMessage
&
ThriftFramed
Message
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
protobuf_AddDesc_baidu_2frpc_2fthrift_binary_5fmessage_2eproto
();
return
*
default_instance_
;
}
Thrift
BinaryMessage
*
ThriftBinary
Message
::
default_instance_
=
NULL
;
Thrift
FramedMessage
*
ThriftFramed
Message
::
default_instance_
=
NULL
;
Thrift
BinaryMessage
*
ThriftBinary
Message
::
New
()
const
{
return
new
Thrift
Binary
Message
;
Thrift
FramedMessage
*
ThriftFramed
Message
::
New
()
const
{
return
new
Thrift
Framed
Message
;
}
void
Thrift
Binary
Message
::
Clear
()
{
void
Thrift
Framed
Message
::
Clear
()
{
memset
(
&
head
,
0
,
sizeof
(
head
));
body
.
clear
();
}
bool
Thrift
Binary
Message
::
MergePartialFromCodedStream
(
bool
Thrift
Framed
Message
::
MergePartialFromCodedStream
(
::
google
::
protobuf
::
io
::
CodedInputStream
*
input
)
{
#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
::
google
::
protobuf
::
uint32
tag
;
...
...
@@ -169,55 +169,55 @@ bool ThriftBinaryMessage::MergePartialFromCodedStream(
#undef DO_
}
void
Thrift
Binary
Message
::
SerializeWithCachedSizes
(
void
Thrift
Framed
Message
::
SerializeWithCachedSizes
(
::
google
::
protobuf
::
io
::
CodedOutputStream
*
)
const
{
}
::
google
::
protobuf
::
uint8
*
Thrift
Binary
Message
::
SerializeWithCachedSizesToArray
(
::
google
::
protobuf
::
uint8
*
Thrift
Framed
Message
::
SerializeWithCachedSizesToArray
(
::
google
::
protobuf
::
uint8
*
target
)
const
{
return
target
;
}
int
Thrift
Binary
Message
::
ByteSize
()
const
{
int
Thrift
Framed
Message
::
ByteSize
()
const
{
return
sizeof
(
thrift_binary_head_t
)
+
body
.
size
();
}
void
Thrift
Binary
Message
::
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
void
Thrift
Framed
Message
::
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
GOOGLE_CHECK_NE
(
&
from
,
this
);
const
Thrift
Binary
Message
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
Thrift
Binary
Message
*>
(
const
Thrift
Framed
Message
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
Thrift
Framed
Message
*>
(
&
from
);
if
(
source
==
NULL
)
{
LOG
(
ERROR
)
<<
"Can only merge from Thrift
Binary
Message"
;
LOG
(
ERROR
)
<<
"Can only merge from Thrift
Framed
Message"
;
return
;
}
else
{
MergeFrom
(
*
source
);
}
}
void
Thrift
BinaryMessage
::
MergeFrom
(
const
ThriftBinary
Message
&
from
)
{
void
Thrift
FramedMessage
::
MergeFrom
(
const
ThriftFramed
Message
&
from
)
{
GOOGLE_CHECK_NE
(
&
from
,
this
);
head
=
from
.
head
;
body
=
from
.
body
;
}
void
Thrift
Binary
Message
::
CopyFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
void
Thrift
Framed
Message
::
CopyFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
if
(
&
from
==
this
)
return
;
Clear
();
MergeFrom
(
from
);
}
void
Thrift
BinaryMessage
::
CopyFrom
(
const
ThriftBinary
Message
&
from
)
{
void
Thrift
FramedMessage
::
CopyFrom
(
const
ThriftFramed
Message
&
from
)
{
if
(
&
from
==
this
)
return
;
Clear
();
MergeFrom
(
from
);
}
bool
Thrift
Binary
Message
::
IsInitialized
()
const
{
bool
Thrift
Framed
Message
::
IsInitialized
()
const
{
return
true
;
}
void
Thrift
BinaryMessage
::
Swap
(
ThriftBinary
Message
*
other
)
{
void
Thrift
FramedMessage
::
Swap
(
ThriftFramed
Message
*
other
)
{
if
(
other
!=
this
)
{
const
thrift_binary_head_t
tmp
=
other
->
head
;
other
->
head
=
head
;
...
...
@@ -226,10 +226,10 @@ void ThriftBinaryMessage::Swap(ThriftBinaryMessage* other) {
}
}
::
google
::
protobuf
::
Metadata
Thrift
Binary
Message
::
GetMetadata
()
const
{
::
google
::
protobuf
::
Metadata
Thrift
Framed
Message
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
Thrift
Binary
Message_descriptor_
;
metadata
.
descriptor
=
Thrift
Framed
Message_descriptor_
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
...
...
This diff is collapsed.
Click to expand it.
src/brpc/thrift_binary_message.h
View file @
c2388562
...
...
@@ -20,6 +20,8 @@
#include <functional>
#include <string>
#include <boost/make_shared.hpp>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
...
...
@@ -53,7 +55,7 @@ void protobuf_AssignDesc_baidu_2frpc_2fthrift_binary_5fmessage_2eproto();
void
protobuf_ShutdownFile_baidu_2frpc_2fthrift_binary_5fmessage_2eproto
();
// Representing a thrift_binary request or response.
class
Thrift
Binary
Message
:
public
::
google
::
protobuf
::
Message
{
class
Thrift
Framed
Message
:
public
::
google
::
protobuf
::
Message
{
public
:
thrift_binary_head_t
head
;
butil
::
IOBuf
body
;
...
...
@@ -62,28 +64,28 @@ public:
void
*
thrift_raw_instance
;
public
:
Thrift
Binary
Message
();
virtual
~
Thrift
Binary
Message
();
Thrift
Framed
Message
();
virtual
~
Thrift
Framed
Message
();
Thrift
BinaryMessage
(
const
ThriftBinary
Message
&
from
);
Thrift
FramedMessage
(
const
ThriftFramed
Message
&
from
);
inline
Thrift
BinaryMessage
&
operator
=
(
const
ThriftBinary
Message
&
from
)
{
inline
Thrift
FramedMessage
&
operator
=
(
const
ThriftFramed
Message
&
from
)
{
CopyFrom
(
from
);
return
*
this
;
}
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
static
const
Thrift
Binary
Message
&
default_instance
();
static
const
Thrift
Framed
Message
&
default_instance
();
void
Swap
(
Thrift
Binary
Message
*
other
);
void
Swap
(
Thrift
Framed
Message
*
other
);
// implements Message ----------------------------------------------
Thrift
Binary
Message
*
New
()
const
;
Thrift
Framed
Message
*
New
()
const
;
void
CopyFrom
(
const
::
google
::
protobuf
::
Message
&
from
);
void
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
);
void
CopyFrom
(
const
Thrift
Binary
Message
&
from
);
void
MergeFrom
(
const
Thrift
Binary
Message
&
from
);
void
CopyFrom
(
const
Thrift
Framed
Message
&
from
);
void
MergeFrom
(
const
Thrift
Framed
Message
&
from
);
void
Clear
();
bool
IsInitialized
()
const
;
...
...
@@ -188,11 +190,11 @@ friend void protobuf_AssignDesc_baidu_2frpc_2fthrift_binary_5fmessage_2eproto();
friend
void
protobuf_ShutdownFile_baidu_2frpc_2fthrift_binary_5fmessage_2eproto
();
void
InitAsDefaultInstance
();
static
Thrift
Binary
Message
*
default_instance_
;
static
Thrift
Framed
Message
*
default_instance_
;
};
template
<
typename
T
>
class
ThriftMessage
:
public
Thrift
Binary
Message
{
class
ThriftMessage
:
public
Thrift
Framed
Message
{
public
:
ThriftMessage
()
{
...
...
This diff is collapsed.
Click to expand it.
src/brpc/thrift_service.h
View file @
c2388562
...
...
@@ -18,7 +18,7 @@
#define BRPC_THRIFT_SERVICE_H
#include "brpc/controller.h" // Controller
#include "brpc/thrift_binary_message.h" // Thrift
Binary
Message
#include "brpc/thrift_binary_message.h" // Thrift
Framed
Message
#include "brpc/describable.h"
...
...
@@ -29,7 +29,7 @@ class Server;
class
MethodStatus
;
class
StatusService
;
namespace
policy
{
void
ProcessThrift
Binary
Request
(
InputMessageBase
*
msg_base
);
void
ProcessThrift
Framed
Request
(
InputMessageBase
*
msg_base
);
}
// The continuation of request processing. Namely send response back to client.
...
...
@@ -56,7 +56,7 @@ public:
void
DoNotRespond
();
private
:
friend
void
policy
::
ProcessThrift
Binary
Request
(
InputMessageBase
*
msg_base
);
friend
void
policy
::
ProcessThrift
Framed
Request
(
InputMessageBase
*
msg_base
);
friend
class
DeleteThriftFramedClosure
;
// Only callable by Run().
~
ThriftFramedClosure
();
...
...
@@ -64,8 +64,8 @@ friend class DeleteThriftFramedClosure;
Socket
*
_socket_ptr
;
const
Server
*
_server
;
int64_t
_start_parse_us
;
Thrift
Binary
Message
_request
;
Thrift
Binary
Message
_response
;
Thrift
Framed
Message
_request
;
Thrift
Framed
Message
_response
;
bool
_do_respond
;
void
*
_additional_space
;
Controller
_controller
;
...
...
@@ -98,10 +98,10 @@ public:
// request The thrift_binary request received.
// response The thrift_binary response that you should fill in.
// done You must call done->Run() to end the processing.
virtual
void
ProcessThrift
Binary
Request
(
const
Server
&
server
,
virtual
void
ProcessThrift
Framed
Request
(
const
Server
&
server
,
Controller
*
controller
,
const
Thrift
Binary
Message
&
request
,
Thrift
Binary
Message
*
response
,
const
Thrift
Framed
Message
&
request
,
Thrift
Framed
Message
*
response
,
ThriftFramedClosure
*
done
)
=
0
;
// Put descriptions into the stream.
...
...
@@ -110,14 +110,14 @@ public:
private
:
DISALLOW_COPY_AND_ASSIGN
(
ThriftFramedService
);
friend
class
ThriftFramedClosure
;
friend
void
policy
::
ProcessThrift
Binary
Request
(
InputMessageBase
*
msg_base
);
friend
void
policy
::
ProcessThrift
Framed
Request
(
InputMessageBase
*
msg_base
);
friend
class
StatusService
;
friend
class
Server
;
private
:
void
Expose
(
const
butil
::
StringPiece
&
prefix
);
// Tracking status of non Thrift
Binary
PbService
// Tracking status of non Thrift
Framed
PbService
MethodStatus
*
_status
;
size_t
_additional_space
;
std
::
string
_cached_name
;
...
...
This diff is collapsed.
Click to expand it.
src/butil/thrift_utils.h
View file @
c2388562
...
...
@@ -28,8 +28,8 @@
namespace
brpc
{
bool
brpc_thrift_server_helper
(
const
brpc
::
Thrift
Binary
Message
&
request
,
brpc
::
Thrift
Binary
Message
*
response
,
bool
brpc_thrift_server_helper
(
const
brpc
::
Thrift
Framed
Message
&
request
,
brpc
::
Thrift
Framed
Message
*
response
,
boost
::
shared_ptr
<::
apache
::
thrift
::
TDispatchProcessor
>
processor
)
{
auto
in_buffer
=
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment