Server Smalltalk Guide : Marshaling : Marshaling with Swapper : Advanced Swapper-based marshaling
Advanced Swapper-based marshaling
Tip icon
This section is an advanced topic and covers how to build your own marshalers or marshaling schemes. For the most part, you will not need to know about or use these capabilities unless you are optimizing performance or customizing behavior.
Loading and dumping strategies define all aspects of SST marshaling with the Swapper. They are much like configurations in that you declaratively define the behavior they require and the strategies coordinate the loader or dumper activities accordingly.
For example, when a dumper needs to calculate the object dumping replacement for a particular object, it typically sends dumpingReplacementForReplacer: to the object itself. Sending this method allows objects to play a role in deciding how they are dumped. Unfortunately, there can only be one definition of this method for a particular class. If two systems need to override this method, a fundamental conflict occurs.
The Swapper routes all such messages through the strategy. This design gives you a centralize point of control over the messages sent to the objects being marshaled. For example, the standard SST by-reference marshaling strategy uses the method sstBRDumpingReplacementForReplacer: rather than dumpingReplacementForReplacer: to define their dumping behavior. This is programmed by overriding the standard strategy method as shown below:
dumpingReplacementFor: anObject for: replacer
^anObject sstBRDumpingReplacementForReplacer: replacer
Notice that this method simply redispatches the request but with a new, method selector (sstBR and so on) which is specific to the marshaling scheme. Similar methods defined on strategies are given below.
definesClassBasedReplacementFor: aClass
Answers true if @aClass defines class-based replacement for its instances.
definesInstVarReplacementFor: aClass
Answers true if @aClass defines instVar replacement for its instances.
definesLoadingReplacementFor: aClass
Answers true if @aClass defines a loading replacement for its instances.
dumpingReplacementFor: anObject for: replacer
Answers the replacement for @anObject when dumping within the scope of the SST BR marshaling scheme. This is used to replace instances of a given class by another object, perhaps of another class.
dumpingReplacementForInstVar: anInteger ofObject: anObject for: replacer
Returns a possibly new object that will replace the receiver's instance variable number @anInteger when dumping within the scope of the SST BR marshaling scheme. This is useful when you want to replace "fields" of a given object by another object.
loadingReplacementFor: anObject for: replacer
Returns the object that will replace @anObject when loading within the scope of the SST BR marshaling scheme.
Note that the BR marshaling scheme is layered on top of the standard the Swapper scheme. You should consider layering your marshaling requirements in this way to avoid conflicts when your systems must be used in concert with others'.
Last modified date: 04/21/2020