Marshaling
The SST marshaling framework supports the conversion of application objects into communication messages and vice versa. That is, the marshalers take in Smalltalk objects (requests) and output messages which a transport can manipulate (an instance of
SstCommunicationMessage from
Communication messages). Similarly they take in communication messages and output Smalltalk objects (requests).
As with most parts of SST, you are free to plug in your own marshaler as long as it conforms to the API specified below. The classes and methods related to marshaling in general are contained in the SstMarshaling application. SST supplies two general purpose message marshalers: one based on the Swapper and the other designed specifically for SST and optimized for its typical use-cases. These marshalers are in the applications SstSwapperMarshaling and SstLightweightMarshaling respectively.
The basic message marshaler API is defined as follows in the abstract class SstMessageMarshaler:
messageForErrorReplyTo: requestId using: message error: error
Builds and returns a communications level message suitable for use in sending a transport level reply. It uses the information and resources provided by @requestId (the ID of the request to which you are replying), @message, and @error (the error object). @message should be an empty communications message of the class indicated by the transport being used to send the reply. This method is intended to be used when you need to build a message and cannot tolerate errors in doing so. @error is typically converted to a string for inclusion in the reply.
messageForReply: reply for: request using: message
Builds and returns the communications level equivalent of @reply suitable for use in sending a transport level reply. It uses the information and resources provided by @request (the request to which @reply is the reply) and @message. @message should be an empty communications message of the class indicated by the transport being used to send the reply. If an error occurs, return the error.
messageForRequest: request for: requestId using: message
Builds and returns the communications level equivalent of @request (having ID @requestId) using the resources defined by @message. @message should be an empty communications message of the class indicated by the transport being used to send the reply. If an error occurs, return the error.
loadRequestFrom: message
Loads and returns the SST request represented by @message. If there is a problem loading the request, it returns a request as defined by either of the following methods on the receiver:
replyForRemoteMarshalError:with:
Uses if @message is an indication that a remote machine was not able to unmarshal a message.
requestForLocalMarshalError:withHeader:
Uses if the receiver was not able to understand the contents of @message.
In some applications (such as mixed legacy and Smalltalk) more than one marshaling strategy is required. This requirement is easily implemented by implementing the marshaling methods to first consider which marshaling mechanism is best for a given message and then apply the corresponding marshaler. The exact nature of the different mechanisms and how they are discriminated is application-specific.
An example of this is the HTTP marshaler (SstHttpMarshaler) which uses the standard HTTP content-type header field to determine the format of the request's body. If the request contains a marshaled Smalltalk request then the body of the message is passed to another marshaler and the corresponding request object returned.
Last modified date: 09/19/2018