小编Mar*_*cus的帖子

序列化前缀树

我得到一个ProtoException("可能的递归检测到(偏移:4级):o EOW")序列化树结构时如下:

var tree = new PrefixTree();
        tree.Add("racket".ToCharArray());
        tree.Add("rambo".ToCharArray());
        using (var stream = File.Open("test.prefix", FileMode.Create))
        {
            Serializer.Serialize(stream, tree);
        }
Run Code Online (Sandbox Code Playgroud)

树实现:

[ProtoContract]
public class PrefixTree
{
    public PrefixTree()
    {
        _nodes = new Dictionary<char, PrefixTree>();
    }

    public PrefixTree(char[] chars, PrefixTree parent)
    {
        if (chars == null) throw new ArgumentNullException("chars");
        if (parent == null) throw new ArgumentNullException("parent");
        if (chars.Length == 0) throw new ArgumentException();

        _parent = parent;
        _nodes = new Dictionary<char, PrefixTree>();
        _value = chars[0];

        var overflow = chars.SubSet(1);
        if (!overflow.Any()) …
Run Code Online (Sandbox Code Playgroud)

c# tree protobuf-net

7
推荐指数
1
解决办法
508
查看次数

标签 统计

c# ×1

protobuf-net ×1

tree ×1