Henry,

> On 14 Nov 2017, at 15:02, henry <he...@callistohouse.club> wrote:
> 
> Hello, I am trying to extend STON to allow for substitutions as data is 
> written out or read in. On the write side I got it working as #nextPut: is 
> recursively called, so that is the perfect place to substitute before an 
> object is written. I have tested and my changes work well, where I have an 
> arbitrary object as a subObject and it gets substituted out for my Descriptor 
> object.

OK good.

> I am having difficult on the read side identifying where a substitution 
> lookup should occur after decoding the object on the input stream. I want to 
> inflate the Descritpor object, with its data, and call for a possible 
> substitution. As it is a Descriptor, it should get substituted with the right 
> bits on the read side. I chose to try and do this in the method 
> #setReference:to: and put the substitute into the objects list. This did not 
> work. Where is a good place to look within STON to do a read-side 
> post-substitution?

In 

STONReader>>#parseObject
        | targetClass reference object |
        [
                reference := self newReference.
                targetClass := self parseClass.
                object := targetClass fromSton: self.
                self setReference: reference to: object ]
...

I would try just re-assigning object with your custom substitute. Like this

MySTONReader>>#parseObject
        | targetClass reference object |
        [
                reference := self newReference.
                targetClass := self parseClass.
                object := targetClass fromSton: self.
                object := object resolveSubstitution.
                self setReference: reference to: object ]
...

The references are used if the same (#==) object is used twice, then you get 
something like

STON fromString: '[Point[1,2],@2]'.

which is an 2 element Array where the exact same object is in both positions 
(structure sharing). This works with circular references too (but be careful 
because the inspector might loop).

HTH,

Sven

> Thank you.
> 
> - HH
> 
> 


Reply via email to