开发者

Serialize circular object networks using writeObject / readObject

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:

  • Reading and writing a ByteArray
  • Using Remote Object Components
  • IExternalizable interface

Please have a look at this related question.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜