[squeak-dev] Re: [vwnc] Any serializer can customize serialization
Hernán Morales Durand
hernan.morales at gmail.com
Fri Oct 14 05:25:53 UTC 2011
Thanks for your detailed reply. What you describe seems suitable for
my needs (I'm interested in simplest techniques, my problem is complex
enough to try premature improvements at the tool level :) however I
cannot comment more until I do some real experiments with SRP.
2011/10/12 Paul Baumann <paul.baumann at theice.com>:
> There are several ways to do it with SRP.
> The encoding supports embedded data (variable and fixed width), so you could do inline serialization. It is clever enough that it is even possible to do this with positional access even to base64 encoded data. Tricks like that are used for example to update individual values in a persistent index. There are simpler techniques that should work for any marshaler...
> All marshalers should have some form of pre-save and post-load exchange. SRP has many ways to pre-save and post-load while maintaining relative references. SRP can even do post-load exchanges after the rest of the object graph is loaded and still keep relative references (without using a #become:).
> Save a proxy in place of the object. The proxy would be a class that you create to do what you want as a post-load actions. You can create the proxy as part of a pre-save action. The proxy can have the encoded binary ByteArray you want embedded in the data. The post-load of the proxy would typically unmarshal the embedded data. Here is an example of a class-based exchange:
> SpecialSaveObject>>srpSavePreMap: aContext
> ^MyOtherMarshalProxy newFor: self
> MyOtherMarshalerProxy class>>newFor: anObject
> ^self new save: anObject
> MyOtherMarshalProxy>>save: anObject
> binData := self marshaler saveAsBinary: anObject.
> MyOtherMarshalerProxy>>srpLoadPostMap: aContext
> ^OtherMarshaler loadFromBinary: binData
> Depending on your needs, you might want your object to remember the embedded data. In that case, you could store the encoded data in an inst var that is lazy-initialized as a pre-save action and save only that inst var. A post-load action could perhaps read the other attributes from the encoded data that you saved.
> SRP also allows any object to answer back "extended attributes" that are saved with an object (#srpExtendedAttributes) and can be restored after loading (#srpExtendedAttributes:). Extended attributes are typically data you want associated with an object that is not directly referenced by the object. You could save/load encoded data along with the SRP saved object.
> Paul Baumann
> -----Original Message-----
> From: vwnc-bounces at cs.uiuc.edu [mailto:vwnc-bounces at cs.uiuc.edu] On Behalf Of Hernán Morales Durand
> Sent: Monday, October 10, 2011 15:36
> To: Pharo Development; The general-purpose Squeak developers list; vwnc mailing list
> Subject: [vwnc] Any serializer can customize serialization strategy?
> 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? With external I mean it could
> be in a separate binary (I could arrange the binding though).
> vwnc mailing list
> vwnc at cs.uiuc.edu
> This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.
More information about the Squeak-dev