-1

In my project I use protobuf c for the server and protobuf-net for the client. But protobuf c cannot decode classes where the client uses the "ProtoInclude" attribute.

This is the client code using protobuf-net

[ProtoContract]
public class MsgBase_Demo : MsgBase
{
    /// <summary>   id   </summary>
    [ProtoMember(11)]
    public float id;

    public MsgBase_Demo() 
    {
        protoName = "MsgBase_Demo";
        id = 110; 
    }
}

This is the server code using the protobuf c

message MsgBase_Extent
{
    extend MsgBase
    {
        required MsgBase_Extent msgBase = 1000;
    }
    optional float id = 11;
}

How should I deal with this problem. I tried this https://www.indelible.org/ink/protobuf-polymorphism/Still not working. Maybe I should not adopt the way of inheritance?

273K
  • 29,503
  • 10
  • 41
  • 64
YueYuHai
  • 1
  • 4

1 Answers1

0

It's not a good idea to mix code-first (your C#) and schema-first (your second code block). The whole idea of something like Google Protocol Buffers is that you have a "single version of the truth". If you're mixing languages, you should have a single .proto file (your second code block) and use protoc.exe (or equivalents on other OSes) to output source code for all the different languages you want to use.

The other thing (that I think you already know) is that Google's protoc will not generate C code. It looks like you're already using protobuf-c (from the tags you've attached to the question). Assuming protobuf-c is good, you'd use Google's protoc to generate the C# source code, and protobuf-c's protoc-c to generate the equivalent C code, using the same .proto file as input.

Generate source code from the same .proto file avoids the problem that I think you have run into, which is that your C# code and the .proto in your question are not describing the same thing.

bazza
  • 7,580
  • 15
  • 22