Hi, Hernán Morales Durand <[email protected]> wrote: >Is there any serializer (Fuel/StOMP/Ma object >serialization/BOSS/SRP/SIXX??) which let me attach an external >compressor/decompressor for specific Strings to the >serialization/deserialization process?
Mariano Martinez Peck <[email protected]> wrote: > I think StOMP should support this as well: > http://stomp.smalltalk-users.jp/home/how-to-use-stomp/hook-methods Yes. StOMP does support such kind of custom serialization. Pattern 1: Using Memento. StOMP has two basic hook methods (stompWriteValue/stompReadValue). With a memento pattern, you can customize serialization/deserialization behavior easily. SpecificString>> stompWriteValue ^ StringCompressedMemento on: self StringCompressedMemento>> stompReadValue ^ SpecificString on: self uncompressToString SpecificString is a mere wrapper class (holding original string). And StringCompressedMemento should implement compress/uncompress logic. Pattern 2: Subclassing Writer/Reader Pattern 1 is usable, but it is basically suitable for pointer objects. For String-like objects, defining a new String wrapper and Memento is overwhelming. You can also subclass StompWriter/Reader for adding custom serialization/deserialization behaviors. MyStompWriter>>writeString: aString (self isSpecificString: aString) ifTrue: [^super writeString: (self compressString: aString)]. ^ super writeString: string MyStompReader>>readByteString | rawString | rawString := self basicReadObject asString. ^ (self isCompressedString: rawString) ifTrue: [self uncompressString: rawString] ifFalse: [rawString] You have to add some marking headers to the original string for determining it should be compressed/uncompressed. (Yes. this is a little awkward, but works well). I've attached working sample codes. So please see for details. Best regards, -- [:masashi | ^umezawa]
Stomp-Exmaple1.st
Description: Binary data
Stomp-Example2.st
Description: Binary data
