class Message

Defined at line 49 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 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 59 of file ../../third_party/perfetto/include/perfetto/protozero/message.h

void Reset (ScatteredStreamWriter * , MessageArena * )

Clears up the state, allowing the message to be reused as a fresh one.

uint32_t Finalize ()

Commits all the changes to the buffer (backfills the size field of this and

all nested messages) and seals the message. Returns the size of the message

(and all nested sub-messages), without taking into account any chunking.

Finalize is idempotent and can be called several times w/o side effects.

Short messages may be compacted in memory into the size field, since their

size can be represented with fewer than

proto_utils::kMessageLengthFieldSize bytes.

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.

Defined at line 79 of file ../../third_party/perfetto/include/perfetto/protozero/message.h

void set_size_field (uint8_t * size_field)

Defined at line 80 of file ../../third_party/perfetto/include/perfetto/protozero/message.h

Message * nested_message ()

Defined at line 82 of file ../../third_party/perfetto/include/perfetto/protozero/message.h

bool is_finalized ()

Defined at line 84 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 94 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 109 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 115 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 130 of file ../../third_party/perfetto/include/perfetto/protozero/message.h

void AppendString (uint32_t field_id, const char * str)
void AppendBytes (uint32_t field_id, const void * value, size_t size)
size_t AppendScatteredBytes (uint32_t field_id, ContiguousMemoryRange * ranges, size_t num_ranges)

Append raw bytes for a field, using the supplied |ranges| to

copy from |num_ranges| individual buffers.

void AppendString (uint32_t field_id, const std::string & str)

Defined at line 146 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 164 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 177 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.

Defined at line 184 of file ../../third_party/perfetto/include/perfetto/protozero/message.h

Friends

class MessageHandleBase