关于python 基于反射的思想去解析protobuf 有些地方卡主了

官方文档地址:
https://googleapis.dev/python/protobuf/latest/google/protobuf/descriptor_pool.html

  1. 官方文档中提到基于反射使用MessageFactory.GetPrototype() 来替代

  2. 找到MessageFactory.GetPrototype() 这个函数参数需要传递一个descriptor

  3. 在descriptor_pool 模块中有有一个类DescriptorPool 中有一个方法FindMessageTypeByName(full_name) ,根据协议名字返回一个descriptor

  4. 就是去构建这个DescriptorPool 对象

从源码中看,DescriptorPool 对象中的AddFileDescriptor 需要传入FileDescriptor 参数

  1. 构建这个FileDescriptor 对象,理想中是根据.proto 文件生成这个对象

但是实际没找到…第五步这里老师们帮忙看看了

你这个这不是官方文档吧,只是google出的,准确性有待考察。 搜准确的在这里找
https://docs.python.org/zh-cn/3/tutorial/index.html

是的,因为要使用python 去解析protobuf ,所以使用了google 的protobuf 库,但是看那个文档有些地方不知道怎么写

可以去 github 搜索一下issue。或者提一下issue。这种开源框架文档最好是直接溯源,找到作者直接提问。一般在github提issue 都会有回复