How to deserialize objects in Io?

I found serialized and justSerialized methods for Object and already successfully serialized objects to files, but I cannot find a suitable deserialization method.

Am I or am I too stupid to find him?

+3
source share
1 answer

I think doStringor doMessageshould do what you need (although I cannot confirm this at the moment, because I do not have work on this machine).

For instance,

doString( yourSerializedString )

or

doMessage( yourSerializedString asMessage )


Refresh . Now you can confirm that doStringor doMessageworks. Full example below:

Foo.io

Foo := Object clone do (
    name ::= nil
)

serialize.io

doRelativeFile("Foo.io")

baz := Foo clone setName("baz")

// serialize "baz" object to file
File with("serialized.data") open write(baz serialized) close

restore_object.io

doRelativeFile("Foo.io")

baz := doString(
    File with("serialized.data") open readLines join
)


doRelativeFile doFile:

baz := doRelativeFile("serialized.data")

- Io.

/I3az/

+5

Source: https://habr.com/ru/post/1782157/


All Articles