mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2025-01-14 01:07:57 +08:00
Merge pull request #221 from protobuf-c/issue220
protoc-c/c_message.cc: Force int size on oneof enums
This commit is contained in:
commit
8bfe960293
@ -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");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user