Skip to content

Commit

Permalink
Fixed bug in generator for nested enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Jan 8, 2017
1 parent ec7de49 commit dbebbf2
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/generator/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,23 +725,23 @@ namespace protobluff {
const EnumDescriptor *descriptor = descriptor_->enum_type();
for (size_t v = 0; v < descriptor->value_count(); v++) {
const EnumValueDescriptor *value = descriptor->value(v);
map<string, string> variables (variables_);
map<string, string> enum_variables (variables);

/* Lowercase enum value name */
string name = value->name();
LowerString(&name);

/* Prepare accessor variables */
variables["field"] += "_" + name;
variables["value"] = "(const pb_enum_t []){ "
enum_variables["field"] += "_" + name;
enum_variables["value"] = "(const pb_enum_t []){ "
+ SimpleItoa(value->number()) +
" }";

/* Extract enum value signature */
variables["enum.signature"] = value->name();
enum_variables["enum.signature"] = value->name();

/* Generate accessors for enum value */
printer->Print(variables,
printer->Print(enum_variables,
"/* `signature` : has(`enum.signature`) */\n"
"`deprecated`"
"PB_INLINE int\n"
Expand All @@ -750,7 +750,8 @@ namespace protobluff {
" assert(pb_message_descriptor(message) == \n"
" &`message`_descriptor);\n"
" return pb_message_nested_match(message,\n"
" `tag`, `value`);\n"
" `tag`, \n"
" `value`);\n"
"}\n"
"\n"
"/* `signature` : put(`enum.signature`) */\n"
Expand All @@ -762,10 +763,10 @@ namespace protobluff {
" assert(pb_message_descriptor(message) == \n"
" &`message`_descriptor);\n"
" return pb_message_nested_put(message,\n"
" `tag`, `value`);\n"
" `tag`, \n"
" `value`);\n"
"}\n"
"\n");

}
}
}
Expand Down Expand Up @@ -845,4 +846,4 @@ namespace protobluff {
FieldComparator(const Field *x, const Field *y) {
return x->descriptor_->number() < y->descriptor_->number();
}
}
}

0 comments on commit dbebbf2

Please sign in to comment.