Skip to content

Commit a00c177

Browse files
committed
Remove protobuf dependency, its not needed / used and brings in too much baggage
Signed-off-by: Rob Ambalu <robert.ambalu@point72.com>
1 parent ad075a0 commit a00c177

17 files changed

+21
-662
lines changed

conda/dev-environment-unix.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ dependencies:
2020
- libarrow=16
2121
- libboost>=1.80.0
2222
- libboost-headers>=1.80.0
23-
- libprotobuf
2423
- librdkafka
2524
- lz4-c
2625
- mamba

conda/dev-environment-win.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ dependencies:
1818
- libarrow=16
1919
- libboost>=1.80.0
2020
- libboost-headers>=1.80.0
21-
- libprotobuf
2221
- librdkafka
2322
- lz4-c
2423
- make

cpp/csp/adapters/kafka/KafkaPublisher.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,11 @@ KafkaPublisher::KafkaPublisher( KafkaAdapterManager * mgr, const Dictionary & pr
1414
m_topic( std::move( topic ) )
1515

1616
{
17-
utils::MsgProtocol protocol = utils::MsgProtocol( properties.get<std::string>( "protocol" ) );
18-
switch( protocol )
19-
{
20-
case utils::MsgProtocol::JSON:
21-
m_msgWriter = std::make_shared<utils::JSONMessageWriter>( properties );
22-
break;
23-
24-
case utils::MsgProtocol::RAW_BYTES:
25-
break;
26-
27-
default:
28-
CSP_THROW( NotImplemented, "msg protocol " << protocol << " not currently supported for kafka output adapters" );
29-
break;
30-
}
17+
auto protocol = properties.get<std::string>( "protocol" );
18+
if( protocol == "JSON" )
19+
m_msgWriter = std::make_shared<utils::JSONMessageWriter>( properties );
20+
else if( protocol != "RAW_BYTES" )
21+
CSP_THROW( NotImplemented, "msg protocol " << protocol << " not currently supported for kafka output adapters" );
3122
}
3223

3324
KafkaPublisher::~KafkaPublisher()

cpp/csp/adapters/utils/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ set(ADAPTER_UTILS_PUBLIC_HEADERS
44
MessageEnums.h
55
MessageWriter.h
66
MessageStructConverter.h
7-
ProtobufHelper.h
8-
ProtobufMessageStructConverter.h
97
RawBytesMessageStructConverter.h
108
StructAdapterInfo.h
119
ValueDispatcher.h
@@ -16,23 +14,12 @@ set(ADAPTER_UTILS_FILES
1614
MessageWriter.cpp
1715
MessageEnums.cpp
1816
MessageStructConverter.cpp
19-
ProtobufHelper.cpp
20-
ProtobufMessageStructConverter.cpp
2117
RawBytesMessageStructConverter.cpp
2218
)
23-
# See https://github.com/Point72/csp/issues/454
24-
if(WIN32)
25-
set(CSP_LIB_TYPE STATIC)
26-
else()
27-
set(CSP_LIB_TYPE SHARED)
28-
endif()
2919

30-
add_library(csp_adapter_utils ${CSP_LIB_TYPE} ${ADAPTER_UTILS_FILES})
20+
add_library(csp_adapter_utils STATIC ${ADAPTER_UTILS_FILES})
3121
set_target_properties(csp_adapter_utils PROPERTIES PUBLIC_HEADER "${ADAPTER_UTILS_PUBLIC_HEADERS}" PREFIX lib)
3222

33-
find_package(Protobuf REQUIRED)
34-
target_link_libraries(csp_adapter_utils PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
35-
3623
install(TARGETS csp_adapter_utils
3724
PUBLIC_HEADER DESTINATION include/csp/adapters/utils
3825
RUNTIME DESTINATION ${CSP_RUNTIME_INSTALL_SUBDIR}

cpp/csp/adapters/utils/JSONMessageStructConverter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class JSONMessageStructConverter: public MessageStructConverter
1919

2020
csp::StructPtr asStruct( void * bytes, size_t size ) final;
2121

22-
MsgProtocol protocol() const override { return MsgProtocol::JSON; }
23-
2422
static MessageStructConverter * create( const CspTypePtr & type, const Dictionary & properties )
2523
{
2624
return new JSONMessageStructConverter( type, properties );

cpp/csp/adapters/utils/JSONMessageWriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class JSONMessageWriter : public MessageWriter
3838
csp::CspType::Type::STRING
3939
>;
4040

41-
JSONMessageWriter( const Dictionary & properties ) : MessageWriter( MsgProtocol::JSON )
41+
JSONMessageWriter( const Dictionary & properties )
4242
{
4343
m_doc.SetObject();
4444
m_datetimeWireType = utils::DateTimeWireType( properties.get<std::string>( "datetime_type" ) );

cpp/csp/adapters/utils/MessageEnums.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,4 @@ INIT_CSP_ENUM( csp::adapters::utils::DateTimeWireType,
1111
"UINT64_SECONDS"
1212
);
1313

14-
INIT_CSP_ENUM( csp::adapters::utils::MsgProtocol,
15-
"UNKNOWN",
16-
"JSON",
17-
"PROTOBUF",
18-
"RAW_BYTES"
19-
);
20-
2114
}

cpp/csp/adapters/utils/MessageEnums.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,6 @@ struct DateTimeWireTypeTraits
2525

2626
using DateTimeWireType = csp::Enum<DateTimeWireTypeTraits>;
2727

28-
//Note this should match enum defined in python
29-
struct MsgProtocolTraits
30-
{
31-
enum _enum : unsigned char
32-
{
33-
UNKNOWN = 0,
34-
JSON = 1,
35-
PROTOBUF = 2,
36-
RAW_BYTES = 3,
37-
NUM_TYPES
38-
};
39-
40-
protected:
41-
_enum m_value;
42-
};
43-
44-
using MsgProtocol = csp::Enum<MsgProtocolTraits>;
45-
4628
};
4729

4830
#endif

cpp/csp/adapters/utils/MessageStructConverter.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <csp/adapters/utils/MessageStructConverter.h>
22
#include <csp/adapters/utils/JSONMessageStructConverter.h>
3-
#include <csp/adapters/utils/ProtobufMessageStructConverter.h>
43
#include <csp/adapters/utils/RawBytesMessageStructConverter.h>
54

65
namespace csp::adapters::utils
@@ -14,14 +13,13 @@ MessageStructConverter::MessageStructConverter( const CspTypePtr & type, const D
1413

1514
MessageStructConverterCache::MessageStructConverterCache()
1615
{
17-
registerConverter( MsgProtocol::RAW_BYTES, &RawBytesMessageStructConverter::create );
18-
registerConverter( MsgProtocol::JSON, &JSONMessageStructConverter::create );
19-
registerConverter( MsgProtocol::PROTOBUF, &ProtobufMessageStructConverter::create );
16+
registerConverter( "RAW_BYTES", &RawBytesMessageStructConverter::create );
17+
registerConverter( "JSON", &JSONMessageStructConverter::create );
2018
}
2119

22-
bool MessageStructConverterCache::registerConverter( MsgProtocol protocol, Creator creator )
20+
bool MessageStructConverterCache::registerConverter( std::string protocol, Creator creator )
2321
{
24-
if( m_creators[ protocol ] )
22+
if( m_creators.find( protocol ) != m_creators.end() )
2523
CSP_THROW( RuntimeException, "Attempted to register creator for MessageStructConverter type " << protocol << " more than once" );
2624

2725
m_creators[ protocol ] = creator;
@@ -42,12 +40,12 @@ MessageStructConverterPtr MessageStructConverterCache::create( const CspTypePtr
4240
if( !rv.second )
4341
return rv.first -> second;
4442

45-
auto protocol = MsgProtocol( properties.get<std::string>( "protocol" ) );
46-
auto creator = m_creators[ protocol ];
47-
if( !creator )
43+
auto protocol = properties.get<std::string>( "protocol" );
44+
auto creatorIt = m_creators.find( protocol );
45+
if( creatorIt == m_creators.end() )
4846
CSP_THROW( ValueError, "MessageStructConverter for type " << protocol << " is not defined" );
4947

50-
auto result = std::shared_ptr<MessageStructConverter>( creator( type, properties ) );
48+
auto result = std::shared_ptr<MessageStructConverter>( creatorIt -> second( type, properties ) );
5149
rv.first -> second = result;
5250
return rv.first -> second;
5351
}

cpp/csp/adapters/utils/MessageStructConverter.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <memory>
1010
#include <mutex>
1111
#include <string>
12+
#include <unordered_map>
1213

1314
namespace csp::adapters::utils
1415
{
@@ -21,8 +22,6 @@ class MessageStructConverter
2122

2223
virtual csp::StructPtr asStruct( void * bytes, size_t size ) = 0;
2324

24-
virtual MsgProtocol protocol() const = 0;
25-
2625
StructMetaPtr structMeta() { return m_structMeta; }
2726

2827
protected:
@@ -51,15 +50,15 @@ class MessageStructConverterCache
5150

5251
using Creator = std::function<MessageStructConverter*( const CspTypePtr &, const Dictionary & )>;
5352

54-
bool registerConverter( MsgProtocol protocol, Creator creator );
53+
bool registerConverter( std::string protocol, Creator creator );
5554

5655
private:
5756
using CacheKey = std::pair<const CspType*,Dictionary>;
5857
using Cache = std::unordered_map<CacheKey,MessageStructConverterPtr,csp::hash::hash_pair>;
5958

60-
std::mutex m_cacheMutex;
61-
Cache m_cache;
62-
Creator m_creators[ MsgProtocol::NUM_TYPES ];
59+
std::unordered_map<std::string,Creator> m_creators;
60+
std::mutex m_cacheMutex;
61+
Cache m_cache;
6362
};
6463

6564
}

0 commit comments

Comments
 (0)