mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-26 21:04:23 +08:00
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
66574f3fd8
but continues to support older versions of protobuf.
Unfortunately, since this is a "deprecated", "legacy" API it'll probably
disappear in about five seconds.
This commit is contained in:
parent
23d2246e0f
commit
1937ba946b
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user