views:

515

answers:

2

Hi, 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)

+2  A: 

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

Jon Skeet
Indeed I do; I've been meaning to add code to fill in a descriptor from the in-memory model, serialize the descriptor as xml, then run that through an xslt to generate proto - i.e. the exact opposite of what it does now. It should work, though... a few days effort, though.
Marc Gravell
+2  A: 

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

Marc Gravell
Very interresting! Does it support this now?
asgerhallas
There is some code, but I can't stand by the ouput - the proto generation is experimental at best. Oddly enough, the proto-to-C# is much more developed, even though that was a complete afterthought! Serializer<T>.GetProto()...
Marc Gravell