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> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 template <size_t LENGTH> | 88 template <size_t LENGTH> |
89 void WriteRedundantVarIntU32(uint32_t value, uint8_t* buf) { | 89 void WriteRedundantVarIntU32(uint32_t value, uint8_t* buf) { |
90 for (size_t i = 0; i < LENGTH; ++i) { | 90 for (size_t i = 0; i < LENGTH; ++i) { |
91 const uint8_t msb = (i < LENGTH - 1) ? 0x80 : 0; | 91 const uint8_t msb = (i < LENGTH - 1) ? 0x80 : 0; |
92 buf[i] = static_cast<uint8_t>((value & 0x7F) | msb); | 92 buf[i] = static_cast<uint8_t>((value & 0x7F) | msb); |
93 value >>= 7; | 93 value >>= 7; |
94 } | 94 } |
95 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"; |
96 } | 96 } |
97 | 97 |
98 template <uint32_t field_id> | |
99 void StaticAssertSingleBytePreamble() { | |
100 static_assert(field_id < 16, | |
101 "Proto field id too big to fit in a single byte preamble"); | |
102 }; | |
103 | |
104 } // namespace proto | 98 } // namespace proto |
105 } // namespace v2 | 99 } // namespace v2 |
106 } // namespace tracing | 100 } // namespace tracing |
107 | 101 |
108 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ | 102 #endif // COMPONENTS_TRACING_CORE_PROTO_UTILS_H_ |
OLD | NEW |