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

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

Issue 2293073002: Tracing V2: Proto fields reflection. (Closed)
Patch Set: nit 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
« no previous file with comments | « no previous file | components/tracing/test/proto_zero_generation_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_GROUP = 10 is not supported.
42 TYPE_BYTES = 12,
43 TYPE_UINT32 = 13,
44 TYPE_ENUM = 14,
45 TYPE_SFIXED32 = 15,
46 TYPE_SFIXED64 = 16,
47 TYPE_SINT32 = 17,
48 TYPE_SINT64 = 18,
49 };
50
51 ProtoFieldDescriptor(const char* name,
52 Type type,
53 uint32_t number,
54 bool is_repeated)
55 : name_(name), type_(type), number_(number), is_repeated_(is_repeated) {
56 }
57
58 const char* name() const {
59 return name_;
60 }
61
62 Type type() const {
63 return type_;
64 }
65
66 uint32_t number() const {
67 return number_;
68 }
69
70 bool is_repeated() const {
71 return is_repeated_;
72 }
73
74 bool is_valid() const {
75 return type_ != Type::TYPE_INVALID;
76 }
77
78 private:
79 const char* const name_;
80 const Type type_;
81 const uint32_t number_;
82 const bool is_repeated_;
83
84 DISALLOW_COPY_AND_ASSIGN(ProtoFieldDescriptor);
85 };
86
27 // Maximum message size supported: 256 MiB (4 x 7-bit due to varint encoding). 87 // Maximum message size supported: 256 MiB (4 x 7-bit due to varint encoding).
28 constexpr size_t kMessageLengthFieldSize = 4; 88 constexpr size_t kMessageLengthFieldSize = 4;
29 constexpr size_t kMaxMessageLength = (1u << (kMessageLengthFieldSize * 7)) - 1; 89 constexpr size_t kMaxMessageLength = (1u << (kMessageLengthFieldSize * 7)) - 1;
30 90
31 // Field tag is encoded as 32-bit varint (5 bytes at most). 91 // 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 92 // 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. 93 // (10 bytes at most). 15 bytes buffer is enough to store a simple field.
34 constexpr size_t kMaxTagEncodedSize = 5; 94 constexpr size_t kMaxTagEncodedSize = 5;
35 constexpr size_t kMaxSimpleFieldEncodedSize = kMaxTagEncodedSize + 10; 95 constexpr size_t kMaxSimpleFieldEncodedSize = kMaxTagEncodedSize + 10;
36 96
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 void StaticAssertSingleBytePreamble() { 152 void StaticAssertSingleBytePreamble() {
93 static_assert(field_id < 16, 153 static_assert(field_id < 16,
94 "Proto field id too big to fit in a single byte preamble"); 154 "Proto field id too big to fit in a single byte preamble");
95 }; 155 };
96 156
97 } // namespace proto 157 } // namespace proto
98 } // namespace v2 158 } // namespace v2
99 } // namespace tracing 159 } // namespace tracing
100 160
101 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ 161 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | components/tracing/test/proto_zero_generation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698