diff options
Diffstat (limited to 'src/perfetto_cmd/pbtxt_to_pb.cc')
-rw-r--r-- | src/perfetto_cmd/pbtxt_to_pb.cc | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/src/perfetto_cmd/pbtxt_to_pb.cc b/src/perfetto_cmd/pbtxt_to_pb.cc index cdb7b7300..cc123a93c 100644 --- a/src/perfetto_cmd/pbtxt_to_pb.cc +++ b/src/perfetto_cmd/pbtxt_to_pb.cc @@ -21,16 +21,16 @@ #include "src/perfetto_cmd/pbtxt_to_pb.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" + +#include "perfetto/base/file_utils.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/file_utils.h" -#include "perfetto/ext/base/optional.h" -#include "perfetto/ext/base/string_utils.h" -#include "perfetto/ext/base/string_view.h" -#include "perfetto/ext/base/utils.h" +#include "perfetto/base/string_view.h" +#include "perfetto/base/utils.h" +#include "perfetto/common/descriptor.pb.h" #include "perfetto/protozero/message.h" #include "perfetto/protozero/message_handle.h" #include "perfetto/protozero/scattered_heap_buffer.h" -#include "protos/perfetto/common/descriptor.pb.h" #include "src/perfetto_cmd/perfetto_config.descriptor.h" namespace perfetto { @@ -41,6 +41,8 @@ using protos::EnumDescriptorProto; using protos::EnumValueDescriptorProto; using protos::FieldDescriptorProto; using protos::FileDescriptorSet; +using ::google::protobuf::io::ZeroCopyInputStream; +using ::google::protobuf::io::ArrayInputStream; namespace { @@ -306,18 +308,9 @@ class ParserDelegate { enum_value_number = enum_value.number(); break; } - if (!found_value) { - AddError(value, - "Unexpected value '$v' for enum field $k in " - "proto $n", - std::map<std::string, std::string>{ - {"$v", value.ToStdString()}, - {"$k", key.ToStdString()}, - {"$n", descriptor_name()}, - }); - return; - } + PERFETTO_CHECK(found_value); msg()->AppendVarInt<int32_t>(field_id, enum_value_number); + } else { } } @@ -383,8 +376,8 @@ class ParserDelegate { template <typename T> void FixedFloatField(const FieldDescriptorProto* field, Token t) { uint32_t field_id = static_cast<uint32_t>(field->number()); - base::Optional<double> opt_n = base::StringToDouble(t.ToStdString()); - msg()->AppendFixed<T>(field_id, static_cast<T>(opt_n.value_or(0l))); + double n = std::stod(t.ToStdString()); + msg()->AppendFixed<T>(field_id, static_cast<T>(n)); } template <typename T> @@ -565,8 +558,7 @@ void Parse(const std::string& input, ParserDelegate* delegate) { case kReadingNumericValue: if (isspace(c) || c == ';' || last_character) { - bool keep_last = last_character && !(isspace(c) || c == ';'); - size_t size = i - value.offset + (keep_last ? 1 : 0); + size_t size = i - value.offset + (last_character ? 1 : 0); value.txt = base::StringView(input.data() + value.offset, size); saw_semicolon_for_this_value = c == ';'; state = kWaitingForKey; @@ -596,9 +588,7 @@ void Parse(const std::string& input, ParserDelegate* delegate) { case kReadingIdentifierValue: if (isspace(c) || c == ';' || c == '#' || last_character) { - bool keep_last = - last_character && !(isspace(c) || c == ';' || c == '#'); - size_t size = i - value.offset + (keep_last ? 1 : 0); + size_t size = i - value.offset + (last_character ? 1 : 0); value.txt = base::StringView(input.data() + value.offset, size); comment_till_eol = c == '#'; saw_semicolon_for_this_value = c == ';'; |