Skip to content

Library request: Google Protocol Buffers (protobuf) repeated fields #11

@arthur-tacca

Description

@arthur-tacca

It would be great to add support for repeated fields in Google Protocol Buffers.

Protocol buffers let you define "messages", which are basically like C structs, which have fields that are numeric, string or nested messages. From these definitions you generate code for any of several languages including C++, and this generated code includes methods for serialization to a language-neutral binary format. This library is used in Google projects like gRPC and TensorFlow, but also in lots of non-Google projects like Caffe and Mosh.

The fields can be single or repeated. Unfortunately, the C++ generated code for repeated fields uses their own custom containers. Depending of the type within, you either only see the first element in the debugger, or (usually) just a void* that points to the first element in the container. It would be great if debug visualizers for both types of classes were added to this plugin.

For intrinsic types, the template class google::protobuf::RepeatedField<T> is used. This stores the elements in a contiguous block, like a std::vector. This block is of type RepeatedField<T>::Rep, and the container includes a member of type Rep*. The static type of Rep finishes with a one-element array, which of course is really a multi-element array at runtime, so only the first element shows up in the debugger.

For string and nested messages types, the template class google::protobuf::RepeatedPtrField<T> is used. This also has a nested Rep type that includes an array (of static type length one), except that this is now an array of pointers rather than a direct array of objects. But wait - this is actually done in a non-templated base class called google::protobuf::RepeatedPtrFieldBase, so the static type of the final element of Rep is just void*.

Thanks for considering it!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions