Edward Loper
Edward Loper

Reputation: 15944

Get the parent message of a protobuf message (in python)

Is there any officially supported way to get the parent message for a given ProtoBuf message in Python? The way the Python protobuf interface is designed, we are guaranteed that each message will have at most one parent. It would be nice to be able to navigate from a message to its parent without building an external index.

Clearly, this information is present, and I can use the following code to get a weak pointer to the parent of any given message:

>>> my_parent = my_message._listener._parent_message_weakref

However, this uses internal attributes -- I would much rather use officially supported methods if possible.

If there is no officially supported way to do this, then I'll need to decide whether to build an external child→parent index (which could hurt performance), or to use this "hackish" method (appropriately wrapped).

Upvotes: 5

Views: 1231

Answers (1)

Edward Loper
Edward Loper

Reputation: 15944

After looking into this further (reading the source code), it's clear that there's no officially supported way to do this in Python.

Upvotes: 1

Related Questions