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

Unified Diff: components/tracing/core/proto_utils.h

Issue 2303343002: tracing v2: building blocks for reading-back trace protobufs (Closed)
Patch Set: oysteine + petrcermak review Created 4 years, 3 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/BUILD.gn ('k') | components/tracing/core/proto_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/tracing/core/proto_utils.h
diff --git a/components/tracing/core/proto_utils.h b/components/tracing/core/proto_utils.h
index fdadf1a18df0b98f0f269b23c02c978c659a78c0..e9315154957fbcf8e945fde16b3993734f698685 100644
--- a/components/tracing/core/proto_utils.h
+++ b/components/tracing/core/proto_utils.h
@@ -10,6 +10,7 @@
#include <type_traits>
#include "base/logging.h"
+#include "components/tracing/tracing_export.h"
namespace tracing {
namespace v2 {
@@ -17,7 +18,7 @@ namespace proto {
// See https://developers.google.com/protocol-buffers/docs/encoding wire types.
-enum : uint32_t {
+enum FieldType : uint32_t {
kFieldTypeVarInt = 0,
kFieldTypeFixed64 = 1,
kFieldTypeLengthDelimited = 2,
@@ -94,6 +95,26 @@ void StaticAssertSingleBytePreamble() {
"Proto field id too big to fit in a single byte preamble");
};
+// Parses a VarInt from the encoded buffer [start, end). |end| is STL-style and
+// points one byte past the end of buffer.
+// The parsed int value is stored in the output arg |value|. Returns a pointer
+// to the next unconsumed byte (so start < retval <= end).
+TRACING_EXPORT const uint8_t* ParseVarInt(const uint8_t* start,
+ const uint8_t* end,
+ uint64_t* value);
+
+// Parses a protobuf field and computes its id, type and value.
+// Returns a pointer to the next unconsumed byte (|start| < retval <= end) that
+// is either the beginning of the next field or the end of the parent message.
+// In the case of a kFieldTypeLengthDelimited field, |field_intvalue| will store
+// the length of the payload (either a string or a nested message). In this
+// case, the start of the payload will be at (return value) - |field_intvalue|.
+TRACING_EXPORT const uint8_t* ParseField(const uint8_t* start,
+ const uint8_t* end,
+ uint32_t* field_id,
+ FieldType* field_type,
+ uint64_t* field_intvalue);
+
} // namespace proto
} // namespace v2
} // namespace tracing
« no previous file with comments | « components/tracing/BUILD.gn ('k') | components/tracing/core/proto_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698