cho-m commented on issue #478:
URL: 
https://github.com/apache/pulsar-client-cpp/issues/478#issuecomment-3211207317

   A simple fix could be something like:
   ```diff
   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::StrCat`[^1]
   ```diff
   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);
    }
   ```
   
   [^1]: 
https://abseil.io/docs/cpp/guides/strings#abslstrcat-and-abslstrappend-for-string-concatenation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to