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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/v2/proto_utils.h
diff --git a/base/trace_event/v2/proto_utils.h b/base/trace_event/v2/proto_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..b1c86bf677ddd7a792e3f5207f750da34ccf5ee4
--- /dev/null
+++ b/base/trace_event/v2/proto_utils.h
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TRACE_EVENT_V2_PROTO_UTILS_H_
+#define BASE_TRACE_EVENT_V2_PROTO_UTILS_H_
+
+#include <inttypes.h>
+
+#include "base/base_export.h"
+#include "base/macros.h"
+
+namespace base {
+namespace trace_event {
+namespace v2 {
+
+class BASE_EXPORT ProtoUtils {
+public:
+ static const uint32_t kFieldTypeVarInt = 0;
+ static const uint32_t kFieldTypeFixed64 = 1;
+ static const uint32_t kFieldTypeLengthLimited = 2;
+ static const uint32_t kFieldTypeFixed32 = 5;
+
+ static inline uint32_t GetVarIntFieldHeader(uint32_t field_id) {
+ return (field_id << 3) | kFieldTypeVarInt;
+ }
+
+ static inline uint32_t GetFixed64FieldHeader(uint32_t field_id) {
+ return (field_id << 3) | kFieldTypeFixed64;
+ }
+
+ static inline uint32_t GetLengthLimitedFieldHeader(uint32_t field_id) {
+ return (field_id << 3) | kFieldTypeLengthLimited;
+ }
+
+ static inline uint32_t GetFixed32FieldHeader(uint32_t field_id) {
+ return (field_id << 3) | kFieldTypeFixed32;
+ }
+
+ static inline size_t EncodeVarIntUnsigned(uint64_t value, uint8_t *buf) {
+ uint8_t *cur = buf;
+ value &= 0x7FFFFFFF;
+ do {
+ char w = (char)(value & 0x7F);
+ value >>= 7;
+ if (value)
+ w |= 0x80;
+ *cur = w;
+ ++cur;
+ } while (value);
+ return cur - buf;
+ }
+
+ static inline void
+ EncodeRedundantVarIntUnsigned(uint64_t value, size_t length, uint8_t *buf) {
+ for (size_t i = 0; i < length; ++i) {
+ const uint8_t msb = (i < length - 1) ? 0x80 : 0;
+ buf[i] = static_cast<uint8_t>((value & 0x7F) | msb);
+ value >>= 7;
+ }
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(ProtoUtils);
+};
+
+} // namespace v2
+} // namespace trace_event
+} // namespace base
+
+#endif // BASE_TRACE_EVENT_V2_PROTO_UTILS_H_
« 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