Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc

Issue 2217703002: Tracing V2: Field number constants for protobuf plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reinvented wheel removed Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/tracing/test/proto_zero_generation_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()) {
« no previous file with comments | « components/tracing/test/proto_zero_generation_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698