DerrickBrayanClayton / protobuf-net

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

Support Generation of Enum Proto Files #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
An enum and class pair, properly annotated with ProtoContractAttribute and
ProtoEnumAttribute, will correctly serialize and deserialize.  However, one
cannot generate a .proto file for the enum using the
Serializer.GetProto<T>() method because T is constrained only to classes. 
That would be okay if the Serializer.GetProto<T>() method would detect the
enum type while generating the .proto for the containing class, and dump it
out automatically; but that is not the case.

Original issue reported on code.google.com by brian.c....@gmail.com on 19 Aug 2008 at 1:08

GoogleCodeExporter commented 8 years ago

Original comment by brian.c....@gmail.com on 19 Aug 2008 at 1:08

Attachments:

GoogleCodeExporter commented 8 years ago
My assumption is (perhaps incorrectly) that you'd only want to generate a 
.proto for 
a top-level message (which an enum can't be) - but it won't be hard to fix... 
I'll 
see what I can do

Original comment by marc.gravell on 19 Aug 2008 at 1:47

GoogleCodeExporter commented 8 years ago
Have added unit test for this, and the enum is not emitted; I have 
re-classified as 
defect (I incorrectly set it as enhancement) - will fix ASAP.

Original comment by marc.gravell on 19 Aug 2008 at 1:55

GoogleCodeExporter commented 8 years ago
Fixed in r151, available for download

Original comment by marc.gravell on 19 Aug 2008 at 2:34

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thanks for the quick response!

The fix from r151 has a bug.  The declared name of the enum is not honoring
ProtoContractAttribute.Name when the type is output, but it is honored in the
declaration of the referencing message.  So, in the following example, 
generated from
the TestProto.cs I uploaded earlier, "TestEnum" should be called "Type".

message testmsg {
   optional Type type = 1;
   optional string foo = 2;
}
enum TestEnum {
   FOO_KEY = 0;
   BAR_KEY = 1;
}

As an aside, I also noticed that class properties returning nullable bools or 
enums
are generated as type int32.  Is that intentional?

Original comment by brian.c....@gmail.com on 19 Aug 2008 at 6:50

GoogleCodeExporter commented 8 years ago
Second fix applied r153

Original comment by marc.gravell on 20 Aug 2008 at 5:47

GoogleCodeExporter commented 8 years ago
Looks great!  Thanks!

Original comment by brian.c....@gmail.com on 20 Aug 2008 at 6:53

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 23 Sep 2008 at 6:49