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

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

Issue 2293073002: Tracing V2: Proto fields reflection. (Closed)
Patch Set: new one 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 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 13
14 namespace tracing { 14 namespace tracing {
15 namespace v2 { 15 namespace v2 {
16 namespace proto { 16 namespace proto {
17 17
18 // See https://developers.google.com/protocol-buffers/docs/encoding wire types. 18 // See https://developers.google.com/protocol-buffers/docs/encoding wire types.
19 19
20 enum : uint32_t { 20 enum : uint32_t {
21 kFieldTypeVarInt = 0, 21 kFieldTypeVarInt = 0,
22 kFieldTypeFixed64 = 1, 22 kFieldTypeFixed64 = 1,
23 kFieldTypeLengthDelimited = 2, 23 kFieldTypeLengthDelimited = 2,
24 kFieldTypeFixed32 = 5, 24 kFieldTypeFixed32 = 5,
25 }; 25 };
26 26
27 class ProtoFieldDescriptor {
28 public:
29 enum Type {
30 TYPE_INVALID = 0,
31 TYPE_DOUBLE = 1,
32 TYPE_FLOAT = 2,
33 TYPE_INT64 = 3,
34 TYPE_UINT64 = 4,
35 TYPE_INT32 = 5,
36 TYPE_FIXED64 = 6,
37 TYPE_FIXED32 = 7,
38 TYPE_BOOL = 8,
39 TYPE_STRING = 9,
40 TYPE_MESSAGE = 11,
41 TYPE_BYTES = 12,
42 TYPE_UINT32 = 13,
43 TYPE_ENUM = 14,
44 TYPE_SFIXED32 = 15,
45 TYPE_SFIXED64 = 16,
46 TYPE_SINT32 = 17,
47 TYPE_SINT64 = 18,
48 // TYPE_GROUP = 10 is not supported.
picksi1 2016/09/01 16:38:39 Should this comment be put at the 'correct' place
49 };
50
51 ProtoFieldDescriptor(const char* name,
Primiano Tucci (use gerrit) 2016/09/01 16:18:06 is this git-cl formatted?
52 Type type,
53 uint32_t number,
54 bool is_repeated) : name_(name),
55 type_(type),
56 number_(number),
57 is_repeated_(is_repeated) {
58 }
59
60 const char* name() const {
61 return name_;
62 }
63
64 Type type() const {
65 return type_;
66 }
67
68 uint32_t number() const {
69 return number_;
70 }
71
72 bool is_repeated() const {
73 return is_repeated_;
74 }
75
76 bool is_valid() const {
77 return type_ != Type::TYPE_INVALID;
78 }
79
80 private:
81 const char* const name_;
82 const Type type_;
83 const uint32_t number_;
84 const bool is_repeated_;
85
86 DISALLOW_COPY_AND_ASSIGN(ProtoFieldDescriptor);
87 };
88
27 // Maximum message size supported: 256 MiB (4 x 7-bit due to varint encoding). 89 // Maximum message size supported: 256 MiB (4 x 7-bit due to varint encoding).
28 constexpr size_t kMessageLengthFieldSize = 4; 90 constexpr size_t kMessageLengthFieldSize = 4;
29 constexpr size_t kMaxMessageLength = (1u << (kMessageLengthFieldSize * 7)) - 1; 91 constexpr size_t kMaxMessageLength = (1u << (kMessageLengthFieldSize * 7)) - 1;
30 92
31 // Field tag is encoded as 32-bit varint (5 bytes at most). 93 // Field tag is encoded as 32-bit varint (5 bytes at most).
32 // Largest value of simple (not length-delimited) field is 64-bit varint 94 // Largest value of simple (not length-delimited) field is 64-bit varint
33 // (10 bytes at most). 15 bytes buffer is enough to store a simple field. 95 // (10 bytes at most). 15 bytes buffer is enough to store a simple field.
34 constexpr size_t kMaxTagEncodedSize = 5; 96 constexpr size_t kMaxTagEncodedSize = 5;
35 constexpr size_t kMaxSimpleFieldEncodedSize = kMaxTagEncodedSize + 10; 97 constexpr size_t kMaxSimpleFieldEncodedSize = kMaxTagEncodedSize + 10;
36 98
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 void StaticAssertSingleBytePreamble() { 154 void StaticAssertSingleBytePreamble() {
93 static_assert(field_id < 16, 155 static_assert(field_id < 16,
94 "Proto field id too big to fit in a single byte preamble"); 156 "Proto field id too big to fit in a single byte preamble");
95 }; 157 };
96 158
97 } // namespace proto 159 } // namespace proto
98 } // namespace v2 160 } // namespace v2
99 } // namespace tracing 161 } // namespace tracing
100 162
101 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ 163 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698