例外:子消息无法正确读取

时间:2013-06-01 08:33:33

标签: c# .net exception deserialization protocol-buffers

在使用protobuf-net对c#中的大文件(20GB)进行反序列化时,我得到"Sub-message not read correctly" Exception。读取2 GB的20 GB后发生异常。 相同的数据结构适用于较小的实例。

20 MB数据的序列化工作正常。

以下是序列化的一些示例代码:

            if (File.Exists(filename))
                File.Delete(filename);

            using (FileStream stream = new FileStream(filename, FileMode.Create))
            {
                Serializer.Serialize<HubLabelingData>(stream, data);
                stream.Close();
            }

以下是反序列化的一些示例代码:

            using (FileStream stream = new FileStream(filename, FileMode.Open))
            {
                data = Serializer.Deserialize<HubLabelingData>(stream);
                stream.Close();
            }

这是数据结构(适用于小实例):

[ProtoContract]
public class HubLabelingData
{
    [ProtoMember(1)]
    public HL[] hlf;

    [ProtoMember(2)]
    public HL[] hlb;

    [ProtoMember(3)]
    public NG g;

    [ProtoMember(4)]
    public List<PL> plf;

    [ProtoMember(5)]
    public List<PL> plb;

    [ProtoMember(6)]
    public PHL[] pihlf;

    [ProtoMember(7)]
    public PHL[] pihlb;
}

[ProtoContract]
public class HL
{
    [ProtoMember(1)]
    public int[] l;

    [ProtoMember(2)]
    public double[] d;
}

[ProtoContract]
public class PL
{
    [ProtoMember(1)]
    public Dictionary<int, List<GP>> p;
}

[ProtoContract]
public class PHL
{
    [ProtoMember(1)]
    public short[] l;
}

[ProtoContract]
public class NG
{
    [ProtoMember(1)]
    public NA[] e;

    [ProtoMember(2)]
    public NA[] tne { get; set; }

    [ProtoMember(3)]
    public float[] a;

    [ProtoMember(4)]
    public float[] o;

    [ProtoMember(5)]
    public int num = 0;

}

[ProtoContract]
public class NA
{
    [ProtoMember(1)]
    public int one { get; set; }

    [ProtoMember(2)]
    public int two { get; set; }

    [ProtoMember(3)]
    public double tree { get; set; }

    [ProtoMember(4)]
    public int four { get; set; }

}

[ProtoContract]
public class NN
{
    [ProtoMember(1)]
    public List<NA> nas;

}

[ProtoContract]
public class GP
{
    [ProtoMember(1)]
    public float one { get; set; }

    [ProtoMember(2)]
    public float two { get; set; }

}

2 个答案:

答案 0 :(得分:1)

对于遇到同样问题的每个人:

Protbuf.net不支持反序列化大于2.048 GB的文件(分别为对象)。

我将数据拆分成多条消息。更多的工作,但它的工作完美。

答案 1 :(得分:0)

protobuf-net支持从v2.2.0开始对大于2GB的流进行反序列化,但有警告。

从v2.0.0.668迁移到v2.3.13对我来说已经解决了此问题,以前我遇到了"Sub-message not read correctly"异常。

Release notes