生成协议缓冲区定义 [英] Generating a Protocol Buffers definition

查看:65
本文介绍了生成协议缓冲区定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组专有模式的XML文件-这些XML文件定义了二进制通信协议(消息结构).

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

我想利用Google的协议缓冲区技术.

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

我正在使用现有代码将XML文件加载到对象模型(在内存中).我想从该对象模型生成一个.proto文件.

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.

所以基本上我要寻找的是将.proto文件格式表示为对象模型的代码/库(在C#/.NET中),并且可以将该对象模型保存到.proto文件中.

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.

我看了Jon Skeet的dotnet-protobufs,我想我了解它的作用(基于.proto文件生成c#代码)

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

但是,我没有弄清楚我是否可以在项目中使用它(它那里可能有.proto格式的对象模型,但可能只有可以解析这种格式并且不能写出来的代码)

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)

推荐答案

protobuf-net(我在.NET中的协议缓冲区版本)具有 primitive 支持生成原型文件,但不会很难填补空白.我首先专注于核心引擎,然后再关注从proto生成C#的过程.编写xslt从对象模型生成原型不会有太大不同.不过要花几天的时间(目前我的时间有限).

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.

有关信息,protobuf-net引擎与大多数 XmlSerializer 类(和 DataContractSerializer ,以及最近的 BinaryFormatter )兼容-如果您的代码当前以xml的形式工作,我们可能可以在protobuf-net中使它工作.当然不能保证...

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...

这篇关于生成协议缓冲区定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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