Serialize protocol buffer file into xml/text format

304 views
Skip to first unread message

henry

unread,
Oct 10, 2011, 12:06:45 AM10/10/11
to Protocol Buffers
I am using protocol buffer in .net http://code.google.com/p/protobuf-net/.

I installed the visual studio support version, which I can just write
proto file in project and it generates csharp class files
automatically.

A lot of times that I need to dump the files into xml(or another text
format if available) file. I found that there is a method
Serializer.Serialize() which takes an XmlWriter parameter. I tried to
use it but it complains that the protobuf type I defined must be
convertible to System.Xml.Serialization.IXmlSerializable.

In my case, what I should do in order for my type can be convertible
to System.Xml.Serialization.IXmlSerializable? I don't want to change
the cs file directly since it is generated on the fly when the proto
file is changed.

thanks.

Marc Gravell

unread,
Oct 10, 2011, 3:30:47 PM10/10/11
to henry, Protocol Buffers
I answered this where you cross-posted on stackoverflow:

To repeat; in most cases, the generated code **should already** work perfectly well with XmlSerailizer (the inbuilt .NET xml serialization tool), so you shouldn't have to do *anything*. If you want to add helper methods for this to your type, then note that the files are generated as "partial classes", which means you can add additional code files for the same classes, and the compiler will combine them.

If I *still* haven't answered your question, maybe provide a small sample of what you are trying to achieve.

Marc



--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.




--
Regards,

Marc
Reply all
Reply to author
Forward
0 new messages