| 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 "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 Loading... |
| 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_ |
| OLD | NEW |