Skip to content

Commit

Permalink
Switch from DownCastToGenerated to DownCastMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybuka committed Jun 16, 2024
1 parent 72dc799 commit 4084aec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
23 changes: 17 additions & 6 deletions port/protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,36 @@
// clang-format off
#include "google/protobuf/port_def.inc" // MUST be last header included
// clang-format on
#if PROTOBUF_VERSION < 4025000

namespace google {
namespace protobuf {
#if PROTOBUF_VERSION < 4025000

template <typename T>
const T* DownCastToGenerated(const Message* message) {
const T* DownCastMessage(const Message* message) {
return static_cast<const T*>(message);
}

template <typename T>
T* DownCastToGenerated(Message* message) {
T* DownCastMessage(Message* message) {
const Message* message_const = message;
return const_cast<T*>(DownCastToGenerated<T>(message_const));
return const_cast<T*>(DownCastMessage<T>(message_const));
}

#elif PROTOBUF_VERSION < 5029000

template <typename T>
const T* DownCastMessage(const Message* message) {
return DownCastToGenerated<T>(message);
}

template <typename T>
T* DownCastMessage(Message* message) {
return DownCastToGenerated<T>(message);
}

#endif // PROTOBUF_VERSION
} // namespace protobuf
} // namespace google
#endif // PROTOBUF_VERSION
#include "google/protobuf/port_undef.inc"


Expand Down
2 changes: 1 addition & 1 deletion src/libfuzzer/libfuzzer_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct PostProcessorRegistration {
RegisterPostProcessor(
Proto::descriptor(),
[callback](protobuf::Message* message, unsigned int seed) {
callback(protobuf::DownCastToGenerated<Proto>(message), seed);
callback(protobuf::DownCastMessage<Proto>(message), seed);
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/mutator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,13 @@ std::unique_ptr<Message> UnpackAny(const Any& any) {

const Any* CastToAny(const Message* message) {
return Any::GetDescriptor() == message->GetDescriptor()
? protobuf::DownCastToGenerated<Any>(message)
? protobuf::DownCastMessage<Any>(message)
: nullptr;
}

Any* CastToAny(Message* message) {
return Any::GetDescriptor() == message->GetDescriptor()
? protobuf::DownCastToGenerated<Any>(message)
? protobuf::DownCastMessage<Any>(message)
: nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions src/mutator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace protobuf_mutator {

using protobuf::DownCastToGenerated;
using protobuf::DownCastMessage;
using protobuf::util::MessageDifferencer;
using testing::TestWithParam;
using testing::ValuesIn;
Expand Down Expand Up @@ -623,7 +623,7 @@ TYPED_TEST(MutatorTypedTest, RegisterPostProcessor) {
TestFixture::Message::descriptor(),
[=](protobuf::Message* message, unsigned int seed) {
auto test_message =
DownCastToGenerated<typename TestFixture::Message>(message);
DownCastMessage<typename TestFixture::Message>(message);
if (seed % 2) test_message->set_optional_string(v);
});
}
Expand Down

0 comments on commit 4084aec

Please sign in to comment.