diff --git a/protoc-c/c_message.cc b/protoc-c/c_message.cc index cb9584d..1c15aba 100644 --- a/protoc-c/c_message.cc +++ b/protoc-c/c_message.cc @@ -148,6 +148,7 @@ GenerateStructDefinition(io::Printer* printer) { } // Generate the case enums for unions + vars["opt_comma"] = ","; for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { const OneofDescriptor *oneof = descriptor_->oneof_decl(i); vars["oneofname"] = FullNameToUpper(oneof->name()); @@ -160,8 +161,13 @@ GenerateStructDefinition(io::Printer* printer) { const FieldDescriptor *field = oneof->field(j); vars["fieldname"] = FullNameToUpper(field->name()); vars["fieldnum"] = SimpleItoa(field->number()); - printer->Print(vars, "$ucclassname$__$oneofname$_$fieldname$ = $fieldnum$,\n"); + bool isLast = j == oneof->field_count() - 1; + if (isLast) { + vars["opt_comma"] = ""; + } + printer->Print(vars, "$ucclassname$__$oneofname$_$fieldname$ = $fieldnum$$opt_comma$\n"); } + printer->Print(vars, " PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE($ucclassname$)\n"); printer->Outdent(); printer->Print(vars, "} $foneofname$Case;\n\n"); }