class Message
Defined at line 50 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
Base class extended by the proto C++ stubs generated by the ProtoZero
compiler. This class provides the minimal runtime required to support
append-only operations and is designed for performance. None of the methods
require any dynamic memory allocation, unless more than 16 nested messages
are created via BeginNestedMessage() calls.
Public Methods
void AppendBytes (uint32_tfield_id,const void *value,size_tsize)
size_t AppendScatteredBytes (uint32_tfield_id,ContiguousMemoryRange *ranges,size_tnum_ranges)
Append raw bytes for a field, using the supplied |ranges| to
copy from |num_ranges| individual buffers.
void Message ()
The ctor is deliberately a no-op to avoid forwarding args from all
subclasses. The real initialization is performed by Reset().
Nested messages are allocated via placement new by MessageArena and
implictly destroyed when the RootMessage's arena goes away. This is
fine as long as all the fields are PODs, which is checked by the
static_assert()s in the Reset() method.
Defined at line 60 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
template <typename T>
void AppendSignedVarInt (uint32_t field_id, T value)
Proto types: sint64, sint32.
Defined at line 142 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
void AppendTinyVarInt (uint32_t field_id, int32_t value)
Proto types: bool, enum (small).
Faster version of AppendVarInt for tiny numbers.
Defined at line 148 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
template <typename T>
void AppendFixed (uint32_t field_id, T value)
Proto types: fixed64, sfixed64, fixed32, sfixed32, double, float.
Defined at line 163 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
void Reset (ScatteredStreamWriter *,MessageArena *,Encoding)
Clears up the state, allowing the message to be reused as a fresh one
with the specified encoding.
uint32_t Finalize ()
Finalizes all open children, then seals this message:
- Length-delimited: writes the encoded size into the reserved length field,
if present. For short messages within the current chunk, compaction can
reduce the field from proto_utils::kMessageLengthFieldSize bytes to one.
- kProtoGroup: writes nothing. The parent writes the closing byte.
Returns the encoded size of this message's fields, including nested
messages. It excludes this message's own tag, length field and closing
byte.
Finalize is idempotent and can be called several times w/o side effects.
void AppendString (uint32_t field_id, const char * str)
Encoding encoding ()
Returns the encoding each new child inherits.
Defined at line 80 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
void Reset (ScatteredStreamWriter * stream_writer, MessageArena * arena)
Convenience wrapper for the default length-delimited encoding.
See the TODO on RootMessage::Reset().
Defined at line 88 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
uint8_t * size_field ()
Optional. If is_valid() == true, the corresponding memory region (its
length == proto_utils::kMessageLengthFieldSize) is backfilled with the size
of this message. This is the mechanism used by messages to backfill their
corresponding size field in the parent message. In most cases this is only
used for nested messages and the ScatteredStreamWriter::Delegate (e.g.
TraceWriterImpl), takes case of the outer message.
In kProtoGroup mode, this pointer must always be null.
Defined at line 112 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
void set_size_field (uint8_t * size_field)
Defined at line 113 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
Message * nested_message ()
Defined at line 115 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
bool is_finalized ()
Defined at line 117 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
template <typename T>
void AppendVarInt (uint32_t field_id, T value)
Proto types: uint64, uint32, int64, int32, bool, enum.
Defined at line 127 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
void AppendString (uint32_t field_id, const std::string & str)
Defined at line 180 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
template <class T>
T * BeginNestedMessage (uint32_t field_id)
Begins a nested message. The returned object is owned by the MessageArena
of the root message. The nested message ends either when Finalize() is
called or when any other Append* method is called in the parent class.
The template argument T is supposed to be a stub class auto generated from
a .proto, hence a subclass of Message.
Defined at line 198 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
const ScatteredStreamWriter * stream_writer ()
Gives read-only access to the underlying stream_writer. This is used only
by few internals to query the state of the underlying buffer. It is almost
always a bad idea to poke at the stream_writer() internals.
Defined at line 211 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
void AppendRawProtoBytes (const void * data, size_t size)
Appends some raw bytes to the message. The use-case for this is preserving
unknown fields in the decode -> re-encode path of xxx.gen.cc classes
generated by the cppgen_plugin.cc.
The caller needs to guarantee that the appended data is properly
proto-encoded and each field has a proto preamble.
In kProtoGroup mode:
- |data| must not contain protobuf group fields. This mode reserves wire
types 3 and 4 for nested message boundaries.
- A nested message must contain only proto fields. For a raw string or
bytes payload, use AppendBytes() on the parent.
Defined at line 224 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
Enumerations
enum class Encoding : uint8_t
| Name | Value | Comments |
|---|---|---|
| kLengthDelimited | 0 |
Standard protobuf. Finalize() writes each child's length into a reserved |
| kProtoGroup | 1 |
Append-only format for tracing v2. It needs no patches: |
Encoding for nested messages. The root selects it in Reset(). Each child
inherits its parent's encoding.
Keep in sync with PerfettoPbMsgEncoding in perfetto/public/pb_msg.h.
Defined at line 65 of file ../../third_party/perfetto/include/perfetto/protozero/message.h
Friends
class MessageHandleBase