protobuf call by python Posted on 2024-11-05 Edited on 2025-08-06 In dev 1、str转protobuf对象 12345678910from example_pb2 import MyMessage# 假设你有一个包含序列化后的protobuf数据的字符串serialized_data = b'\n\x05Hello'# 解析字符串message = MyMessage()message.ParseFromString(serialized_data)print(message.content) # 输出: Hello 2、protobuf对象转str 123msg_ctrl = jpush_protocol_pb2.JPushProtocol()msg_ctrl.head.ver = 0str = msg_ctrl.SerializeToString()