代码在这里:
var responseMsg = new ResponseMessage()
{
code = ErrorCode.OK,
type = MsgType.LOGIN,
responseStr = "this is local server"
};
var serverStream = new MemoryStream();
ProtoBuf.Serializer.Serialize(serverStream, responseMsg);
Console.WriteLine($"responseMsg {responseMsg?.responseStr ?? "failed"}\n");
var response =ProtoBuf.Serializer.Deserialize<ResponseMessage>(serverStream);
Console.WriteLine($"response {response?.responseStr ?? "failed"}\n");
结果是
responseMsg this is local server
response
ProtoBuf-net无法反序列化它的序列化内容。这真是一件奇怪的事情