简体   繁体   English

获取protobuf消息的父消息(在python中)

[英]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? 有没有官方支持的方法来获取Python中给定ProtoBuf消息的父消息? The way the Python protobuf interface is designed, we are guaranteed that each message will have at most one parent. Python protobuf接口的设计方式,我们保证每条消息最多只有一个父级。 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). 如果没有官方支持的方法来执行此操作,那么我将需要决定是构建外部子项→父项索引(可能会损害性能),还是使用此“hackish”方法(适当包装)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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