Skip to content

Commit

Permalink
Merge pull request #25002 from BenPope/schema_registry_unrollback-pro…
Browse files Browse the repository at this point in the history
…tobuf-v24.3.x

[CORE-8999] [v24.3.x] Revert "Schema Registry/protobuf: Remove support for editions."
  • Loading branch information
BenPope authored Feb 3, 2025
2 parents 83618d9 + 96c5eac commit ecec527
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/v/pandaproxy/schema_registry/protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ struct protobuf_schema_definition::impl {

void render_field(
std::ostream& os,
std::string_view edition,
pb::Edition edition,
const pb::FieldDescriptorProto& field,
const pb::FieldDescriptor* descriptor,
int indent,
Expand Down Expand Up @@ -848,7 +848,7 @@ struct protobuf_schema_definition::impl {
};

const auto label = [&]() {
bool is_proto2 = edition == "proto2";
bool is_proto2 = edition == pb::Edition::EDITION_PROTO2;
if(descriptor &&
(descriptor->is_map() || descriptor->real_containing_oneof() ||
((descriptor->is_optional() && !field.proto3_optional()) && !(is_proto2 && !descriptor->containing_oneof())))) {
Expand Down Expand Up @@ -978,7 +978,7 @@ struct protobuf_schema_definition::impl {
template<typename Descriptor>
void render_extensions(
std::ostream& os,
std::string_view edition,
pb::Edition edition,
const pb::RepeatedPtrField<pb::FieldDescriptorProto>& raw_extensions,
const Descriptor& descriptor,
int indent) const {
Expand Down Expand Up @@ -1116,7 +1116,7 @@ struct protobuf_schema_definition::impl {
// Render a message, including nested messages
void render_nested(
std::ostream& os,
std::string_view edition,
pb::Edition edition,
const std::optional<pb::FieldDescriptorProto>& field,
const pb::FieldDescriptor* field_descriptor,
const pb::DescriptorProto& message,
Expand Down Expand Up @@ -1584,9 +1584,18 @@ struct protobuf_schema_definition::impl {
std::ostream& os,
const pb::FileDescriptorProto& fdp,
const pb::FileDescriptor& descriptor) const {
auto syntax = fdp.has_syntax() ? fdp.syntax() : "proto2";
std::string_view edition = syntax;
fmt::print(os, "syntax = {};\n", pb_string_value(syntax));
auto edition = fdp.edition();
if (edition == pb::Edition::EDITION_UNKNOWN) {
auto syntax = fdp.has_syntax() ? fdp.syntax() : "proto2";
edition = syntax == "proto3" ? pb::Edition::EDITION_PROTO3
: pb::Edition::EDITION_PROTO2;
fmt::print(os, "syntax = {};\n", pb_string_value(syntax));
} else {
fmt::print(
os,
"edition = {};\n",
pb_string_value(Edition_Name(fdp.edition())));
}

if (fdp.has_package() && !fdp.package().empty()) {
fmt::print(os, "package {};\n", fdp.package());
Expand Down

0 comments on commit ecec527

Please sign in to comment.