class TypedProtoDecoderBase
Defined at line 376 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
This decoder loads all fields upfront, without recursing in nested messages.
It is used as a base class for typed decoders generated by the pbzero plugin.
The split between TypedProtoDecoderBase and TypedProtoDecoder
<
> is to have
unique definition of functions like ParseAllFields() and ExpandHeapStorage().
The storage (either on-stack or on-heap) for this class is organized as
follows:
|-------------------------- fields_ ----------------------|
[ field 0 (invalid) ] [ fields 1 .. N ] [ repeated fields ]
^ ^
num_fields_ size_
Note that if a message has high field numbers, upon creation |size_| can be
<
|num_fields_| (until a heap expansion is hit while inserting).
Protected Members
unique_ptr heap_storage_
Field * fields_
uint64_t * presence_
uint32_t num_fields_
uint32_t size_
bool has_out_of_range_fields_
uint32_t capacity_
static Field kInvalidField
Public Methods
const Field & Get (uint32_t id)
If the field |id| is known at compile time, prefer the templated
specialization at
<kFieldNumber
>().
Defined at line 380 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
bool has_out_of_range_fields ()
True if the message contained at least one field with an id beyond the
highest id known in-tree (typically an out-of-tree extension). Such
fields are not stored here; this lets callers skip a selective re-decode
via unknown_fields() when there is nothing to find.
Defined at line 394 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
bool HasAnyField (const uint64_t * mask, size_t words)
True if any field whose bit is set in |mask| is present. |mask| is laid
out like the presence bitmap (bit i of word i / 64 for field id i) and
holds |words| words; bits beyond the known field range are ignored.
Defined at line 399 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
bool HasField (uint32_t id)
True if the field with the given id was seen while decoding: tests bit
|id| of the presence bitmap. The caller must check that |id| is within
the bitmap, i.e.
<
= the decoder's MAX_FIELD_ID. Note that |id| may
exceed |num_fields_|: the selective decoding constructor shrinks
num_fields_ to the mask's extent but clears the full bitmap, so that
at
<
>() can keep testing the bit directly.
Defined at line 414 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
template <typename T>
RepeatedFieldIterator<T> GetRepeated (uint32_t field_id)
Returns an object that allows to iterate over all instances of a repeated
field given its id. Example usage:
for (auto it = decoder.GetRepeated
<int32
_t>(N); it; ++it) { ... }
Defined at line 425 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
template <proto_utils::ProtoWireType wire_type, typename cpp_type>
PackedRepeatedFieldIterator<wire_type, cpp_type> GetPackedRepeated (uint32_t field_id, bool * parse_error_location)
Returns an objects that allows to iterate over all entries of a packed
repeated field given its id and type. The |wire_type| is necessary for
decoding the packed field, the |cpp_type| is for convenience
&
stronger
typing.
The caller must also supply a pointer to a bool that is set to true if the
packed buffer is found to be malformed while iterating (so you need to
exhaust the iterator if you want to check the full extent of the buffer).
Note that unlike standard protobuf parsers, protozero does not allow
treating of packed repeated fields as non-packed and vice-versa (therefore
not making the packed option forwards and backwards compatible). So
the caller needs to use the right accessor for correct results.
Defined at line 463 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
template <proto_utils::ProtoWireType wire_type, typename cpp_type>
UnifiedRepeatedFieldIterator<wire_type, cpp_type> GetUnifiedRepeated (uint32_t field_id, bool * parse_error_location)
Returns a unified iterator that automatically dispatches between packed and
non-packed repeated field iteration based on the wire format. This allows
parsers to handle both formats without knowing ahead of time which one is
used.
Example usage:
bool parse_error = false;
for (auto it = decoder.GetUnifiedRepeated
<wire
_type, int32_t>(N,
&parse
_error);
it; ++it) { ... }
Defined at line 487 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
Protected Methods
void ParseAllFields ()
void ParseAllFieldsSelective (const uint64_t *dense_mask,Field **spill,uint32_t *spill_capacity,uint32_t *spill_size,std::unique_ptr<Field[]> *heap_spill)
Selective-decoding flavour, driven by SelectiveTypedProtoDecoder. The
spill arguments are in/out and deliberately arguments rather than
members: as members they would cost an initialization per decoder
construction (decoders are constructed per nested message). |*spill| is
repointed at |*heap_spill| if its capacity is exhausted.
void ExpandHeapStorage ()
Called when the default on-stack storage is exhausted and new repeated
fields need to be pushed.
void TypedProtoDecoderBase (Field *storage,uint64_t *presence,uint32_tnum_fields,uint32_tcapacity,const uint8_t *buffer,size_tlength)
Defined at line 507 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h
void SetField (uint32_t id)
Marks the field with the given id as seen: sets bit |id| of the presence
bitmap. |id| must be
<
num_fields_.
Defined at line 536 of file ../../third_party/perfetto/include/perfetto/protozero/proto_decoder.h