Protobuf-net未序列化列表

问题描述

我目前正在实验protobuf-net(v3.0.29),并尝试对一些简单的类进行序列化/反序列化。从最小的工作示例来看,我不明白为什么protobuf-net将简单的List<int> Value序列化/反序列化为没有元素的列表。

    public enum BigEnum { One,Two }

    [ProtoContract]
    public class Container
    {
        [ProtoMember(1)]
        public BigEnum Parameter { get; private set; }
        [ProtoMember(2)]
        public List<int> Value { get; set; }
        public Container()
        {
            Parameter = BigEnum.One;
            Value = new List<int>();
        }
    }
    static class Program
    {
        static void Main(string[] args)
        {
            Container data = new Container();
            data.Value.Add(-1);
            data.Value.Add(1);

            MemoryStream memStream = new MemoryStream();
            Serializer.Serialize<Container>(memStream,data);
            var result = Serializer.Deserialize<Container>(memStream);
        }
    }

此protobuf文件是由 Serializer.GetProto()生成的,对我来说还不错。 我们如何正确处理List<int> Value,并且protobuf-net可以处理更复杂的结构,例如 一个课程中的List<KeyValuePair<String,String>>Dictionary<int,double>? protobuf-net上有一些非常古老的帖子,周围有字典,但我不知道当前状态是什么。

syntax = "proto3";
package NetCoreProtobuf;

enum BigEnum {
   One = 0;
   Two = 1;
}
message Container {
   BigEnum Parameter = 1;
   repeated int32 Value = 2 [packed = false];
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)