Skip to content

Commit

Permalink
[dependencies] Add Protobuf 3.26 support to eCAL. (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstinKeller authored Apr 16, 2024
1 parent 578a10e commit 05c9cfc
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
target: 'desktop'

- name: Install Dependencies
run: brew install ninja doxygen graphviz protobuf@21 [email protected] pkg-config
run: brew install ninja doxygen graphviz protobuf [email protected] pkg-config

- name: Install Cap’n Proto
run: |
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
-DECAL_THIRDPARTY_BUILD_QWT=ON \
-DECAL_THIRDPARTY_BUILD_YAML-CPP=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="/usr/local/opt/[email protected]:/usr/local/opt/protobuf@21" \
-DCMAKE_PREFIX_PATH=/usr/local/opt/[email protected] \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
-DPython_FIND_STRATEGY=LOCATION \
Expand Down
100 changes: 92 additions & 8 deletions contrib/ecalproto/src/ecal_proto_dyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,113 @@
#include <sstream>
#include <fstream>

#include <google/protobuf/stubs/common.h>

namespace eCAL
{
namespace protobuf
{
#if GOOGLE_PROTOBUF_VERSION >= 5026000
class ParserErrorCollector : public google::protobuf::io::ErrorCollector
{
public:
ParserErrorCollector() = default;
~ParserErrorCollector() override = default;

std::string Get() { return(m_ss.str()); }

// Indicates that there was an error in the input at the given line and
// column numbers. The numbers are zero-based, so you may want to add
// 1 to each before printing them.
void RecordError(int line_,
google::protobuf::io::ColumnNumber column_,
absl::string_view message_) override
{
Add(line_, column_, "ERROR", message_);
}

// Indicates that there was a warning in the input at the given line and
// column numbers. The numbers are zero-based, so you may want to add
// 1 to each before printing them.
void RecordWarning(int line_,
google::protobuf::io::ColumnNumber column_,
absl::string_view message_) override
{
Add(line_, column_, "WARNING: ", message_);
}

private:
void Add(int line_, google::protobuf::io::ColumnNumber column_, const std::string& type_, absl::string_view message_)
{
m_ss << line_ << ":" << column_ << " " << type_ << ": " << message_ << std::endl;
}

std::stringstream m_ss;
};

class DescriptorErrorCollector : public google::protobuf::DescriptorPool::ErrorCollector
{
public:
DescriptorErrorCollector() = default;
~DescriptorErrorCollector() override {}

std::string Get() { return(m_ss.str()); }

void RecordError(absl::string_view filename,
absl::string_view element_name,
const google::protobuf::Message* descriptor,
ErrorLocation location,
absl::string_view message) override
{
Add(filename, element_name, descriptor, location, "ERROR", message);
}

void RecordWarning(absl::string_view filename,
absl::string_view element_name,
const google::protobuf::Message* descriptor,
ErrorLocation location,
absl::string_view message) override
{
Add(filename, element_name, descriptor, location, "WARNING", message);
}

private:
void Add(
absl::string_view filename,
absl::string_view element_name,
const google::protobuf::Message* /*descriptor*/,
ErrorLocation location,
const std::string& type,
absl::string_view message
)
{
m_ss << filename << " " << element_name << " " << location << " " << type << ": " << message << std::endl;
}

std::stringstream m_ss;
};

#else
class ParserErrorCollector : public google::protobuf::io::ErrorCollector
{
public:
ParserErrorCollector() {}
~ParserErrorCollector() {}
ParserErrorCollector() = default;
~ParserErrorCollector() override = default;

std::string Get() { return(m_ss.str()); }

// Indicates that there was an error in the input at the given line and
// column numbers. The numbers are zero-based, so you may want to add
// 1 to each before printing them.
void AddError(int line_, int column_, const std::string& msg_)
void AddError(int line_, int column_, const std::string& msg_) override
{
Add(line_, column_, "ERROR: " + msg_);
}

// Indicates that there was a warning in the input at the given line and
// column numbers. The numbers are zero-based, so you may want to add
// 1 to each before printing them.
void AddWarning(int line_, int column_, const std::string& msg_)
void AddWarning(int line_, int column_, const std::string& msg_) override
{
Add(line_, column_, "WARNING: " + msg_);
}
Expand All @@ -69,8 +151,8 @@ namespace protobuf
class DescriptorErrorCollector : public google::protobuf::DescriptorPool::ErrorCollector
{
public:
DescriptorErrorCollector() {}
~DescriptorErrorCollector() {}
DescriptorErrorCollector() = default;
~DescriptorErrorCollector() override {}

std::string Get() { return(m_ss.str()); }

Expand All @@ -80,7 +162,7 @@ namespace protobuf
const google::protobuf::Message* descriptor, // Descriptor of the erroneous element.
ErrorLocation location, // One of the location constants, above.
const std::string& message // Human-readable error message.
)
) override
{
Add(filename, element_name, descriptor, location, "ERROR: " + message);
}
Expand All @@ -91,7 +173,7 @@ namespace protobuf
const google::protobuf::Message* descriptor, // Descriptor of the erroneous element.
ErrorLocation location, // One of the location constants, above.
const std::string& message // Human-readable error message.
)
) override
{
Add(filename, element_name, descriptor, location, "WARNING: " + message);
}
Expand All @@ -110,6 +192,8 @@ namespace protobuf

std::stringstream m_ss;
};
#endif


google::protobuf::Message* CProtoDynDecoder::GetProtoMessageFromFile(const std::string& proto_filename_, const std::string& msg_type_, std::string& error_s_)
{
Expand Down
7 changes: 6 additions & 1 deletion ecal/core/src/pubsub/ecal_proto_dyn_json_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/type_resolver_util.h>
#include <google/protobuf/util/type_resolver.h>
Expand Down Expand Up @@ -156,7 +157,11 @@ namespace eCAL
{

google::protobuf::util::JsonOptions options;
options.always_print_primitive_fields = true;
#if GOOGLE_PROTOBUF_VERSION >= 5026000
options.always_print_fields_with_no_presence = true;
#else
options.always_print_primitive_fields = true;
#endif

std::string binary_input;
binary_input.assign((char*)data_->buf, static_cast<size_t>(data_->size));
Expand Down

0 comments on commit 05c9cfc

Please sign in to comment.