Skip to content

[Bug] Build fails with Protobuf 30 from type changes #478

Closed

Description

@cho-m

Search before asking

  • I searched in the issues and found nothing similar.

Version

OS: macOS 15
Client: v3.7.0

Minimal reproduce step

Should be reproducible with any build attempt using Protobuf 30.0 (C++ 6.30.0) or later.

However, won't be able to use Vcpkg build yet as they only have Protobuf 29.3 (C++ 5.29.3).

What did you expect to see?

Successful build

What did you see instead?

lib/ProtobufNativeSchema.cc:42:23: error: no viable conversion from 'internal::DescriptorStringView' (aka 'basic_string_view<char>') to 'const std::string' (aka 'const basic_string<char>')
   42 |     const std::string rootMessageTypeName = descriptor->full_name();
      |                       ^                     ~~~~~~~~~~~~~~~~~~~~~~~

Anything else?

Caused by breaking change in protocolbuffers/protobuf@d1990d9

Should be possible to use explicit constructor for std::string instead and work for both Protobuf 30 and older compatibility. I think move constructor/assignment should avoid unnecessary copies for older Protobuf.

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. cho-m commented on Aug 21, 2025

    @cho-m
    Author

    A simple fix could be something like:

    diff --git a/lib/ProtobufNativeSchema.cc b/lib/ProtobufNativeSchema.cc
    index 632943d..cbcda43 100644
    --- a/lib/ProtobufNativeSchema.cc
    +++ b/lib/ProtobufNativeSchema.cc
    @@ -39,8 +39,13 @@ SchemaInfo createProtobufNativeSchema(const google::protobuf::Descriptor* descri
         }
     
         const auto fileDescriptor = descriptor->file();
    +#if GOOGLE_PROTOBUF_VERSION >= 6030000
    +    const std::string& rootMessageTypeName = std::string(descriptor->full_name());
    +    const std::string& rootFileDescriptorName = std::string(fileDescriptor->name());
    +#else
         const std::string& rootMessageTypeName = descriptor->full_name();
         const std::string& rootFileDescriptorName = fileDescriptor->name();
    +#endif
     
         FileDescriptorSet fileDescriptorSet;
         internalCollectFileDescriptors(fileDescriptor, fileDescriptorSet);

    Perhaps more efficient would be to pass absl::string_view to absl::StrCat1

    diff --git a/lib/ProtobufNativeSchema.cc b/lib/ProtobufNativeSchema.cc
    index 632943d..45c46ab 100644
    --- a/lib/ProtobufNativeSchema.cc
    +++ b/lib/ProtobufNativeSchema.cc
    @@ -19,6 +19,9 @@
     #include "pulsar/ProtobufNativeSchema.h"
     
     #include <google/protobuf/descriptor.pb.h>
    +#if GOOGLE_PROTOBUF_VERSION >= 6030000
    +#include <absl/strings/str_cat.h>
    +#endif
     
     #include <stdexcept>
     #include <vector>
    @@ -39,8 +42,8 @@ SchemaInfo createProtobufNativeSchema(const google::protobuf::Descriptor* descri
         }
     
         const auto fileDescriptor = descriptor->file();
    -    const std::string& rootMessageTypeName = descriptor->full_name();
    -    const std::string& rootFileDescriptorName = fileDescriptor->name();
    +    const auto& rootMessageTypeName = descriptor->full_name();
    +    const auto& rootFileDescriptorName = fileDescriptor->name();
     
         FileDescriptorSet fileDescriptorSet;
         internalCollectFileDescriptors(fileDescriptor, fileDescriptorSet);
    @@ -48,9 +51,15 @@ SchemaInfo createProtobufNativeSchema(const google::protobuf::Descriptor* descri
         std::vector<char> bytes(fileDescriptorSet.ByteSizeLong());
         fileDescriptorSet.SerializeToArray(bytes.data(), bytes.size());
     
    +#if GOOGLE_PROTOBUF_VERSION >= 6030000
    +    const std::string schemaJson = absl::StrCat(R"({"fileDescriptorSet":")", base64::encode(bytes),
    +                                                R"(","rootMessageTypeName":")", rootMessageTypeName,
    +                                                R"(","rootFileDescriptorName":")", rootFileDescriptorName, R"("})");
    +#else
         const std::string schemaJson = R"({"fileDescriptorSet":")" + base64::encode(bytes) +
                                        R"(","rootMessageTypeName":")" + rootMessageTypeName +
                                        R"(","rootFileDescriptorName":")" + rootFileDescriptorName + R"("})";
    +#endif
     
         return SchemaInfo(SchemaType::PROTOBUF_NATIVE, "", schemaJson);
     }

    Footnotes

    1. https://abseil.io/docs/cpp/guides/strings#abslstrcat-and-abslstrappend-for-string-concatenation ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions