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

[dependencies] Add Protobuf 3.26 support to eCAL. #1530

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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/port_def.inc"

namespace eCAL
{
namespace protobuf
{
#if 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 {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use '= default' to define a trivial destructor [modernize-use-equals-default]

Suggested change
~DescriptorErrorCollector() override {}
~DescriptorErrorCollector() override = default;


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
Loading