从描述符字符串恢复 .proto 文件.可能的? [英] Restoring .proto file from descriptor string. Possible?

查看:60
本文介绍了从描述符字符串恢复 .proto 文件.可能的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将包含 Protocol Buffers 描述符的字符串反编译回 .proto 文件?

说我有一个很长的字符串

\n\file.proto\u001a\u000ccommon.proto\"\u00a3\u0001\n\nMsg1Request\u0012\u0017\n\u0006common\u0018\u0001 ...

我需要恢复 .proto,不需要完全按照原样,但可以编译.

解决方案

是的,应该可以得到一些接近原始定义的东西.我不知道有任何现有的代码可以做到这一点(希望其他人会这样做).

看看协议缓冲区本身如何处理字符串.

基本上

  1. 将字符串转换为字节(在 Java 中使用 charset="ISO-8859-1"),它将是一个 Protocol-Buffer 消息(format=FileDescriptorProto 在 Java 中).FileDescriptorProto 是作为 Protocol-Buffers 安装的一部分构建的.

  2. 提取Protocol-Buffer消息

  3. 中的数据

这是协议缓冲区编辑器中显示的文件描述符协议

Is it possible to decompile a string containing Protocol Buffers descriptor back to .proto file?

Say I have a long string like

\n\file.proto\u001a\u000ccommon.proto\"\u00a3\u0001\n\nMsg1Request\u0012\u0017\n\u0006common\u0018\u0001 ... etc.

I need to restore .proto, not necessary exactly as it was but compilable.

解决方案

Yes it should be possible to get some thing close get original definition. I do not know of any existing code to do it (hopefully some one else will).

Hava a look at how protocol buffers itself handles the String.

Basically

  1. convert the string to bytes (using charset="ISO-8859-1" in java), it will then be a Protocol-Buffer message(format=FileDescriptorProto in java). The FileDescriptorProto is built as part of the Protocol-Buffers install.

  2. Extract the data in the Protocol-Buffer message

Here is a File-Descriptor protocol displayed in the Protocol-Buffer editor

这篇关于从描述符字符串恢复 .proto 文件.可能的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆