To present the pickling format and algorithm in an intuitive way, we show below an example of how Fuel stores a rectangle.
In the following snippet, we create a rectangle with two points that define the origin and the corner. A rectangle is created and then passed to the serializer as an argument. In this case, the rectangle is the root of the graph which also includes the points that the rectangle references. The first step analyzes the graph starting from the root. Objects are mapped to clusters following some criteria. For this example we only use the criterium by class. In reality Fuel defines a set of other clusters such as global objects (it is at Smalltalk dictionary) or small integer range (i.e., an integer is between 0 and 232 − 1) or key literals (nil true or false), etc.
fuelFile := '/Users/rgb/workspace/test.fuel' asFileReference fullName. aFileStream := (File named: fuelFile) writeStream binary
anOrigin := Point x: 10 y: 20. aCorner := Point x: 30 y: 40. aRectangle := Rectangle origin: anOrigin corner: aCorner. (FLSerializer on: aFileStream) serialize: aRectangle
'/Users/rgb/workspace/test.fuel' asFileReference
loadedRectangle := FLMaterializer materializeFromFileNamed: fuelFile
[ loadedRectangle = aRectangle ] value
[](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Book%3A_Pharo_by_Example_5.0_(Ducasse_Zagidulin_Hess_and_Chloupis)/10%3A_Basic_Classes/10.01%3A_Object)
loadedRectangle class == aRectangle class
MyFirstFLTest
Cf. Serializing Complex Objects with Fuel, Ch. 10 of Cassou et. al., Enterprise Pharo a Web Perspective.
Duplication of Custom Globals
With this following code snippet, we show that by default a Smalltalk global value is not serialized as a global. In such a case it is duplicated on materialization.
"Define a global variable named SomeGlobal." SomeGlobal := Set new.
"Serialize and materialize the value of SomeGlobal." FLSerializer serialize: SomeGlobal toFileNamed: 'g.fuel'.
"The materialized object *is not* the same as the global instance." [ (FLMaterializer materializeFromFileNamed: 'g.fuel') ~~ SomeGlobal ] assert
[ loadedRectangle ~~ aRectangle ] assert.