Commit 1937ba94 authored by Robert Edmonds's avatar Robert Edmonds

protoc-c: Use FileDescriptorLegacy to obtain proto syntax version on protobuf >= 23.0

Use the newer "legacy" way of determining whether a file descriptor is
using proto2 or proto3 syntax on protobuf >= 23.0.

Based on
https://github.com/protobuf-c/protobuf-c/pull/556/commits/66574f3fd85a205eb7c90b790477d5415364209e
but continues to support older versions of protobuf.

Unfortunately, since this is a "deprecated", "legacy" API it'll probably
disappear in about five seconds.
parent 23d2246e
......@@ -119,7 +119,11 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
int min_header_version = 1000000;
#if defined(HAVE_PROTO3)
# if GOOGLE_PROTOBUF_VERSION >= 4023000
if (FileDescriptorLegacy(file_).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3) {
# else
if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) {
#endif
min_header_version = 1003000;
}
#endif
......
......@@ -70,6 +70,10 @@
#include <protobuf-c/protobuf-c.pb.h>
#include <google/protobuf/io/printer.h>
#if GOOGLE_PROTOBUF_VERSION >= 4023000
# include <google/protobuf/descriptor_legacy.h>
#endif
namespace google {
namespace protobuf {
namespace compiler {
......@@ -172,7 +176,11 @@ int compare_name_indices_by_name(const void*, const void*);
// This wrapper is needed to be able to compile against protobuf2.
inline int FieldSyntax(const FieldDescriptor* field) {
#ifdef HAVE_PROTO3
# if GOOGLE_PROTOBUF_VERSION >= 4023000
return FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3 ? 3 : 2;
# else
return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? 3 : 2;
# endif
#else
return 2;
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment