Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

serialization: completely remove protobuf support #161

Merged
merged 9 commits into from
Sep 20, 2018
Merged
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
27 changes: 1 addition & 26 deletions bin/dsn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,6 @@ macro(ms_find_source_files SOURCE_DIR GLOB_OPTION PROJ_SRC)
set(${PROJ_SRC} ${${PROJ_SRC}} ${TEMP_PROJ_SRC})
endmacro(ms_find_source_files)

macro(dsn_setup_serialization)
set(USE_THRIFT TRUE)
set(USE_PROTOBUF FALSE)
foreach(IDL ${MY_SERIALIZATION_TYPE})
if (${IDL} STREQUAL "thrift")
set(USE_THRIFT TRUE)
elseif (${IDL} STREQUAL "protobuf")
set(USE_PROTOBUF TRUE)
endif ()
endforeach()
if (USE_THRIFT)
list(APPEND MY_PROJ_LIBS thrift)
add_definitions(-DDSN_USE_THRIFT_SERIALIZATION)
add_definitions(-DDSN_ENABLE_THRIFT_RPC)
endif ()
if (USE_PROTOBUF)
list(APPEND MY_PROJ_LIBS protobuf.a)
add_definitions(-DDSN_USE_PROTOBUF_SERIALIZATION)
endif ()
endmacro(dsn_setup_serialization)

function(dsn_add_project)
if((NOT DEFINED MY_PROJ_TYPE) OR (MY_PROJ_TYPE STREQUAL ""))
message(FATAL_ERROR "MY_PROJ_TYPE is empty.")
Expand Down Expand Up @@ -190,9 +169,6 @@ function(dsn_add_project)
set(MY_DO_INSTALL TRUE)
endif()
endif()
if(NOT DEFINED MY_SERIALIZATION_TYPE)
set(MY_SERIALIZATION_TYPE "")
endif()

set(MY_BOOST_LIBS "")
if(NOT (MY_BOOST_PACKAGES STREQUAL ""))
Expand All @@ -213,7 +189,7 @@ function(dsn_add_project)
endif()
endif()

dsn_setup_serialization()
list(APPEND MY_PROJ_LIBS thrift)

if(DEFINED DSN_DEBUG_CMAKE)
message(STATUS "MY_PROJ_TYPE = ${MY_PROJ_TYPE}")
Expand All @@ -226,7 +202,6 @@ function(dsn_add_project)
message(STATUS "MY_PROJ_BINPLACES = ${MY_PROJ_BINPLACES}")
message(STATUS "MY_PROJ_BINDIRS = ${MY_PROJ_BINDIRS}")
message(STATUS "MY_DO_INSTALL = ${MY_DO_INSTALL}")
message(STATUS "MY_SERIALIZATION_TYPE = ${MY_SERIALIZATION_TYPE}")
message(STATUS "MY_BOOST_PACKAGES = ${MY_BOOST_PACKAGES}")
message(STATUS "MY_BOOST_LIBS = ${MY_BOOST_LIBS}")
endif()
Expand Down
15 changes: 0 additions & 15 deletions compile_thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,6 @@ def fix_include(thrift_name, include_fix_dict):

os.chdir("..")

def toggle_serialization_in_cpp(thrift_name):
# current dir is thrift file dir
os.chdir("output")
cpp_file = thrift_name + "_types.cpp"
new_file = cpp_file + ".swapfile"

os.system("pwd")
os.system("echo \"#ifdef DSN_USE_THRIFT_SERIALIZATION\" > %s"%(new_file) )
os.system("cat %s >> %s"%(cpp_file, new_file))
os.system("echo \"#endif\" >> %s"%(new_file) )

os.remove(cpp_file)
os.rename(new_file, cpp_file)
os.chdir("..")

def compile_thrift_file(thrift_info):
thrift_name = thrift_info["name"]
print ">>>compiling thrift file %s.thrift ..."%(thrift_name)
Expand Down
104 changes: 28 additions & 76 deletions include/dsn/cpp/serialization.h
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#pragma once

#include <dsn/utility/utils.h>
#include <dsn/tool-api/rpc_address.h>
#include <dsn/cpp/rpc_stream.h>

#ifdef DSN_USE_THRIFT_SERIALIZATION
#include <dsn/cpp/serialization_helper/thrift_helper.h>
#endif

#ifdef DSN_USE_PROTOBUF_SERIALIZATION
#include <dsn/cpp/serialization_helper/protobuf_helper.h>
#endif
namespace dsn {
namespace serialization {

template <typename T>
std::string no_registered_function_error_notice(const T &t, dsn_msg_serialize_format fmt)
{
Expand All @@ -61,9 +47,8 @@ std::string no_registered_function_error_notice(const T &t, dsn_msg_serialize_fo
ss << fmt << ".";
return ss.str();
}
}

#ifdef DSN_USE_THRIFT_SERIALIZATION
} // namespace serialization

#define THRIFT_MARSHALLER \
case DSF_THRIFT_BINARY: \
Expand Down Expand Up @@ -101,40 +86,6 @@ inline void unmarshall(binary_reader &reader, T &value, dsn_msg_serialize_format
dassert(false, serialization::no_registered_function_error_notice(value, fmt).c_str());
}
}
#else
#define THRIFT_MARSHALLER \
{ \
}
#define THRIFT_UNMARSHALLER \
{ \
}
#endif

#ifdef DSN_USE_PROTOBUF_SERIALIZATION
#define PROTOBUF_MARSHALLER \
case DSF_PROTOC_BINARY: \
marshall_protobuf_binary(writer, value); \
break; \
case DSF_PROTOC_JSON: \
marshall_protobuf_json(writer, value); \
break;

#define PROTOBUF_UNMARSHALLER \
case DSF_PROTOC_BINARY: \
unmarshall_protobuf_binary(reader, value); \
break; \
case DSF_PROTOC_JSON: \
unmarshall_protobuf_json(reader, value); \
break;

#else
#define PROTOBUF_MARSHALLER \
{ \
}
#define PROTOBUF_UNMARSHALLER \
{ \
}
#endif

#define GENERATED_TYPE_SERIALIZATION(GType, SerializationType) \
inline void marshall(binary_writer &writer, const GType &value, dsn_msg_serialize_format fmt) \
Expand Down Expand Up @@ -174,4 +125,5 @@ inline void unmarshall(dsn::message_ex *msg, /*out*/ T &val)
::dsn::rpc_read_stream reader(msg);
unmarshall(reader, val, (dsn_msg_serialize_format)msg->header->context.u.serialize_format);
}
}

} // namespace dsn
143 changes: 0 additions & 143 deletions include/dsn/cpp/serialization_helper/protobuf_helper.h

This file was deleted.

8 changes: 2 additions & 6 deletions include/dsn/tool-api/gpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
#pragma once

#include <cstdint>

#ifdef DSN_USE_THRIFT_SERIALIZATION
#include <thrift/protocol/TProtocol.h>
#endif

namespace dsn {

Expand Down Expand Up @@ -68,10 +65,9 @@ class gpid

const char *to_string() const;

#ifdef DSN_USE_THRIFT_SERIALIZATION
// for serialization in thrift format
uint32_t read(::apache::thrift::protocol::TProtocol *iprot);
uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const;
#endif

int thread_hash() const { return _value.u.app_id * 7919 + _value.u.partition_index; }

Expand All @@ -98,4 +94,4 @@ struct hash<::dsn::gpid>
return static_cast<std::size_t>(pid.thread_hash());
}
};
}
} // namespace std
Loading