| 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_
|
|
|