Generating a Protocol Buffers definition

杀马特。学长 韩版系。学妹 提交于 2019-12-06 09:19:12

问题


I have a large set of XML files of a propriatary schema -the XML files define binary communication protocol (message structure).

I'd like to leverage Google's protocol buffers technology.

I am using existing code to load the XML files into an object model (in memory). I'd like to generate a .proto file from that object model.

so basically what I am looking for is code/library (in C#/.NET) that represents the .proto file format as an object model and can save that object model into a .proto file.

I took a look at Jon Skeet's dotnet-protobufs, I think I understand what it does (generate c# code based on .proto files)

However, I didn't figure out if I can use it for my project (it probably has the .proto format object model there, but probably only code that can parse this format and not write it out)


回答1:


protobuf-net (my version of protocol buffers in .NET) has primitive support for generating proto files, but it wouldn't be hard to fill in the blanks. I concentrated on the core engine first, then the generation of C# from proto. Writing an xslt to generate a proto from the object model wouldn't be much different. It would take a few days though... (I have limited time at the moment).

If this would be useful, please let me know.

For info, the protobuf-net engine is compatible with most XmlSerializer classes (and DataContractSerializer, and recently BinaryFormatter) - so if your code currently works as xml, we can probably get it working in protobuf-net. No guarantees, of course...




回答2:


My code can only serialize and deserialize to binary and text. However, I believe Marc Gravell's project has XML capabilities. In fact, I believe he generates C# code based on loading the binary version of a .proto file (which is itself encoded as a protobuf), writing it out as XML, and then applying XSLT to it...



来源:https://stackoverflow.com/questions/342270/generating-a-protocol-buffers-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!