leejw51 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

Simple sample problem #140

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
I started to investigate "protocol buffer" and started from "Getting Started" 
(http://code.google.com/p/protobuf-net/wiki/GettingStarted) page.

1. Samples from http://code.google.com/p/protobuf-net/wiki/GettingStarted
2. I prepared (VS2010, .NET4) binary file person.bin.
3. When I tried to create .cs file from person.bin with help of protogen.exe by 
command line "protogen.exe" -i:..\person.protobin -o:person.cs" next file was 
created:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

Thank you,
Igor.

Original issue reported on code.google.com by igor.zc on 10 Nov 2010 at 3:12

GoogleCodeExporter commented 9 years ago
Can you clarify what you did in step 2, and what exactly person.protobin 
contains? I am unclear whether this is:

- a .proto schema file (text), renamed
- a .proto schema file (binary, via protoc)
- protobuf data, as produced from Serialize

if it is the 3rd, that is not the intended usage; by that point you *already 
have* classes (you must have, to have generated a file). The protogen tool is 
intended for use with schema files, but it is not *necessary* to do this to use 
protobuf-net

Original comment by marc.gravell on 10 Nov 2010 at 10:05

GoogleCodeExporter commented 9 years ago
Hi marc,

In "step 2" I prepared sample (see attached .cs files) and run it.
As result of the running sample, a binary file "person.protobin" was created.
So, file person.protobin contains binary serialization data.

Now I understand, protogen works with schema file (not binary serialization).

Can I convert binary file to a text file?
Could you add to "Getting Started" page relevant schema for the published 
sample.

I am beginner in "protobuf" and, to understand the thing, I want to link "new 
protobuf domain" with known "xml domain".

I guess, if "Getting Started" will be expanded, it will help to us to 
investigate the technology and, probably, to start use it in our projects.

Thank you,
Igor.

Original comment by igor.zc on 11 Nov 2010 at 12:19

Attachments:

GoogleCodeExporter commented 9 years ago
Protobuf-net is inherently a binary serializer, not a text serializer. There 
*is* an alternative text format associated with the protocol, but this is 
rarely used so is not provided here (you lose most of the benefits). However, 
it is almost always possible (very easily) to use protobuf-net and 
XmlSerializer against the exact same class model. 

Here is an example of such a model: 
http://stackoverflow.com/questions/4143421/4143614#4143614

If you need to retain your existing xml attributes (in particular for 
[XmlAttribute]) then simply use [ProtoContract]/[ProtoMember(n)] to describe 
the protobuf behaviour, retaining [XmlType],[XmlElement],[XmlAttribute] etc for 
XmlSerializer's use.

Original comment by marc.gravell on 11 Nov 2010 at 1:37

GoogleCodeExporter commented 9 years ago
Thank you.
Igor.

Original comment by igor.zc on 11 Nov 2010 at 2:48