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

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

Issue 2271653004: Reland of tracing v2: Introduce TraceBufferWriter (https://codereview.chromium.org/2196663002) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix undefined behavior of move ctor that caused revert on Win 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/BUILD.gn ('k') | components/tracing/core/proto_utils_unittest.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 016975d298757b8ccba71af153afd3194c067004..fdadf1a18df0b98f0f269b23c02c978c659a78c0 100644
--- a/components/tracing/core/proto_utils.h
+++ b/components/tracing/core/proto_utils.h
@@ -15,9 +15,6 @@ namespace tracing {
namespace v2 {
namespace proto {
-// TODO(kraynov): Change namespace to tracing::proto::internal.
-// This is required in headers and it's too low-level to be exposed.
-
// See https://developers.google.com/protocol-buffers/docs/encoding wire types.
enum : uint32_t {
@@ -35,7 +32,7 @@ constexpr size_t kMaxMessageLength = (1u << (kMessageLengthFieldSize * 7)) - 1;
// Largest value of simple (not length-delimited) field is 64-bit varint
// (10 bytes at most). 15 bytes buffer is enough to store a simple field.
constexpr size_t kMaxTagEncodedSize = 5;
-constexpr size_t kMaxSimpleFieldEncodedSize = 15;
+constexpr size_t kMaxSimpleFieldEncodedSize = kMaxTagEncodedSize + 10;
// Proto types: (int|uint|sint)(32|64), bool, enum.
constexpr uint32_t MakeTagVarInt(uint32_t field_id) {
@@ -76,21 +73,27 @@ inline uint8_t* WriteVarInt(T value, uint8_t* target) {
}
// Writes a fixed-size redundant encoding of the given |value|. This is
-// used to backfill fixed-size reservations for the length of field using a
+// used to backfill fixed-size reservations for the length field using a
// non-canonical varint encoding (e.g. \x81\x80\x80\x00 instead of \x01).
// See https://github.com/google/protobuf/issues/1530.
// In particular, this is used for nested messages. The size of a nested message
// is not known until all its field have been written. |kMessageLengthFieldSize|
// bytes are reserved to encode the size field and backfilled at the end.
-inline void WriteRedundantLength(uint32_t value, uint8_t* buf) {
- DCHECK_LE(value, kMaxMessageLength) << "Message is too long";
+inline void WriteRedundantVarInt(uint32_t value, uint8_t* buf) {
for (size_t i = 0; i < kMessageLengthFieldSize; ++i) {
const uint8_t msb = (i < kMessageLengthFieldSize - 1) ? 0x80 : 0;
buf[i] = static_cast<uint8_t>(value) | msb;
value >>= 7;
}
+ DCHECK_EQ(0u, value) << "Message is too long";
}
+template <uint32_t field_id>
+void StaticAssertSingleBytePreamble() {
+ static_assert(field_id < 16,
+ "Proto field id too big to fit in a single byte preamble");
+};
+
} // namespace proto
} // namespace v2
} // namespace tracing
« no previous file with comments | « components/tracing/BUILD.gn ('k') | components/tracing/core/proto_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698