Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sofa-pbrpc protobuf v3支持 #102

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ OPT ?= -O2 # (A) Production use (optimized mode)
# SOFA_PBRPC_ENABLE_DETAILED_LOGGING : print current-time and thread-id in logging header
# SOFA_PBRPC_ENABLE_FUNCTION_TRACE : print trace log when enter and leave function
# SOFA_PBRPC_USE_SPINLOCK : use SpinLock as FastLock
# SOFA_PBRPC_PROFILING : use Profiling
# SOFA_PBRPC_USE_PROTO3 : use proto3 version of the Protocol Buffers language
#
CXXFLAGS ?= -DSOFA_PBRPC_ENABLE_DETAILED_LOGGING
#-----------------------------------------------
Expand All @@ -35,7 +37,7 @@ include depends.mk
LIB=libsofa-pbrpc.a
LIB_SRC=$(wildcard src/sofa/pbrpc/*.cc)
LIB_OBJ=$(patsubst %.cc,%.o,$(LIB_SRC))
PROTO=$(wildcard src/sofa/pbrpc/*.proto)
PROTO=$(wildcard src/sofa/pbrpc/$(PROTO_VERSION)/*.proto)
PROTO_SRC=$(patsubst %.proto,%.pb.cc,$(PROTO))
PROTO_HEADER=$(patsubst %.proto,%.pb.h,$(PROTO))
PROTO_OBJ=$(patsubst %.cc,%.o,$(PROTO_SRC))
Expand All @@ -53,8 +55,7 @@ PUB_INC=src/sofa/pbrpc/pbrpc.h src/sofa/pbrpc/closure_helper.h src/sofa/pbrpc/cl
src/sofa/pbrpc/locks.h src/sofa/pbrpc/mutex_lock.h src/sofa/pbrpc/spin_lock.h \
src/sofa/pbrpc/fast_lock.h src/sofa/pbrpc/rw_lock.h src/sofa/pbrpc/scoped_locker.h \
src/sofa/pbrpc/condition_variable.h src/sofa/pbrpc/wait_event.h src/sofa/pbrpc/http.h \
src/sofa/pbrpc/buffer.h src/sofa/pbrpc/buf_handle.h src/sofa/pbrpc/profiling_linker.h \
$(PROTO) $(PROTO_HEADER)
src/sofa/pbrpc/buffer.h src/sofa/pbrpc/buf_handle.h src/sofa/pbrpc/profiling_linker.h

#-----------------------------------------------
ifeq ($(OS),Windows_NT)
Expand All @@ -73,6 +74,9 @@ else
endif
endif

ifeq ($(PROTO_VERSION), proto3)
CXXFLAGS += -DSOFA_PBRPC_USE_PROTO3
endif
#-----------------------------------------------

CXX=g++
Expand Down Expand Up @@ -124,6 +128,9 @@ install: $(LIB) $(BIN)
cp src/sofa/pbrpc/smart_ptr/*.hpp $(PREFIX)/include/sofa/pbrpc/smart_ptr
mkdir -p $(PREFIX)/include/sofa/pbrpc/smart_ptr/detail
cp src/sofa/pbrpc/smart_ptr/detail/*.hpp $(PREFIX)/include/sofa/pbrpc/smart_ptr/detail
mkdir -p $(PREFIX)/include/sofa/pbrpc/$(PROTO_VERSION)
cp src/sofa/pbrpc/$(PROTO_VERSION)/*.proto $(PREFIX)/include/sofa/pbrpc/$(PROTO_VERSION)
cp src/sofa/pbrpc/$(PROTO_VERSION)/*.pb.h $(PREFIX)/include/sofa/pbrpc/$(PROTO_VERSION)
mkdir -p $(PREFIX)/lib
cp $(LIB) $(PREFIX)/lib/
mkdir -p $(PREFIX)/bin
Expand Down
10 changes: 10 additions & 0 deletions depends.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
##
################################################################

################################################################
## Version of Protocol Buffers language.
##
## Support Protocol Buffers version:
## proto2
## proto3
##
PROTO_VERSION=proto2
################################################################

################################################################
## Boost header directory.
##
Expand Down
12 changes: 10 additions & 2 deletions sample/compress_sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ else
endif
endif

PROTO_SRC=echo_service.proto
#-----------------------------------------------
# Customized macro switch:
# SOFA_PBRPC_USE_PROTO3 : use proto3 version of the protocol buffers language
ifeq ($(PROTO_VERSION),proto3)
CXXFLAGS += -DSOFA_PBRPC_USE_PROTO3
endif
#----------------------------------------------

PROTO_SRC=$(PROTO_VERSION)/echo_service.proto
PROTO_OBJ=$(patsubst %.proto,%.pb.o,$(PROTO_SRC))
PROTO_OPTIONS=--proto_path=. --proto_path=$(SOFA_PBRPC)/include --proto_path=$(PROTOBUF_DIR)/include

Expand All @@ -64,7 +72,7 @@ check_depends:
@if [ ! -f "$(SOFA_PBRPC)/lib/libsofa-pbrpc.a" ]; then echo "ERROR: need sofa-pbrpc lib"; exit 1; fi

clean:
@rm -f $(BIN) *.o *.pb.*
@rm -f $(BIN) *.o $(PROTO_VERSION)/*.pb.*

rebuild: clean all

Expand Down
7 changes: 6 additions & 1 deletion sample/compress_sample/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
// Author: [email protected] (Qin Zuoyan)

#include <sofa/pbrpc/pbrpc.h>
#include "echo_service.pb.h"

#if defined ( SOFA_PBRPC_USE_PROTO3 )
#include "proto3/echo_service.pb.h"
#else
#include "proto2/echo_service.pb.h"
#endif

int main(int /*argc*/, char** /*argv*/)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import "sofa/pbrpc/rpc_option.proto";
syntax = "proto2";

import "sofa/pbrpc/proto2/rpc_option.proto";

package sofa.pbrpc.test;

Expand Down
22 changes: 22 additions & 0 deletions sample/compress_sample/proto3/echo_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

import "sofa/pbrpc/proto3/rpc_option.proto";

package sofa.pbrpc.test;

option cc_generic_services = true;

message EchoRequest {
string message = 1;
}

message EchoResponse {
string message = 1;
}

service EchoServer {
rpc Echo(EchoRequest) returns(EchoResponse) {
option (sofa.pbrpc.request_compress_type) = CompressTypeSnappy;
option (sofa.pbrpc.response_compress_type) = CompressTypeSnappy;
}
}
7 changes: 6 additions & 1 deletion sample/compress_sample/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
#include <signal.h>
#include <unistd.h>
#include <sofa/pbrpc/pbrpc.h>
#include "echo_service.pb.h"

#if defined ( SOFA_PBRPC_USE_PROTO3 )
#include "proto3/echo_service.pb.h"
#else
#include "proto2/echo_service.pb.h"
#endif

class EchoServerImpl : public sofa::pbrpc::test::EchoServer
{
Expand Down
12 changes: 10 additions & 2 deletions sample/echo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ else
endif
endif

PROTO_SRC=echo_service.proto
#-----------------------------------------------
# Customized macro switch:
# SOFA_PBRPC_USE_PROTO3 : use proto3 version of the protocol buffers language
ifeq ($(PROTO_VERSION),proto3)
CXXFLAGS += -DSOFA_PBRPC_USE_PROTO3
endif
#----------------------------------------------

PROTO_SRC=$(PROTO_VERSION)/echo_service.proto
PROTO_OBJ=$(patsubst %.proto,%.pb.o,$(PROTO_SRC))
PROTO_OPTIONS=--proto_path=. --proto_path=$(SOFA_PBRPC)/include --proto_path=$(PROTOBUF_DIR)/include

Expand All @@ -64,7 +72,7 @@ check_depends:
@if [ ! -f "$(SOFA_PBRPC)/lib/libsofa-pbrpc.a" ]; then echo "ERROR: need sofa-pbrpc lib"; exit 1; fi

clean:
@rm -f $(BIN) *.o *.pb.*
@rm -f $(BIN) *.o $(PROTO_VERSION)/*.pb.*

rebuild: clean all

Expand Down
7 changes: 6 additions & 1 deletion sample/echo/client_async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

#include <unistd.h>
#include <sofa/pbrpc/pbrpc.h>
#include "echo_service.pb.h"

#if defined ( SOFA_PBRPC_USE_PROTO3 )
#include "proto3/echo_service.pb.h"
#else
#include "proto2/echo_service.pb.h"
#endif

void EchoCallback(sofa::pbrpc::RpcController* cntl,
sofa::pbrpc::test::EchoRequest* request,
Expand Down
7 changes: 6 additions & 1 deletion sample/echo/client_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
// Author: [email protected] (Qin Zuoyan)

#include <sofa/pbrpc/pbrpc.h>
#include "echo_service.pb.h"

#if defined ( SOFA_PBRPC_USE_PROTO3 )
#include "proto3/echo_service.pb.h"
#else
#include "proto2/echo_service.pb.h"
#endif

// Using global RpcClient object can help share resources such as threads and buffers.
sofa::pbrpc::RpcClient g_rpc_client;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
syntax = "proto2";

package sofa.pbrpc.test;

option cc_generic_services = true;
Expand Down
18 changes: 18 additions & 0 deletions sample/echo/proto3/echo_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package sofa.pbrpc.test;

option cc_generic_services = true;
option java_generic_services = true;

message EchoRequest {
string message = 1;
}

message EchoResponse {
string message = 1;
}

service EchoServer {
rpc Echo(EchoRequest) returns(EchoResponse);
}
7 changes: 6 additions & 1 deletion sample/echo/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
#include <signal.h>
#include <unistd.h>
#include <sofa/pbrpc/pbrpc.h>
#include "echo_service.pb.h"

#if defined ( SOFA_PBRPC_USE_PROTO3 )
#include "proto3/echo_service.pb.h"
#else
#include "proto2/echo_service.pb.h"
#endif

bool WebServlet(const sofa::pbrpc::HTTPRequest& request, sofa::pbrpc::HTTPResponse& response)
{
Expand Down
12 changes: 10 additions & 2 deletions sample/mock_sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ else
endif
endif

PROTO_SRC=echo_service.proto
#-----------------------------------------------
# Customized macro switch:
# SOFA_PBRPC_USE_PROTO3 : use proto3 version of the protocol buffers language
ifeq ($(PROTO_VERSION),proto3)
CXXFLAGS += -DSOFA_PBRPC_USE_PROTO3
endif
#-----------------------------------------------

PROTO_SRC=$(PROTO_VERSION)/echo_service.proto
PROTO_OBJ=$(patsubst %.proto,%.pb.o,$(PROTO_SRC))
PROTO_OPTIONS=--proto_path=. --proto_path=$(SOFA_PBRPC)/include --proto_path=$(PROTOBUF_DIR)/include

Expand All @@ -66,7 +74,7 @@ check_depends:
@if [ ! -f "$(GTEST_DIR)/src/gtest-all.cc" ]; then echo "ERROR: need gtest"; exit 1; fi

clean:
@rm -f $(BIN) *.o *.pb.* libgtest.a
@rm -f $(BIN) *.o $(PROTO_VERSION)/*.pb.* libgtest.a

rebuild: clean all

Expand Down
7 changes: 6 additions & 1 deletion sample/mock_sample/mock_test_sample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#include <sofa/pbrpc/mock_test_helper.h>
#include <gtest/gtest.h>
#include <unistd.h>
#include "echo_service.pb.h"

#if defined ( SOFA_PBRPC_USE_PROTO3 )
#include "proto3/echo_service.pb.h"
#else
#include "proto2/echo_service.pb.h"
#endif

using namespace ::sofa::pbrpc;
using namespace ::sofa::pbrpc::test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
syntax = "proto2";

package sofa.pbrpc.test;

option cc_generic_services = true;
Expand Down
17 changes: 17 additions & 0 deletions sample/mock_sample/proto3/echo_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";

package sofa.pbrpc.test;

option cc_generic_services = true;

message EchoRequest {
string message = 1;
}

message EchoResponse {
string message = 1;
}

service EchoServer {
rpc Echo(EchoRequest) returns(EchoResponse);
}
12 changes: 10 additions & 2 deletions sample/multi_server_sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ else
endif
endif

PROTO_SRC=echo_service.proto
#-----------------------------------------------
# Customized macro switch:
# SOFA_PBRPC_USE_PROTO3 : use proto3 version of the protocol buffers language
ifeq ($(PROTO_VERSION),proto3)
CXXFLAGS += -DSOFA_PBRPC_USE_PROTO3
endif
#----------------------------------------------

PROTO_SRC=$(PROTO_VERSION)/echo_service.proto
PROTO_OBJ=$(patsubst %.proto,%.pb.o,$(PROTO_SRC))
PROTO_OPTIONS=--proto_path=. --proto_path=$(SOFA_PBRPC)/include --proto_path=$(PROTOBUF_DIR)/include

Expand All @@ -64,7 +72,7 @@ check_depends:
@if [ ! -f "$(SOFA_PBRPC)/lib/libsofa-pbrpc.a" ]; then echo "ERROR: need sofa-pbrpc lib"; exit 1; fi

clean:
@rm -f $(BIN) *.o *.pb.*
@rm -f $(BIN) *.o $(PROTO_VERSION)/*.pb.*

rebuild: clean all

Expand Down
7 changes: 6 additions & 1 deletion sample/multi_server_sample/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
#include <set>

#include <sofa/pbrpc/pbrpc.h>
#include "echo_service.pb.h"

#if defined ( SOFA_PBRPC_USE_PROTO3 )
#include "proto3/echo_service.pb.h"
#else
#include "proto2/echo_service.pb.h"
#endif

class ReloadableAddressProvider : public sofa::pbrpc::RpcChannel::AddressProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
syntax = "proto2";

package sofa.pbrpc.test;

option cc_generic_services = true;
Expand Down
18 changes: 18 additions & 0 deletions sample/multi_server_sample/proto3/echo_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package sofa.pbrpc.test;

option cc_generic_services = true;
option java_generic_services = true;

message EchoRequest {
string message = 1;
}

message EchoResponse {
string message = 1;
}

service EchoServer {
rpc Echo(EchoRequest) returns(EchoResponse);
}
7 changes: 6 additions & 1 deletion sample/multi_server_sample/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#include <signal.h>
#include <unistd.h>
#include <sofa/pbrpc/pbrpc.h>
#include "echo_service.pb.h"

#if defined ( SOFA_PBRPC_USE_PROTO3 )
#include "proto3/echo_service.pb.h"
#else
#include "proto2/echo_service.pb.h"
#endif

class EchoServerImpl : public sofa::pbrpc::test::EchoServer
{
Expand Down
Loading