Skip to content

Commit 4084aec

Browse files
committed
Switch from DownCastToGenerated to DownCastMessage
1 parent 72dc799 commit 4084aec

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

port/protobuf.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,36 @@
2727
// clang-format off
2828
#include "google/protobuf/port_def.inc" // MUST be last header included
2929
// clang-format on
30-
#if PROTOBUF_VERSION < 4025000
31-
3230
namespace google {
3331
namespace protobuf {
32+
#if PROTOBUF_VERSION < 4025000
3433

3534
template <typename T>
36-
const T* DownCastToGenerated(const Message* message) {
35+
const T* DownCastMessage(const Message* message) {
3736
return static_cast<const T*>(message);
3837
}
3938

4039
template <typename T>
41-
T* DownCastToGenerated(Message* message) {
40+
T* DownCastMessage(Message* message) {
4241
const Message* message_const = message;
43-
return const_cast<T*>(DownCastToGenerated<T>(message_const));
42+
return const_cast<T*>(DownCastMessage<T>(message_const));
43+
}
44+
45+
#elif PROTOBUF_VERSION < 5029000
46+
47+
template <typename T>
48+
const T* DownCastMessage(const Message* message) {
49+
return DownCastToGenerated<T>(message);
50+
}
51+
52+
template <typename T>
53+
T* DownCastMessage(Message* message) {
54+
return DownCastToGenerated<T>(message);
4455
}
4556

57+
#endif // PROTOBUF_VERSION
4658
} // namespace protobuf
4759
} // namespace google
48-
#endif // PROTOBUF_VERSION
4960
#include "google/protobuf/port_undef.inc"
5061

5162

src/libfuzzer/libfuzzer_macro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct PostProcessorRegistration {
119119
RegisterPostProcessor(
120120
Proto::descriptor(),
121121
[callback](protobuf::Message* message, unsigned int seed) {
122-
callback(protobuf::DownCastToGenerated<Proto>(message), seed);
122+
callback(protobuf::DownCastMessage<Proto>(message), seed);
123123
});
124124
}
125125
};

src/mutator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,13 @@ std::unique_ptr<Message> UnpackAny(const Any& any) {
381381

382382
const Any* CastToAny(const Message* message) {
383383
return Any::GetDescriptor() == message->GetDescriptor()
384-
? protobuf::DownCastToGenerated<Any>(message)
384+
? protobuf::DownCastMessage<Any>(message)
385385
: nullptr;
386386
}
387387

388388
Any* CastToAny(Message* message) {
389389
return Any::GetDescriptor() == message->GetDescriptor()
390-
? protobuf::DownCastToGenerated<Any>(message)
390+
? protobuf::DownCastMessage<Any>(message)
391391
: nullptr;
392392
}
393393

src/mutator_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
namespace protobuf_mutator {
3131

32-
using protobuf::DownCastToGenerated;
32+
using protobuf::DownCastMessage;
3333
using protobuf::util::MessageDifferencer;
3434
using testing::TestWithParam;
3535
using testing::ValuesIn;
@@ -623,7 +623,7 @@ TYPED_TEST(MutatorTypedTest, RegisterPostProcessor) {
623623
TestFixture::Message::descriptor(),
624624
[=](protobuf::Message* message, unsigned int seed) {
625625
auto test_message =
626-
DownCastToGenerated<typename TestFixture::Message>(message);
626+
DownCastMessage<typename TestFixture::Message>(message);
627627
if (seed % 2) test_message->set_optional_string(v);
628628
});
629629
}

0 commit comments

Comments
 (0)