Header

Basic examples

We give some class-side messages to facilitate the more common uses of serialization and materialization. The next example writes and reads from file:
FLSerializer serialize: 'stringToSerialize' toFileNamed: 'demo.fuel'. 
materializedString := FLMaterializer materializeFromFileNamed: 'demo.fuel'.
We also provide messages for working with ByteArray instances. This can be fine for users of a NoSQL db:
anArray := FLSerializer serializeToByteArray: 'stringToSerialize'. 
materializedString := FLMaterializer materializeFromByteArray: anArray.

FileStream

In this example we work with files. Note that we set the file in binary mode:
FileStream newFileNamed: 'demo.fuel' do: [:aStream |
	FLSerializer newDefault 
		serialize: 'stringToSerialize' 
 		on: aStream binary].

FileStream oldFileNamed: 'demo.fuel' do: [:aStream |
	materializedString := (FLMaterializer newDefault 
		materializeFrom: aStream binary) root].
Note also that we are no longer using the class-side messages of previous examples. Now, for both FLSerializer and FLMaterializer, we first create instances with #newDefault to then perform the desired operations. As we will see in next example, creating the instances brings more possibilities.

Showing a progress bar

Sometimes it is nice to see progress updates on screen:
FileStream newFileNamed: 'numbers.fuel' do: [:aStream |
	FLSerializer newDefault showProgress
		serialize: (1 to: 250000) asArray on: aStream binary ].
	
FileStream oldFileNamed: 'numbers.fuel' do: [:aStream | 
	materializedString := (FLMaterializer newDefault showProgress
		materializeFrom: aStream binary) root ].

Basic examples

We give some class-side messages to facilitate the more common uses of serialization and materialization. The next example writes and reads from file:

FLSerializer serialize: 'stringToSerialize' toFileNamed: 'demo.fuel'. 
materializedString := FLMaterializer materializeFromFileNamed: 'demo.fuel'.

We also provide messages for working with ByteArray instances. This can be fine for users of a NoSQL db:

anArray := FLSerializer serializeToByteArray: 'stringToSerialize'. 
materializedString := FLMaterializer materializeFromByteArray: anArray.

FileStream

In this example we work with files. Note that we set the file in binary mode:

FileStream newFileNamed: 'demo.fuel' do: [:aStream |
	FLSerializer newDefault 
		serialize: 'stringToSerialize' 
 		on: aStream binary].

FileStream oldFileNamed: 'demo.fuel' do: [:aStream |
	materializedString := (FLMaterializer newDefault 
		materializeFrom: aStream binary) root].

Note also that we are no longer using the class-side messages of previous examples. Now, for both FLSerializer and FLMaterializer, we first create instances with #newDefault to then perform the desired operations. As we will see in next example, creating the instances brings more possibilities.

Showing a progress bar

Sometimes it is nice to see progress updates on screen:

FileStream newFileNamed: 'numbers.fuel' do: [:aStream |
	FLSerializer newDefault showProgress
		serialize: (1 to: 250000) asArray on: aStream binary ].
	
FileStream oldFileNamed: 'numbers.fuel' do: [:aStream | 
	materializedString := (FLMaterializer newDefault showProgress
		materializeFrom: aStream binary) root ].