简体   繁体   中英

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).

在进一步研究之后(阅读源代码),很明显在Python中没有官方支持的方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM