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

Side by Side Diff: base/trace_event/v2/proto_utils.h

Issue 1947373002: Tracing V2 prototype [NOT FOR REVIEW] Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WORKS Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_TRACE_EVENT_V2_PROTO_UTILS_H_
6 #define BASE_TRACE_EVENT_V2_PROTO_UTILS_H_
7
8 #include <inttypes.h>
9
10 #include "base/base_export.h"
11 #include "base/macros.h"
12
13 namespace base {
14 namespace trace_event {
15 namespace v2 {
16
17 class BASE_EXPORT ProtoUtils {
18 public:
19 static const uint32_t kFieldTypeVarInt = 0;
20 static const uint32_t kFieldTypeFixed64 = 1;
21 static const uint32_t kFieldTypeLengthLimited = 2;
22 static const uint32_t kFieldTypeFixed32 = 5;
23
24 static inline uint32_t GetVarIntFieldHeader(uint32_t field_id) {
25 return (field_id << 3) | kFieldTypeVarInt;
26 }
27
28 static inline uint32_t GetFixed64FieldHeader(uint32_t field_id) {
29 return (field_id << 3) | kFieldTypeFixed64;
30 }
31
32 static inline uint32_t GetLengthLimitedFieldHeader(uint32_t field_id) {
33 return (field_id << 3) | kFieldTypeLengthLimited;
34 }
35
36 static inline uint32_t GetFixed32FieldHeader(uint32_t field_id) {
37 return (field_id << 3) | kFieldTypeFixed32;
38 }
39
40 static inline size_t EncodeVarIntUnsigned(uint64_t value, uint8_t *buf) {
41 uint8_t *cur = buf;
42 value &= 0x7FFFFFFF;
43 do {
44 char w = (char)(value & 0x7F);
45 value >>= 7;
46 if (value)
47 w |= 0x80;
48 *cur = w;
49 ++cur;
50 } while (value);
51 return cur - buf;
52 }
53
54 static inline void
55 EncodeRedundantVarIntUnsigned(uint64_t value, size_t length, uint8_t *buf) {
56 for (size_t i = 0; i < length; ++i) {
57 const uint8_t msb = (i < length - 1) ? 0x80 : 0;
58 buf[i] = static_cast<uint8_t>((value & 0x7F) | msb);
59 value >>= 7;
60 }
61 }
62
63 DISALLOW_COPY_AND_ASSIGN(ProtoUtils);
64 };
65
66 } // namespace v2
67 } // namespace trace_event
68 } // namespace base
69
70 #endif // BASE_TRACE_EVENT_V2_PROTO_UTILS_H_
OLDNEW
« no previous file with comments | « base/trace_event/v2/append_only_proto_message_unittest.cc ('k') | base/trace_event/v2/proto_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698