[C++] Fix wrong Base64 paddings
@@ -54,12 +54,17 @@ SchemaInfo createProtobufNativeSchema(const google::protobuf::Descriptor* descri
std::string base64String{base64(bytes.data()), base64(bytes.data() + bytes.size())};
// Pulsar broker only supports decoding Base64 with padding so we need to add padding '=' here
const size_t numPadding = 4 - base64String.size() % 4;
+ if (numPadding <= 2) {
for (size_t i = 0; i < numPadding; i++) {
base64String.push_back('=');
}
+ } else if (numPadding == 3) {
+ // The length of encoded Base64 string (without padding) should not be 4N+1
+ throw std::runtime_error("Unexpected padding number (3), the encoded Base64 string is:\n" +
+ base64String);
+ } // else numPadding == 4, which means no padding characters need to be added
- const std::string schemaJson =
- R"({"fileDescriptorSet":")" + base64String +
+ const std::string schemaJson = R"({"fileDescriptorSet":")" + base64String +
R"(","rootMessageTypeName":")" + rootMessageTypeName +
R"(","rootFileDescriptorName":")" + rootFileDescriptorName + R"("})";
