什么是处理与protobuf网亲子关系的最佳途径 [英] What is the Best Way to handle Parent-Child relationships with ProtoBuf-Net
问题描述
这异常被抛出在与protobuf的序列化我的测试应用程序
This exception is being thrown on my test application for serializing with ProtoBuf.
SceneryFile:temp.ad2
ProtoBuf.ProtoException: Possible recursion detected (offset: 2 level(s): SceneryFile: temp.ad2
at ProtoBuf.ProtoWriter.CheckRecursionStackAndPush(Object instance( in c:\protbuf-net\protobuf-net\ProtoWriter.sc:line321
我发现这些其他问题
我的树的深度只有4我看看我是否能修改 protobuf的。 ProtoWriter.RecursionCheckDepth
,但我无法找到一个方法来做到这一点在我的代码。
The depth of my tree is only 4. I looked to see if I can change the ProtoBuf.ProtoWriter.RecursionCheckDepth
but I could not find a way to do that in my code.
根据马克的回答最后一个问题,我认为这通过引用意味着相同的对象实例被称为再次 - 所以在我的情况下SceneryFile是指本身或称为别处(实际上它是基类)。这是所有的孩子直接抱到它的参考意义。这里的答案似乎暗示这可能是问题所在:基于第二个问题上面我从序列中删除父,这确实停止这一问题的调查结果。
Based on Marc's answer to the last question I think it means by reference that the same object instance is being referred to again - so in my case the SceneryFile is referring to itself or is referred to somewhere else (actually it is the base class). It is in the sense that all the direct children hold a reference to it. The answer here seems to suggest this might be the problem:
。
有一些办法可以让我继续引用父如在序列化或做我需要做的是这样使用索引父,然后重建时,我反编译的图形?
Is there some way to allow me to keep the reference to the parent as is in the serialization or do I need to do something like use an index for the parent and then reconstruct the graph when I decompile?
感谢
推荐答案
在递归深度检查是一个优化的细节的仅:避免经常检查递归每个对象的开销,只检查深度高于此。它使的是什么/是无效的没有什么区别。
The "recursion check depth" is an optimisation detail only: to avoid the overhead of constantly checking every object for recursion, it only checks if the depth is higher than this. It makes no difference to what is/isn't valid.
这里有两种方法。我的首选是只连载儿童的关系,并使用后反序列化回调然后遍历的孩子和他们的设置parent属性。这样做是通过回调属性,通常的代码5十岁上下行。
There are two approaches here. My preferred would be to just serialise "child" relationships, and use an after-deserialization callback that then loops over the children and sets their parent property. This is done via callback attributes, and is usually 5-ish lines of code.
另外就是要告诉protobuf网尊重的引用(设置AsReference为true成员)。这改变了布局,使它不适当的,如果你想互操作到不同的(非protobuf网)实现。
The other is to tell protobuf-net to respect references (set AsReference to true on the members). This changes the layout, making it inappropriate if you want to interop to a different (non protobuf-net) implementation.
我可以添加两个例子IR要么,但不在一个电话!
I can add examples of both ir either, but not on a phone!
这篇关于什么是处理与protobuf网亲子关系的最佳途径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!