| 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_ZERO_MESSAGE_H_ | 5 #ifndef COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_H_ |
| 6 #define COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_H_ | 6 #define COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <type_traits> | 10 #include <type_traits> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace v2 { | 23 namespace v2 { |
| 24 | 24 |
| 25 class ProtoZeroMessageHandleBase; | 25 class ProtoZeroMessageHandleBase; |
| 26 | 26 |
| 27 // Base class extended by the proto C++ stubs generated by the ProtoZero | 27 // Base class extended by the proto C++ stubs generated by the ProtoZero |
| 28 // compiler (see //components/tracing/tools/). This class provides the minimal | 28 // compiler (see //components/tracing/tools/). This class provides the minimal |
| 29 // runtime required to support append-only operations and is desiged for | 29 // runtime required to support append-only operations and is desiged for |
| 30 // performance. None of the methods require any dynamic memory allocation. | 30 // performance. None of the methods require any dynamic memory allocation. |
| 31 class TRACING_EXPORT ProtoZeroMessage { | 31 class TRACING_EXPORT ProtoZeroMessage { |
| 32 public: | 32 public: |
| 33 ProtoZeroMessage(); |
| 34 |
| 33 // Clears up the state, allowing the message to be reused as a fresh one. | 35 // Clears up the state, allowing the message to be reused as a fresh one. |
| 34 void Reset(ScatteredStreamWriter*); | 36 void Reset(ScatteredStreamWriter*); |
| 35 | 37 |
| 36 // Commits all the changes to the buffer (backfills the size field of this and | 38 // Commits all the changes to the buffer (backfills the size field of this and |
| 37 // all nested messages) and seals the message. Returns the size of the message | 39 // all nested messages) and seals the message. Returns the size of the message |
| 38 // (and all nested sub-messages), without taking into account any chunking. | 40 // (and all nested sub-messages), without taking into account any chunking. |
| 39 // Finalize is idempotent and can be called several times w/o side effects. | 41 // Finalize is idempotent and can be called several times w/o side effects. |
| 40 size_t Finalize(); | 42 size_t Finalize(); |
| 41 | 43 |
| 42 // Optional. If is_valid() == true, the corresponding memory region (its | 44 // Optional. If is_valid() == true, the corresponding memory region (its |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 // message which is split into multiple chunks. Upon finalization only the | 55 // message which is split into multiple chunks. Upon finalization only the |
| 54 // partial size that lies in the last chunk has to be backfilled. | 56 // partial size that lies in the last chunk has to be backfilled. |
| 55 void inc_size_already_written(size_t size) { size_already_written_ += size; } | 57 void inc_size_already_written(size_t size) { size_already_written_ += size; } |
| 56 | 58 |
| 57 #if DCHECK_IS_ON() | 59 #if DCHECK_IS_ON() |
| 58 // Only for ProtoZeroMessageHandleBase. | 60 // Only for ProtoZeroMessageHandleBase. |
| 59 void set_handle(ProtoZeroMessageHandleBase* handle) { handle_ = handle; } | 61 void set_handle(ProtoZeroMessageHandleBase* handle) { handle_ = handle; } |
| 60 #endif | 62 #endif |
| 61 | 63 |
| 62 protected: | 64 protected: |
| 63 ProtoZeroMessage(); | |
| 64 | |
| 65 // Proto types: uint64, uint32, int64, int32, bool, enum. | 65 // Proto types: uint64, uint32, int64, int32, bool, enum. |
| 66 template <typename T> | 66 template <typename T> |
| 67 void AppendVarInt(uint32_t field_id, T value) { | 67 void AppendVarInt(uint32_t field_id, T value) { |
| 68 if (nested_message_) | 68 if (nested_message_) |
| 69 EndNestedMessage(); | 69 EndNestedMessage(); |
| 70 | 70 |
| 71 uint8_t buffer[proto::kMaxSimpleFieldEncodedSize]; | 71 uint8_t buffer[proto::kMaxSimpleFieldEncodedSize]; |
| 72 uint8_t* pos = buffer; | 72 uint8_t* pos = buffer; |
| 73 | 73 |
| 74 pos = proto::WriteVarInt(proto::MakeTagVarInt(field_id), pos); | 74 pos = proto::WriteVarInt(proto::MakeTagVarInt(field_id), pos); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // DO NOT add any fields below |nested_messages_arena_|. The memory layout of | 190 // DO NOT add any fields below |nested_messages_arena_|. The memory layout of |
| 191 // nested messages would overflow the storage allocated by the root message. | 191 // nested messages would overflow the storage allocated by the root message. |
| 192 | 192 |
| 193 DISALLOW_COPY_AND_ASSIGN(ProtoZeroMessage); | 193 DISALLOW_COPY_AND_ASSIGN(ProtoZeroMessage); |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 } // namespace v2 | 196 } // namespace v2 |
| 197 } // namespace tracing | 197 } // namespace tracing |
| 198 | 198 |
| 199 #endif // COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_H_ | 199 #endif // COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_H_ |
| OLD | NEW |