使用 writeObject/readObject 序列化循环对象网络 [英] Serialize circular object networks using writeObject / readObject

查看:26
本文介绍了使用 writeObject/readObject 序列化循环对象网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将实施

public function writeExternal( output:IDataOutput ):void {...}
public function readExternal( input:IDataInput ):void {...}

使一组对象可序列化.

虽然我很确定,我实现的一切都是正确的,readExternal(..) 在某个时候抱怨剩下的数据太少了:

Although I'm pretty sure, that I implemented all correctly, readExternal(..) at a certain point complains about too few data left to read:

RangeError: Error #2006: The supplied index is out of bounds.
    at flash.filesystem::FileStream/readObject()

我想知道,如果我有一个像

I wonder, if I have a circular object network like

A = { left -> B, right -> B }
B = { father -> A }

我打电话给

writeObject( a )

Flex 将孔对象网络和每个对象序列化一次且仅一个吗?

will Flex serialize the hole object network and each object once and only one?

我是这样做的:

  • 声明的类型注解如下:[RemoteClass(alias="model.MyClass")]
  • 实现无参数构造函数
  • 使用实现IExternalizable
  • 声明所有类

SharedObjectsend() 方法保证发送每个对象一次且仅一次.

SharedObject's send() method is guaranteed to send each object once and only once.

附加信息:

请看看这个 相关问题.

推荐答案

元 [RemoteClass] 是用于且仅用于 Flex 编译器识别为使用 Flex 框架的项目中的类的指令.它基本上等同于调用 registerClassAlias(MyClass, "model.MyClass"); 出于多种扩展本主题容量的原因,我建议您改用 registerClassAlias.

The meta [RemoteClass] is an instruction for and only for classes used in projects that Flex compiler identifies as using Flex framework. It is basically equivalent to calling registerClassAlias(MyClass, "model.MyClass"); For a number of reasons that extend the capacity of this topic, I'd suggest that you use registerClassAlias instead.

关于 AMF 内置的 writer,行为如下:如果 writer 收到所有需要写入的对象一次(就像在树中,你给它根节点),然后它只会完整地写入对象一次,下次出现对该对象的引用时,它将使用该引用.但是,如果您不断地向它提供对象,这些对象可能已经被引用(例如通过对 writeExternal 的连续调用),它会将每个对象视为新对象.至少在理论上,它也应该以另一种方式工作.也就是说,如果对象是通过引用序列化的,一旦它们反序列化,就应该使用引用.查看更多代码会有所帮助,尤其是 writeExternal 和 readExternal 的实现以提供更好的答案.

Regarding AMF built-in writer, the behavior is as follows: if the writer receives all objects it needs to write at once (as in a tree, you give it the root node), then it will write fully the object only once, the next time the reference to that object appears, it will use the reference. However, if you continually feed it objects, which may have already been referenced (such as through successive calls to writeExternal) it will treat every object as if it was new. At least theoretically, it should work the other way too. That is if the objects were serialized by reference, once they deserialized, the reference should be used. It would help to see more of your code, particularly the implementation of writeExternal and readExternal to give a better answer.

这篇关于使用 writeObject/readObject 序列化循环对象网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆