Ma Serializer
Last updated at 1:12 pm UTC on 26 June 2018
The purpose of a Serializer is to convert domain objects to a String or ByteArray, and back. This representation of an object allows it to be stored on disk or sent over a networks, whereupon it can be converted back to an object for live processing by an application.
Ma Serializer is a serializer for Squeak which:
- Provides a simple API for serializing and materializing objects to/from disk, a stream, or a ByteArray.
- Is format compatible with earlier versions of Squeak, including prior image formats, and plan to remain compatible with all future versions.
- Supports serialization and materialization of partial graphs.
- Plenty of pre, post, and substitution hooks for special needs support.
- Can support application-specific attributes in the serialized buffers.
- Maintains object transparency and traversability in its serialized state. An API for traversing the serialized graph and easily examining and/or processing the sub objects in their serialized state, without ever materializing instances of the classes they represent, is provided.
- Serializes above the Smalltalk meta-layer, providing its own meta-description of classes, similar to MCClassDefinition.
- Is the serializer and format used by Ma client server and Magma.
Installation
It can be installed from the SqueakMap UI, or via this Smalltalk code script:
Installer new merge: #maInstaller.
(Smalltalk classNamed: #MaInstaller) new merge: #serializerTests
Note:Loading Ma Serilalizer is currently included in the Ma "Base" layer which also has some extra classes and methods used by multiple applications, but not used or needed by Ma Serializer itself. These can be unloaded or, if there is interest, put exclusively into their own package.
Simplest Use, Save/Load an Object from the filesystem
To save an object to a file:
mySerializer
fileOut: myObject
toFileNamed: theFilename
in: theFileDirectory
To load an object from a file:
MaObjectSerializer fileIn:
Effective Serialization
A serializer is useful to the extent it allows state to be seamlessly transferred between Smalltalk images. Any object which might be serialized is of a particular class. It may have references to objects which are outside the purview of its domain, such as the Transcript, or Smalltalk, or the current World. For these kinds of objects it must establish, and then restore, to the proper references in the target image, not create duplicate Smalltalk, Transcript or World objects. Ma Serializer handles this automatically.
Example use case
Ma Serializer was used to get the SSRepository object (the root object of http://source.squeak.org) out of the 3.11 image and into a 5.1.