Marshaling wrappers
Marshaling wrappers are used to control the dumping technique used for individual objects during by-reference marshaling. SST provides three wrappers suitable for general use.
shallow
Ensures that the wrapped object is dumped as a shallow copy. That is, the object is not exported and the objects in its slots are dumped according to their normal dumping rules. This wrapper is equivalent to defining the individual object as immutable.
deep
Dumps the wrapped object using the by-value mode to copy the entire object graph starting at the object.
reference
Ensures that the wrapped object is dumped as a reference even if it is normally defined as immutable. This wrapper cannot be applied to immediate objects such as Booleans and SmallIntegers.
These wrappers are made available through extensions to Object:
sstAsDeepValue
Answers a deep value marshaling wrapper on the receiver.
sstAsReference
Answers a by reference marshaling wrapper on the receiver.
sstAsShallowValue
Answers a shallow value marshaling wrapper on the receiver.
Wrappers are typically used for defining the marshaling of message arguments at the point of sending or of the return value at the point of return. For example, suppose anArray is to be passed as the argument in the foo: message to some remoteObject (for example, remoteObject foo: anArray). Normally, arrays are considered mutable and are passed by reference. If you want anArray to go as a shallow copy, simply wrap it in a shallow value wrapper (for example, remoteObject foo: anArray sstAsShallowValue). Wrappers can also be nested.
Tip icon
It is important to note that wrappers make no attempt to imitate the objects they wrap. As such, a wrapped object will have a different identity and semantics to the original. It is good practice to only wrap objects when you know that they will be used only in a message send. This practice is especially relevant when nesting wrappers as this requires the modification of the object containing the object being wrapped.
If you use value wrappers, also note that objects dumped by value do not maintain identity outside the object subgraph of which they are a part. In contrast to the by-value marshaling behavior where the same object passed as the first and second arguments are identical at the receiver, if both the first and second are wrapped with separate deep or shallow wrappers, they will not be identical at the receiver. Objects within a particular value wrapped subgraph do however maintain identity (assuming they are not further wrapped).
Last modified date: 04/21/2020