Skip to content

Commit 9c985a3

Browse files
committed
Fix GOOGLE_PROTOBUF_VERSION comparisons
To check the feature: 1. checkout to the first commit where feature was available 2. find value of `GOOGLE_PROTOBUF_VERSION`, call it `V` 3. Use strict `(GOOGLE_PROTOBUF_VERSION > V)`, as there are commits where `GOOGLE_PROTOBUF_VERSION == V`, but features is not there yet.
1 parent cdc822f commit 9c985a3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

port/protobuf.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace google {
2929
namespace protobuf {
30-
#if GOOGLE_PROTOBUF_VERSION < 4025000
30+
#if GOOGLE_PROTOBUF_VERSION <= 4025000
3131

3232
template <typename T>
3333
const T* DownCastMessage(const Message* message) {
@@ -40,7 +40,7 @@ T* DownCastMessage(Message* message) {
4040
return const_cast<T*>(DownCastMessage<T>(message_const));
4141
}
4242

43-
#elif GOOGLE_PROTOBUF_VERSION < 5029000
43+
#elif GOOGLE_PROTOBUF_VERSION <= 5028000
4444

4545
template <typename T>
4646
const T* DownCastMessage(const Message* message) {
@@ -63,7 +63,7 @@ namespace protobuf = google::protobuf;
6363
inline bool RequiresUtf8Validation(
6464
const google::protobuf::FieldDescriptor& descriptor) {
6565
// commit d8c2501b43c1b56e3efa74048a18f8ce06ba07fe of >= v3.22.0
66-
#if GOOGLE_PROTOBUF_VERSION >= 4022000
66+
#if GOOGLE_PROTOBUF_VERSION > 3021005
6767
return descriptor.requires_utf8_validation();
6868
#else
6969
return descriptor.type() == google::protobuf::FieldDescriptor::TYPE_STRING &&
@@ -74,7 +74,7 @@ inline bool RequiresUtf8Validation(
7474

7575
inline bool HasPresence(const google::protobuf::FieldDescriptor& descriptor) {
7676
// commit bb30225f06c36399757dc698b409d5f79738e8d1 of >=3.12.0
77-
#if GOOGLE_PROTOBUF_VERSION >= 3012000
77+
#if GOOGLE_PROTOBUF_VERSION > 3011004
7878
return descriptor.has_presence();
7979
#else
8080
// NOTE: This mimics Protobuf 3.21.12 ("3021012")
@@ -89,20 +89,22 @@ inline bool HasPresence(const google::protobuf::FieldDescriptor& descriptor) {
8989

9090
inline void PrepareTextParser(google::protobuf::TextFormat::Parser& parser) {
9191
// commit d8c2501b43c1b56e3efa74048a18f8ce06ba07fe of >=3.8.0
92-
#if GOOGLE_PROTOBUF_VERSION >= 3008000
92+
#if GOOGLE_PROTOBUF_VERSION > 3006001
9393
parser.SetRecursionLimit(100);
94+
#endif
95+
#if GOOGLE_PROTOBUF_VERSION > 3007000
9496
parser.AllowUnknownField(true);
9597
#endif
9698
}
9799

98100
constexpr bool TextParserCanSetRecursionLimit() {
99101
// commit d8c2501b43c1b56e3efa74048a18f8ce06ba07fe of >=3.8.0
100-
return GOOGLE_PROTOBUF_VERSION >= 3008000;
102+
return GOOGLE_PROTOBUF_VERSION > 3006001;
101103
}
102104

103105
constexpr bool TextParserCanAllowUnknownField() {
104106
// commit 176f7db11d8242b36a3ea6abb1cc436fca5bf75d of >=3.8.0
105-
return GOOGLE_PROTOBUF_VERSION >= 3008000;
107+
return GOOGLE_PROTOBUF_VERSION > 3007000;
106108
}
107109

108110
} // namespace protobuf_mutator

0 commit comments

Comments
 (0)