Chromium Code Reviews| Index: components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc |
| diff --git a/components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc b/components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc |
| index 2165673b362eeefc3bbb110ca2e0be0fa6aac01c..e15dd8d6f7e1d5f7f02191bc42dd18b8a2af753d 100644 |
| --- a/components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc |
| +++ b/components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc |
| @@ -93,6 +93,14 @@ class GeneratorJob { |
| return name; |
| } |
| + template <class T> |
| + inline std::string GetCamelCaseName(const T* descriptor, bool capitalize) { |
|
Primiano Tucci (use gerrit)
2016/08/05 11:34:18
looks like capitalize is always = true.
Unless you
|
| + std::string camel_name = descriptor->camelcase_name(); |
| + if (capitalize && !camel_name.empty()) |
| + camel_name.at(0) = toupper(camel_name.at(0)); |
| + return camel_name; |
| + } |
| + |
| // Small enums can be written faster without involving VarInt encoder. |
| inline bool IsTinyEnumField(const FieldDescriptor* field) { |
| if (field->type() != FieldDescriptor::TYPE_ENUM) |
| @@ -463,7 +471,29 @@ class GeneratorJob { |
| } |
| } |
| - // Fields descriptors. |
| + // Field numbers. |
| + if (message->field_count() > 0) { |
| + stub_h_->Print("enum : int32_t {\n"); |
| + stub_h_->Indent(); |
| + |
| + for (int i = 0; i < message->field_count(); ++i) { |
| + const FieldDescriptor* field = message->field(i); |
| + std::string name = GetCamelCaseName(field, true); |
| + if (name.empty()) { |
| + // Protoc allows fields like: 'bool _ = 1'. |
| + Abort("Empty field name in camel case notation."); |
|
Primiano Tucci (use gerrit)
2016/08/05 11:34:18
lol, TIL
|
| + } |
| + |
| + stub_h_->Print( |
| + "k$name$FieldNumber = $id$,\n", |
| + "name", name, |
| + "id", std::to_string(field->number())); |
| + } |
| + stub_h_->Outdent(); |
| + stub_h_->Print("};\n"); |
| + } |
| + |
| + // Field descriptors. |
| for (int i = 0; i < message->field_count(); ++i) { |
| const FieldDescriptor* field = message->field(i); |
| if (field->is_packed()) { |