Hi Sven
I was using STON in P7 and I’m now migrating to P10.
In the past I had no problem with a SortedCollection and now I have because of the block serialisation (of course).
So I cannot really ignore or skip my sorted collection because it has what I want.
I could go over all my collections and transform them into OrderedCollection for the saving.
But may be there is a hook for that.
In fact I do not care to save the sortedCollection as soon as when I reload I restore it.
S
On 4 Nov 2022, at 17:56, stephane ducasse stephane.ducasse@inria.fr wrote:
Hi Sven
I was using STON in P7 and I’m now migrating to P10.
In the past I had no problem with a SortedCollection and now I have because of the block serialisation (of course).
So I cannot really ignore or skip my sorted collection because it has what I want.
I could go over all my collections and transform them into OrderedCollection for the saving.
But may be there is a hook for that.
In fact I do not care to save the sortedCollection as soon as when I reload I restore it.
S
I read
writeObject: anObject
| instanceVariableNames |
(instanceVariableNames := anObject class stonAllInstVarNames) isEmpty
ifTrue: [
self writeObject: anObject do: [ self encodeMap: #() ] ]
ifFalse: [
self writeObject: anObject streamMap: [ :dictionary |
instanceVariableNames do: [ :each |
(anObject instVarNamed: each)
ifNotNil: [ :value |
dictionary at: each asSymbol put: value ]
ifNil: [
anObject stonShouldWriteNilInstVars
ifTrue: [ dictionary at: each asSymbol put: nil ] ] ] ] ]
It would be nice if we could say
MyClass >> transformedInstances
{
#series -> [:each | each asOrderedCollection ] .
}
Or something like that. I was considering to hack my own version of STON to avoid to that in my model.
Or serializing nicely SortedCollection.
May be I missed something obvious.
S
I found
stonProcessSubObjects: block
"Execute block to (potentially) change each of my subObjects.
In general, all instance and indexable variables are processed.
Overwrite when necessary. Not used when #stonContainSubObjects returns false."
1 to: self class instSize do: [ :each |
self instVarAt: each put: (block value: (self instVarAt: each)) ].
(self class isVariable and: [ self class isBytes not ])
ifTrue: [
1 to: self basicSize do: [ :each |
self basicAt: each put: (block value: (self basicAt: each)) ] ]
but I could not really get how to use it and if it was at the moment of writing.
So I will patch my model but to me it defeats the purpose of serialization.
Either we can serialize everything or we can transform to that we can fall back on the stable part.
Forcing clients to prepare the objects to serialize is always possible but less satisfactory.
Because I will have to do it twice. to save
from sorted to ordered
save
from ordered to sorted
and on load
from ordered to sorted.
S
Can you use SortFunctions instead of blocks with the SortedCollections? This is what I finally figured out to do with Fuel most of the time after lots of pain