Commit 8bfe9602 authored by Robert Edmonds's avatar Robert Edmonds Committed by GitHub

Merge pull request #221 from protobuf-c/issue220

protoc-c/c_message.cc: Force int size on oneof enums
parents 651ec8f5 bb6553c3
......@@ -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");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment