Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "components/tracing/tracing_export.h" | |
| 13 | 14 |
| 14 namespace tracing { | 15 namespace tracing { |
| 15 namespace v2 { | 16 namespace v2 { |
| 16 namespace proto { | 17 namespace proto { |
| 17 | 18 |
| 18 // See https://developers.google.com/protocol-buffers/docs/encoding wire types. | 19 // See https://developers.google.com/protocol-buffers/docs/encoding wire types. |
| 19 | 20 |
| 20 enum : uint32_t { | 21 enum FieldType : uint32_t { |
| 21 kFieldTypeVarInt = 0, | 22 kFieldTypeVarInt = 0, |
| 22 kFieldTypeFixed64 = 1, | 23 kFieldTypeFixed64 = 1, |
| 23 kFieldTypeLengthDelimited = 2, | 24 kFieldTypeLengthDelimited = 2, |
| 24 kFieldTypeFixed32 = 5, | 25 kFieldTypeFixed32 = 5, |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 // Maximum message size supported: 256 MiB (4 x 7-bit due to varint encoding). | 28 // Maximum message size supported: 256 MiB (4 x 7-bit due to varint encoding). |
| 28 constexpr size_t kMessageLengthFieldSize = 4; | 29 constexpr size_t kMessageLengthFieldSize = 4; |
| 29 constexpr size_t kMaxMessageLength = (1u << (kMessageLengthFieldSize * 7)) - 1; | 30 constexpr size_t kMaxMessageLength = (1u << (kMessageLengthFieldSize * 7)) - 1; |
| 30 | 31 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 } | 88 } |
| 88 DCHECK_EQ(0u, value) << "Message is too long"; | 89 DCHECK_EQ(0u, value) << "Message is too long"; |
| 89 } | 90 } |
| 90 | 91 |
| 91 template <uint32_t field_id> | 92 template <uint32_t field_id> |
| 92 void StaticAssertSingleBytePreamble() { | 93 void StaticAssertSingleBytePreamble() { |
| 93 static_assert(field_id < 16, | 94 static_assert(field_id < 16, |
| 94 "Proto field id too big to fit in a single byte preamble"); | 95 "Proto field id too big to fit in a single byte preamble"); |
| 95 }; | 96 }; |
| 96 | 97 |
| 98 // Parses a VarInt. Supports both canonical and redundant encoding. | |
| 99 // Returns a pointer to the next unconsumed byte, that is, one byte past the | |
| 100 // end of the VarInt. | |
| 101 TRACING_EXPORT const uint8_t* ParseVarInt(const uint8_t* start, | |
| 102 const uint8_t* end, | |
|
kraynov
2016/09/02 16:06:49
You use STL-style when defined ContinuousMemoryRan
Primiano Tucci (use gerrit)
2016/09/02 16:54:59
The same thing is here (unless I screwed something
| |
| 103 uint64_t* value); | |
| 104 | |
| 105 // Parses a protobuf field, returning its id, type and value. | |
| 106 // Returns a pointer to the next unconsumed byte (|start| < retval <= end). | |
| 107 // In the case of a kFieldTypeLengthDelimited field, |field_intvalue| will | |
| 108 // contain the field payload (either a string or a nested message) and the | |
| 109 // return value will point to the first byte of the field payload. | |
| 110 TRACING_EXPORT const uint8_t* ParseField(const uint8_t* start, | |
| 111 const uint8_t* end, | |
| 112 uint32_t* field_id, | |
| 113 FieldType* field_type, | |
| 114 uint64_t* field_intvalue); | |
| 115 | |
| 97 } // namespace proto | 116 } // namespace proto |
| 98 } // namespace v2 | 117 } // namespace v2 |
| 99 } // namespace tracing | 118 } // namespace tracing |
| 100 | 119 |
| 101 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ | 120 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ |
| OLD | NEW |