JuliaLang/julia — pull request #4896 by JeffBezanson (2013-11-22 22:51:02+00:00)
Title: WIP: proposed design+implementation of serializing objects with cycles

this design is fully backwards-compatible with all uses and definitions of `serialize` and `deserialize`.

the methodology is as follows:

* serialize to an `IOBuffer`, and do a takebuf when a message is done

* objects that can participate in cycles insert

```
serialize_cycle(io, OBJ) && return
```

at the top of their serialize() methods

* to support deserialization, implement `deserialize(io, ::Type{T}, pos)` and insert

```
deserialize_cycle(pos, OBJ)
```

as soon as the new object `OBJ` is allocated.