是否可以使用 Java Protobuf 反序列化以下使用 Protobuf-net 序列化的 DerivedMessage?
namespace Test.Protobuf
{
[ProtoBuf.ProtoContract]
[ProtoBuf.ProtoInclude(2550, "Test.Protobuf.DerivedMessage")]
class BaseMessage
{
[ProtoBuf.ProtoMember(1)]
public string MessageId { get; set; }
[ProtoBuf.ProtoMember(2)]
public int CommandId { get; set; }
}
[ProtoBuf.ProtoContract]
class DerivedMessage : BaseMessage
{
[ProtoBuf.ProtoMember(1)]
public int ClientId { get; set; }
[ProtoBuf.ProtoMember(2)]
public string Message { get; set; }
[ProtoBuf.ProtoMember(3)]
public string Description { get; set; }
}
}
DerivedMessage 扩展 BaseMessage,阅读文档解决方案似乎在原型文件中使用嵌套消息,但它不起作用,这是我的原型文件:
package protobuf;
option java_package = "test.protobuf";
option java_outer_classname = "Proto";
message BaseMessage {
optional string message_id = 1;
optional int32 command_id = 2;
}
message DerivedMessage {
optional int32 client_id = 1;
optional string token = 2;
optional string message = 3;
optional string description = 4;
optional BaseMessage base_message = 5;
}
有解决办法吗?
谢谢