Note that there are some explanatory texts on larger screens.

plurals
  1. POMimicing Inheritance in Protobuf-net v2
    primarykey
    data
    text
    <p>So I have a .NET server and an IOS client and I'm trying to use protocol buffers to communicate back and forth. On the server I have one object that contains a list of FormField objects where FormField is actually going to be a subtype of FormField like say ButtonFormField.</p> <p>After doing some research, I implemented my .proto files similar to this: <a href="https://stackoverflow.com/questions/3717500/protobuf-net-proto-file-generation-for-inheritance">Protobuf-net .proto file generation for inheritance</a></p> <p>Which works fine for serializing from the server to the client.</p> <p>Unfortunately when I send items back to the server, I get errors because it is trying to cast FormField as ButtonFormField (which obviously doesn't work) in CompiledSerializer.cs line 49.</p> <p>Does this not work in protobuf-net v2 or am I doing something wrong? I am really hoping to get this working.</p> <p><strong>EDIT*</strong> I tried this using protobuf-net v1 and it does work, so I'm assuming this behavior changes in v2. Is there an alternate way to do this in v2 or am I stuck on v1 for now?</p> <p><strong>Edit 2:</strong> Sorry for the delay Marc. Here is a cut down .proto and the C# classes. I am using protoc to generate the IOS classes, so I am assuming generating C++ or Java with protoc as the client would generate the same effect also. </p> <p><strong>Working Sample Proto File</strong></p> <pre><code>message PersonSelectionFormField { } message TextFormField { } message FormFieldDto { //Properties and optional properties truncated for brevity required int32 Id = 1; required int32 FieldTemplateId = 6; required int32 RowId = 9; optional PersonSelectionFormField PersonSelectionFormField = 55; optional TextFormField TextFormField = 59; } </code></pre> <p><strong>Classes</strong></p> <pre><code>namespace Sample.Fields { //I get a list of FormFields back from the client [ProtoContract] [ProtoInclude(55, typeof(PersonSelectionFormField))] [ProtoInclude(59, typeof(TextFormField))] public class FormField:IFormField { //Cleaned up for brevity...There are virtual methods and fields //getting overriden but they aren't relevant to the example [ProtoMember(1)] public int Id { get; set; } [ProtoMember(6)] [Required] public int FieldTemplateId { get; set; } [ProtoMember(9)] [Required] public int RowId { get; set; } } public class TextFormField:FormField { //Some overriden field / methods. //None of the serialized fields are overriden } public class PersonSelectionFormField:FormField { //Some overriden field / methods. //None of the serialized fields are overriden } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload