Smalltalk offers various ways to store and retrieve objects to/from the external world.
For textual storage of non-recursive objects, you can also use the well-known
#storeOn:
/ #readFrom:
methods.
For a very compact binary encoding of arbitrary object hierarchies (can be recursive),
you would use #storeBinaryOn:
/ #readBinaryFrom:
.
Both of the above are described in "Binary Object Storage".
XML storage as described here allows for other XML tools to interact more easily with Smalltalk storage files.
The scheme writes all named and indexed instance variables.
Unassigned slots (nil-valued) are skipped.
For example:
generates a datafile containing a representation of the stored array.
|myObject outStream|
myObject := Array with:'hello world'
with:1.2345
with:#(1 2 3 4 5)
with:('ne' -> #one)
with:nil.
myObject at:5 put:myObject.
outStream := 'data.xml' asFilename writeStream.
(XMLStandardCoder on:outStream) nextPut:myObject.
outStream close.
From this, the object can be reconstructed:
|restoredObject|
restoredObject := (XMLStandardDecoder on:('data.xml' asFilename readStream)) next.
restoredObject inspect.
We are working on a scheme which is both easy to use and flexible enough to support a wide range of formats.
[... expect more to come soon...]
Copyright © 2008 eXept Software AG
<cg at exept.de>