| 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 11 matching lines...) Expand all Loading... |
| 22 namespace v2 { | 22 namespace v2 { |
| 23 | 23 |
| 24 class ProtoZeroMessageHandleBase; | 24 class ProtoZeroMessageHandleBase; |
| 25 | 25 |
| 26 // Base class extended by the proto C++ stubs generated by the ProtoZero | 26 // Base class extended by the proto C++ stubs generated by the ProtoZero |
| 27 // compiler (see //components/tracing/tools/). This class provides the minimal | 27 // compiler (see //components/tracing/tools/). This class provides the minimal |
| 28 // runtime required to support append-only operations and is desiged for | 28 // runtime required to support append-only operations and is desiged for |
| 29 // performance. None of the methods require any dynamic memory allocation. | 29 // performance. None of the methods require any dynamic memory allocation. |
| 30 class TRACING_EXPORT ProtoZeroMessage { | 30 class TRACING_EXPORT ProtoZeroMessage { |
| 31 public: | 31 public: |
| 32 ProtoZeroMessage(); |
| 33 |
| 32 // Clears up the state, allowing the message to be reused as a fresh one. | 34 // Clears up the state, allowing the message to be reused as a fresh one. |
| 33 void Reset(ScatteredStreamWriter*); | 35 void Reset(ScatteredStreamWriter*); |
| 34 | 36 |
| 35 // Commits all the changes to the buffer (backfills the size field of this and | 37 // Commits all the changes to the buffer (backfills the size field of this and |
| 36 // all nested messages) and seals the message. Returns the size of the message | 38 // all nested messages) and seals the message. Returns the size of the message |
| 37 // (and all nested sub-messages), without taking into account any chunking. | 39 // (and all nested sub-messages), without taking into account any chunking. |
| 38 // Finalize is idempotent and can be called several times w/o side effects. | 40 // Finalize is idempotent and can be called several times w/o side effects. |
| 39 size_t Finalize(); | 41 size_t Finalize(); |
| 40 | 42 |
| 41 // Optional. If is_valid() == true, the corresponding memory region (its | 43 // Optional. If is_valid() == true, the corresponding memory region (its |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 // message which is split into multiple chunks. Upon finalization only the | 54 // message which is split into multiple chunks. Upon finalization only the |
| 53 // partial size that lies in the last chunk has to be backfilled. | 55 // partial size that lies in the last chunk has to be backfilled. |
| 54 void inc_size_already_written(size_t size) { size_already_written_ += size; } | 56 void inc_size_already_written(size_t size) { size_already_written_ += size; } |
| 55 | 57 |
| 56 #if DCHECK_IS_ON() | 58 #if DCHECK_IS_ON() |
| 57 // Only for ProtoZeroMessageHandleBase. | 59 // Only for ProtoZeroMessageHandleBase. |
| 58 void set_handle(ProtoZeroMessageHandleBase* handle) { handle_ = handle; } | 60 void set_handle(ProtoZeroMessageHandleBase* handle) { handle_ = handle; } |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 61 protected: | 63 protected: |
| 62 ProtoZeroMessage(); | |
| 63 | |
| 64 void AppendVarIntU64(uint32_t field_id, uint64_t value); | 64 void AppendVarIntU64(uint32_t field_id, uint64_t value); |
| 65 void AppendVarIntU32(uint32_t field_id, uint32_t value); | 65 void AppendVarIntU32(uint32_t field_id, uint32_t value); |
| 66 void AppendFloat(uint32_t field_id, float value); | 66 void AppendFloat(uint32_t field_id, float value); |
| 67 void AppendDouble(uint32_t field_id, double value); | 67 void AppendDouble(uint32_t field_id, double value); |
| 68 void AppendString(uint32_t field_id, const char* str); | 68 void AppendString(uint32_t field_id, const char* str); |
| 69 void AppendBytes(uint32_t field_id, const void* value, size_t size); | 69 void AppendBytes(uint32_t field_id, const void* value, size_t size); |
| 70 // TODO(kraynov): implement AppendVarIntS32/64(...) w/ zig-zag encoding. | 70 // TODO(kraynov): implement AppendVarIntS32/64(...) w/ zig-zag encoding. |
| 71 | 71 |
| 72 // Begins a nested message, using the static storage provided by the parent | 72 // Begins a nested message, using the static storage provided by the parent |
| 73 // class (see comment in |nested_messages_arena_|). The nested message ends | 73 // class (see comment in |nested_messages_arena_|). The nested message ends |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // DO NOT add any fields below |nested_messages_arena_|. The memory layout of | 156 // DO NOT add any fields below |nested_messages_arena_|. The memory layout of |
| 157 // nested messages would overflow the storage allocated by the root message. | 157 // nested messages would overflow the storage allocated by the root message. |
| 158 | 158 |
| 159 DISALLOW_COPY_AND_ASSIGN(ProtoZeroMessage); | 159 DISALLOW_COPY_AND_ASSIGN(ProtoZeroMessage); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 } // namespace v2 | 162 } // namespace v2 |
| 163 } // namespace tracing | 163 } // namespace tracing |
| 164 | 164 |
| 165 #endif // COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_H_ | 165 #endif // COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_H_ |
| OLD | NEW |