Skip to content

Commit

Permalink
[dependencies] Add Protobuf 3.26 support to eCAL.
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstinKeller committed Apr 16, 2024
1 parent 71a58a0 commit 2f67a1e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 10 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/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 {}

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

0 comments on commit 2f67a1e

Please sign in to comment.