使用 writeObject / readObject 序列化循环对象网络
我即将实现
public function writeExternal( output:IDataOutput ):void {...}
public function readExternal( input:IDataInput ):void {...}
一组对象可序列化。
尽管我很确定我实现了所有正确的操作,但在某个时刻 readExternal(..)
抱怨剩下的数据太少了:
RangeError: Error #2006: The supplied index is out of bounds.
at flash.filesystem::FileStream/readObject()
的循环对象网络
A = { left -> B, right -> B }
B = { father -> A }
我想知道,我是否有一个像和这样 我认为
writeObject( a )
Flex会序列化孔对象网络和每个对象一次且仅一次吗?
我这样做了:
- 声明类型注释如下:
[RemoteClass(alias="model.MyClass")]
- 实现无参数构造函数
- 使用
implements IExternalizable
声明所有类
SharedObject 的 send() 方法保证发送每个对象一次且仅一次。
其他信息:
- 读取和写入 ByteArray
- <一href="http://help.adobe.com/en_US/flex/accessingdata/WS2db454920e96a9e51e63e3d11c0bf69084-7fda.html" rel="nofollow noreferrer">使用远程对象组件
- IExternalized 接口
请看一下这个相关问题。
I'm about to implement
public function writeExternal( output:IDataOutput ):void {...}
public function readExternal( input:IDataInput ):void {...}
to make a set of object serializable.
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 }
and I call
writeObject( a )
will Flex serialize the hole object network and each object once and only one?
I did this:
- Declared type annotations like this:
[RemoteClass(alias="model.MyClass")]
- Implemented parameter-free constructors
- Declared all classes using
implements IExternalizable
SharedObject's send() method is guaranteed to send each object once and only once.
Additional infos:
Please have a look at this related question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
元 [RemoteClass] 是一条指令,仅适用于 Flex 编译器识别为使用 Flex 框架的项目中使用的类。它基本上相当于调用
registerClassAlias(MyClass, "model.MyClass");
由于多种原因扩展了本主题的容量,我建议您改用 registerClassAlias。对于 AMF 内置 writer,行为如下:如果 writer 一次性接收到需要写入的所有对象(就像在树中一样,您给它根节点),那么它将写入仅完全使用对象一次,下次出现对该对象的引用时,它将使用该引用。但是,如果您不断地向其提供可能已被引用的对象(例如通过连续调用 writeExternal),它将把每个对象视为新对象。至少从理论上来说,反之亦然。也就是说,如果对象是通过引用序列化的,那么一旦反序列化,就应该使用该引用。查看更多代码,特别是 writeExternal 和 readExternal 的实现,将有助于给出更好的答案。
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.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.