ncupper / protobuf-net

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

GetProto does not write the correct .proto messages for classes with inheretance #303

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
My email: franchescamullin at gmail.com

What steps will reproduce the problem?
1. This is my extremely trivial example:

namespace MyLib
{
    [DataContract]
    public abstract class Animal
    {
        [DataMember(Order=1)]
        public int NumberOfLegs = 4;
    }

    [DataContract]
    public class Cat : Animal
    {
        [DataMember(Order = 1)]
        public List<Animal> AnimalsHunted;
    }
}

2.
I am then programmatically adding Cat as a subtype of Animal with a field 
number of 2.

3.
Call GetProto() on Cat, or on Animal.

What is the expected output? What do you see instead?

expected output I thought should be something along the lines of this?

package MyLib;

message Animal {
   optional int32 NumberOfLegs = 1 [default = 0];
   optional Cat Cat = 2;
}

message Cat {
   repeated Animal AnimalsHunted = 1;
}

what I actually get is this:

for Animal: 

package MyLib;

message Animal {
   optional int32 NumberOfLegs = 1 [default = 0];
}

for Cat:

package MyLib;

message Animal {
   optional int32 NumberOfLegs = 1 [default = 0];
}
message Cat {
   repeated Animal AnimalsHunted = 1;
}

What version of the product are you using? On what operating system?
I am using the revision 549 from trunk (the latest one last I checked)

Please provide any additional information below.

I have attached 2 files containing a quick fix I made that gets it working for 
my use case (I just hacked it in there so I hope it's ok :P).

Original issue reported on code.google.com by Franches...@gmail.com on 24 Jul 2012 at 12:54

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks. The GetProto is still very definitely a work-in-progress; I'll take a 
look at these scenario / patch later, thanks.

Original comment by marc.gravell on 24 Jul 2012 at 1:02

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 26 Jul 2012 at 6:31

GoogleCodeExporter commented 9 years ago
Thanks for the fix!!!!!

I think line 1590 in MetaType.cs revision 551 has a slight copy/paste error? It 
looks to me like

 Array.Sort(fieldsArr, SubType.Comparer.Default);

should be

 Array.Sort(subTypeArr, SubType.Comparer.Default);

Original comment by Franches...@gmail.com on 26 Jul 2012 at 7:57

GoogleCodeExporter commented 9 years ago
eek! thanks; it wasn't a show-stopper, since the "as" just means it wasn't 
actually doing any sorting (and thus sub-types would have been in a random 
order) - but definitely better fixed.

Original comment by marc.gravell on 26 Jul 2012 at 8:44