Index: components/tracing/core/proto_zero_message.h |
diff --git a/components/tracing/core/proto_zero_message.h b/components/tracing/core/proto_zero_message.h |
index b5b0a37cce1bc4b82788c62108ee7036702cb6d0..01853c75d7be43242b46de5bf6cf22fc891bf88a 100644 |
--- a/components/tracing/core/proto_zero_message.h |
+++ b/components/tracing/core/proto_zero_message.h |
@@ -7,6 +7,7 @@ |
#include <stdint.h> |
+#include <set> |
#include <type_traits> |
#include "base/compiler_specific.h" |
@@ -22,7 +23,9 @@ |
namespace tracing { |
namespace v2 { |
+#if DCHECK_IS_ON() |
Primiano Tucci (use gerrit)
2016/08/24 08:59:45
is this causing an actual compilation error? If no
|
class ProtoZeroMessageHandleBase; |
+#endif |
// Base class extended by the proto C++ stubs generated by the ProtoZero |
// compiler (see //components/tracing/tools/). This class provides the minimal |
@@ -62,7 +65,7 @@ class TRACING_EXPORT ProtoZeroMessage { |
protected: |
ProtoZeroMessage(); |
- // Proto types: uint64, uint32, int64, int32, bool, enum. |
+ // Proto types: uint64, uint32, int64, int32, enum (large). |
template <typename T> |
void AppendVarInt(uint32_t field_id, T value) { |
if (nested_message_) |
@@ -83,6 +86,21 @@ class TRACING_EXPORT ProtoZeroMessage { |
AppendVarInt(field_id, proto::ZigZagEncode(value)); |
} |
+ // Proto types: bool, enum (small). |
+ // It could be looking weird not to optimize writing field_id, but it's |
Primiano Tucci (use gerrit)
2016/08/24 08:59:45
Honestly I feel this comment is just too apologeti
|
+ // unnecessary because compiler already optimize WriteVarInt for constexpr. |
+ void AppendTinyVarInt(uint32_t field_id, int32_t value) { |
+ DCHECK(0 <= value && value < 0x80); |
+ if (nested_message_) |
+ EndNestedMessage(); |
+ |
+ uint8_t buffer[proto::kMaxSimpleFieldEncodedSize]; |
+ uint8_t* pos = buffer; |
+ pos = proto::WriteVarInt(proto::MakeTagVarInt(field_id), pos); |
+ *pos++ = static_cast<uint8_t>(value); |
+ WriteToStream(buffer, pos); |
+ } |
+ |
// Proto types: fixed64, sfixed64, fixed32, sfixed32, double, float. |
template <typename T> |
void AppendFixed(uint32_t field_id, T value) { |
@@ -99,7 +117,6 @@ class TRACING_EXPORT ProtoZeroMessage { |
WriteToStream(buffer, pos); |
} |
- // TODO(kraynov): Add AppendTinyInt. |
void AppendString(uint32_t field_id, const char* str); |
void AppendBytes(uint32_t field_id, const void* value, size_t size); |
@@ -122,6 +139,14 @@ class TRACING_EXPORT ProtoZeroMessage { |
return message; |
} |
+ // Prevent multiple appends for non-repeated fields. |
Primiano Tucci (use gerrit)
2016/08/24 08:59:45
honestly I feel this duplicated field detection is
|
+ inline void DCheckSealField(uint32_t field_id) { |
+#if DCHECK_IS_ON() |
+ DCHECK(field_id > 0); |
+ SealField(field_id); |
+#endif |
+ } |
+ |
private: |
friend class ProtoZeroMessageTest; |
FRIEND_TEST_ALL_PREFIXES(ProtoZeroMessageTest, BasicTypesNoNesting); |
@@ -147,6 +172,10 @@ class TRACING_EXPORT ProtoZeroMessage { |
size_ += size; |
} |
+#if DCHECK_IS_ON() |
+ void SealField(uint32_t field_id); |
+#endif |
+ |
// Only POD fields are allowed. This class's dtor is never called. |
// See the comment on the static_assert in the the corresponding .cc file. |