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

Side by Side Diff: components/tracing/core/proto_utils.h

Issue 2134683002: tracing v2: Add base class for zero-copy protobuf (ProtoZero) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proto_utils
Patch Set: petrcermak review Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ 5 #ifndef COMPONENTS_TRACING_CORE_PROTO_UTILS_H_
6 #define COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ 6 #define COMPONENTS_TRACING_CORE_PROTO_UTILS_H_
7 7
8 #include <inttypes.h> 8 #include <inttypes.h>
9 9
10 #include <type_traits> 10 #include <type_traits>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "components/tracing/tracing_export.h" 14 #include "components/tracing/tracing_export.h"
15 15
16 namespace tracing { 16 namespace tracing {
17 namespace v2 { 17 namespace v2 {
18 namespace proto { 18 namespace proto {
19 19
20 // See https://developers.google.com/protocol-buffers/docs/encoding wire types. 20 // See https://developers.google.com/protocol-buffers/docs/encoding wire types.
21 21
22 enum : uint32_t { 22 enum : uint32_t {
23 kFieldTypeVarInt = 0, 23 kFieldTypeVarInt = 0,
24 kFieldTypeFixed64 = 1, 24 kFieldTypeFixed64 = 1,
25 kFieldTypeLengthDelimited = 2, 25 kFieldTypeLengthDelimited = 2,
26 kFieldTypeFixed32 = 5, 26 kFieldTypeFixed32 = 5,
27 }; 27 };
28 28
29 // Maximum message size supported: 256 MiB (4 x 7-bit due to varint encoding).
30 constexpr size_t kMessageLengthFieldSize = 4;
31 constexpr size_t kMaxMessageLength = (1u << (kMessageLengthFieldSize * 7)) - 1;
32
29 // Returns the number of bytes sufficient to encode the largest 33 // Returns the number of bytes sufficient to encode the largest
30 // |int_size_in_bits|-bits integer using a non-redundant varint encoding. 34 // |int_size_in_bits|-bits integer using a non-redundant varint encoding.
31 template <typename T> 35 template <typename T>
32 constexpr size_t GetMaxVarIntEncodedSize() { 36 constexpr size_t GetMaxVarIntEncodedSize() {
33 return (sizeof(T) * 8 + 6) / 7; 37 return (sizeof(T) * 8 + 6) / 7;
34 } 38 }
35 39
36 // Variable-length field types: (s)int32, (s)int64, bool, enum. 40 // Variable-length field types: (s)int32, (s)int64, bool, enum.
37 inline uint32_t MakeTagVarInt(uint32_t field_id) { 41 inline uint32_t MakeTagVarInt(uint32_t field_id) {
38 return (field_id << 3) | kFieldTypeVarInt; 42 return (field_id << 3) | kFieldTypeVarInt;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 value >>= 7; 93 value >>= 7;
90 } 94 }
91 DCHECK_EQ(0u, value) << "Buffer too short to encode the given value"; 95 DCHECK_EQ(0u, value) << "Buffer too short to encode the given value";
92 } 96 }
93 97
94 } // namespace proto 98 } // namespace proto
95 } // namespace v2 99 } // namespace v2
96 } // namespace tracing 100 } // namespace tracing
97 101
98 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ 102 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698