array := Array with: 1 with: 'Hello' with: Date today.
array sixxString.
'<sixx.object sixx.id="0" sixx.type="Array" >
<sixx.object sixx.id="1" sixx.type="SmallInteger" >1</sixx.object>
<sixx.object sixx.id="2" sixx.type="String" >Hello</sixx.object>
<sixx.object sixx.id="3" sixx.type="Date" >16 June 2002</sixx.object>
</sixx.object>'
Object readSixxFrom: sixxString. "sixxString is the above string"
sws := SixxWriteStream newFileNamed: 'obj.sixx'.
sws nextPut: <object>.
sws nextPutAll: <collection of object>.
sws close.
srs := SixxReadStream readOnlyFileNamed: 'obj.sixx'.
objects := srs contents.
srs close.
Customizing serialization | |
Object>>sixxPrepareWrite | It is called before the instance is written in SIXX. |
Object>>sixxWriteValue | Return the object actually serialized. |
Object>>sixxIgnorableInstVarNames | Specify the instance variables that are not written in SIXX |
Object>>sixxNonReferencableInstVarNames | Specify the instance variables that should not be referenced in SIXX. Values are always written redundantly. It is useful for small literal objects like String, Number, etc. |
Object>>sixxReferenceIdInContext: | Return unique id that can be referenced from other objects in SIXX. It is useful when objects have their own unique id. |
Customizing deserialization | |
Object>>sixxInitialize | It is called immediately after the instance is read from SIXX |
Object>>sixxReadValue | Return the object for the client from the deserialized instance. |
srs := SixxShapeChangeReadStream on: oldSixx readStream.
srs shapeChangers at:#SmallIntegerOLD put: SmallInteger . "simple renaming"
srs shapeChangers at: #SixxShapeChangedObject put: SixxMockShapeChanger.
"You can implement ShapeChanger for more complex conversion. "
YourShapeChanger>>shapeChangedObjectClass) | Return a newly introduced class for old instances. |
YourShapeChanger>>sixxInstVarNamed: varName put: value) | Override this method for setting converted values to the shape changed object. |
YourShapeChanger>>initializeShapeChangedObject | Override this method for setting newly introduced values to the shape changed object. |
sixxInstVarNamed: varName put: value
"#oldNamedVar1 inst var was renamed to #renamedAtt1"
varName == #oldNamedVar1 ifTrue: [^self attributesMap at: #renamedAtt1 put: value].
"#oldNamedVar2 inst var was removed."
varName == #oldNamedVar2 ifTrue: [^self].
super sixxInstVarNamed: varName put: value
obj := SixxContext evaluate: [Object readSixxFrom: oldSixx]
shapeChangersBy: [:shapeChangers | shapeChangers at: #SixxShapeChangedObject put: SixxSomeShapeChanger].
array := #(1 2 3 4 5).
array sixxString. "print it"
'<sixx.object sixx.id="0" sixx.type="Array" >
<sixx.object sixx.id="1" sixx.type="SmallInteger" >1</sixx.object>
<sixx.object sixx.id="2" sixx.type="SmallInteger" >2</sixx.object>
<sixx.object sixx.id="3" sixx.type="SmallInteger" >3</sixx.object>
<sixx.object sixx.id="4" sixx.type="SmallInteger" >4</sixx.object>
<sixx.object sixx.id="5" sixx.type="SmallInteger" >5</sixx.object>
</sixx.object>'
SixxContext formatters: {SixxMockLiteralArrayFormatter on: Array}.
'<sixx.object sixx.id="0" sixx.type="Array" sixx.formatter="SixxMockLiteralArrayFormatter" >
<sixx.object sixx.id="1" sixx.type="String" >#(1 2 3 4 5)</sixx.object>
</sixx.object>'
SixxContext resetFormatters.
SixxContext applyFormatters: {SixxMockLiteralArrayFormatter on: Array} while: [
array sixxString.
]
SixxContext evaluate: [array sixxString]
formattersBy: [:formatters | formatters add: (SixxMockLiteralArrayFormatter on: Array)].