summaryrefslogtreecommitdiff
path: root/tools/streaming_proto/cpp/main.cpp
diff options
context:
space:
mode:
authorYi Jin <jinyithu@google.com>2017-11-01 17:08:27 -0700
committerYi Jin <jinyithu@google.com>2017-11-10 17:34:07 -0800
commite2f7f79d023f0b3ba2fee374492dde61f525ece6 (patch)
tree8ea7efe3b552f1cb23c2f4c2ef379be6fb02f19b /tools/streaming_proto/cpp/main.cpp
parent9a753af26b2ce27c10ad215aa70cf1bcd44d7915 (diff)
Implement Cpu Info Section
Support carriage return in Read class, and add a new way to parse lines which is not able to split purly by delimiters Bug: 65642861 Test: unit test and on device test Change-Id: Ib82dd4e458bb7d2fa33462b23fbe11b828325916
Diffstat (limited to 'tools/streaming_proto/cpp/main.cpp')
-rw-r--r--tools/streaming_proto/cpp/main.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/tools/streaming_proto/cpp/main.cpp b/tools/streaming_proto/cpp/main.cpp
index 481698432711..9aef56270ee2 100644
--- a/tools/streaming_proto/cpp/main.cpp
+++ b/tools/streaming_proto/cpp/main.cpp
@@ -18,6 +18,12 @@ make_filename(const FileDescriptorProto& file_descriptor)
return file_descriptor.name() + ".h";
}
+static inline bool
+should_generate_enums_mapping(const EnumDescriptorProto& enu)
+{
+ return enu.options().GetExtension(stream_enum).enable_enums_mapping();
+}
+
static void
write_enum(stringstream& text, const EnumDescriptorProto& enu, const string& indent)
{
@@ -29,6 +35,23 @@ write_enum(stringstream& text, const EnumDescriptorProto& enu, const string& ind
<< make_constant_name(value.name())
<< " = " << value.number() << ";" << endl;
}
+
+ if (should_generate_enums_mapping(enu)) {
+ string name = make_constant_name(enu.name());
+ string prefix = name + "_";
+ text << indent << "const int _ENUM_" << name << "_COUNT = " << N << ";" << endl;
+ text << indent << "const char* _ENUM_" << name << "_NAMES[" << N << "] = {" << endl;
+ for (int i=0; i<N; i++) {
+ text << indent << INDENT << "\"" << stripPrefix(enu.value(i).name(), prefix) << "\"," << endl;
+ }
+ text << indent << "};" << endl;
+ text << indent << "const uint32_t _ENUM_" << name << "_VALUES[" << N << "] = {" << endl;
+ for (int i=0; i<N; i++) {
+ text << indent << INDENT << make_constant_name(enu.value(i).name()) << "," << endl;
+ }
+ text << indent << "};" << endl;
+ }
+
text << endl;
}
@@ -59,7 +82,7 @@ write_field(stringstream& text, const FieldDescriptorProto& field, const string&
static inline bool
should_generate_fields_mapping(const DescriptorProto& message)
{
- return message.options().GetExtension(stream).enable_fields_mapping();
+ return message.options().GetExtension(stream_msg).enable_fields_mapping();
}
static void