SmartRefStream has no usable Stream interface. Why?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

SmartRefStream has no usable Stream interface. Why?

marcel.taeumel
Hi, there!

If you want to serialize an object with the SmartRefStream to support addition and removal instance variables in classes, you can do this:

obj := Morph new.
stream := SmartRefStream on: #[] writeStream.
stream nextPutObjOnly: obj.
stream close.
blob := stream contents.
objCopy := (SmartRefStream on: blob readStream) next.

Or your can do this, which produces the traditional "file-in format" with a text header used, for example, when filing out a morph:

obj := Morph new.
stream := SmartRefStream on: (RWBinaryOrTextStream on: '').
stream nextPut: obj.
stream close.
blob := stream contents.
objCopy := (SmartRefStream on: blob readStream asBinaryOrTextStream) nextAndClose.

This is awkward. It took me some time to figure out that I just cannot use the regular stream interface, which I can do with ReferenceStream. And SmartRefStream is just a subclass of it. *sigh*

So, I want to use #nextPut: and #next: just as usual:

obj := Morph new.
stream := SmartRefStream on: #[] writeStream.
stream nextPut: obj.
stream close.
blob := stream contents.
objCopy := (SmartRefStream on: blob readStream) next.

Also, WriteStream DNU #ascii. *sigh*

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: SmartRefStream has no usable Stream interface. Why?

Edgar De Cleene
Some of us are using .obj for long time for limited exchange of simple objects between Cuis,Squeak and Pharo

Object methodsFor: 'objects from disk' stamp: 'edc 6/20/2008 11:41'!
saveOnFileNamed: aString 
"Ask the user for a filename and save myself on a
SmartReferenceStream file. Writes out the version and class structure.
The file is fileIn-able. UniClasses will be filed out.
This save objects as .obj"
| aFileName fileStream |
aString isEmpty
ifTrue: [^ self error: 'name is missing'].
aFileName := aString , '.obj'.
fileStream := ReferenceStream fileNamed: aFileName .
fileStream nextPut: self.
fileStream close.
! !


!Object class methodsFor: 'objects from disk' stamp: 'edc 3/5/2008 12:12'!
readAndInspect: inputStream
| o rr |

rr _ ReferenceStream on: inputStream.
o _ rr next.
rr close.
o inspect! !

!Object class methodsFor: '*services-extras' stamp: 'edc 2/14/2008 08:24'!
fileReaderServicesForFile: fullName suffix: suffix
| services |
services _ OrderedCollection new.
(fullName asLowercase endsWith: '.obj')
ifTrue: [ services add: self serviceLoadObject ].
^services! !

!Object class methodsFor: '*services-extras' stamp: 'edc 7/27/2008 08:11'!
readCompressedObject: aFileStream 
self readAndInspect: (MultiByteBinaryOrTextStream with: (GZipReadStream on: aFileStream) upToEnd) reset! !

!Object class methodsFor: '*services-extras' stamp: 'edc 7/27/2008 07:40'!
serviceCompressedObject
"Answer a service for opening a saved Object"
^ (SimpleServiceEntry
provider: Object
label: 'gz saved Object'
selector: #readCompressedObject:
description: 'open a gz Object'
buttonLabel: 'object')
argumentGetter: [:fileList | 
fileList readOnlyStream]! !

!Object class methodsFor: '*services-extras' stamp: 'edc 2/14/2008 08:26'!
serviceLoadObject
"Answer a service for opening a saved Object"

^ (SimpleServiceEntry 
provider: self 
label: 'saved Object'
selector: #readAndInspect:
description: 'open a Object'
buttonLabel: 'object')
argumentGetter: [:fileList | fileList readOnlyStream]! !


-- 
Edgar De Cleene
Sent with Airmail

On May 10, 2016 at 08:23:08, marcel.taeumel ([hidden email]) wrote:

Hi, there!

If you want to serialize an object with the SmartRefStream to support
addition and removal instance variables in classes, you can do this:

obj := Morph new.
stream := SmartRefStream on: #[] writeStream.
stream nextPutObjOnly: obj.
stream close.
blob := stream contents.
objCopy := (SmartRefStream on: blob readStream) next.

Or your can do this, which produces the traditional "file-in format" with a
text header used, for example, when filing out a morph:

obj := Morph new.
stream := SmartRefStream on: (RWBinaryOrTextStream on: '').
stream nextPut: obj.
stream close.
blob := stream contents.
objCopy := (SmartRefStream on: blob readStream asBinaryOrTextStream)
nextAndClose.

This is awkward. It took me some time to figure out that I just cannot use
the regular stream interface, which I can do with ReferenceStream. And
SmartRefStream is just a subclass of it. *sigh*

So, I want to use #nextPut: and #next: just as usual:

obj := Morph new.
stream := SmartRefStream on: #[] writeStream.
stream nextPut: obj.
stream close.
blob := stream contents.
objCopy := (SmartRefStream on: blob readStream) next.

Also, WriteStream DNU #ascii. *sigh*

Best,
Marcel




--
View this message in context: http://forum.world.st/SmartRefStream-has-no-usable-Stream-interface-Why-tp4894185.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: SmartRefStream has no usable Stream interface. Why?

Chris Muller-3
In reply to this post by marcel.taeumel
I feel your pain!   :)

I wouldn't mind ReferenceStream to just be upgraded to be "smart" and
then deprecate SmartRefStream.  Keeping the nice API of
ReferenceStream, of course.

If Smalltalk is capable to let volatile memory withstand class-schema
changes, I see no reason it should suddenly fail just to thaw cold
storage objects into a newer image..  And no instvar mapping "specs"
are needed, just map them by name...


On Tue, May 10, 2016 at 5:47 AM, marcel.taeumel <[hidden email]> wrote:

> Hi, there!
>
> If you want to serialize an object with the SmartRefStream to support
> addition and removal instance variables in classes, you can do this:
>
> obj := Morph new.
> stream := SmartRefStream on: #[] writeStream.
> stream nextPutObjOnly: obj.
> stream close.
> blob := stream contents.
> objCopy := (SmartRefStream on: blob readStream) next.
>
> Or your can do this, which produces the traditional "file-in format" with a
> text header used, for example, when filing out a morph:
>
> obj := Morph new.
> stream := SmartRefStream on: (RWBinaryOrTextStream on: '').
> stream nextPut: obj.
> stream close.
> blob := stream contents.
> objCopy := (SmartRefStream on: blob readStream asBinaryOrTextStream)
> nextAndClose.
>
> This is awkward. It took me some time to figure out that I just cannot use
> the regular stream interface, which I can do with ReferenceStream. And
> SmartRefStream is just a subclass of it. *sigh*
>
> So, I want to use #nextPut: and #next: just as usual:
>
> obj := Morph new.
> stream := SmartRefStream on: #[] writeStream.
> stream nextPut: obj.
> stream close.
> blob := stream contents.
> objCopy := (SmartRefStream on: blob readStream) next.
>
> Also, WriteStream DNU #ascii. *sigh*
>
> Best,
> Marcel
>
>
>
>
> --
> View this message in context: http://forum.world.st/SmartRefStream-has-no-usable-Stream-interface-Why-tp4894185.html
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: SmartRefStream has no usable Stream interface. Why?

David T. Lewis
In reply to this post by marcel.taeumel
I think that one issue is that SmartRefStream only works on positionable
streams, at least for reading. I looked at this a few years ago when I did
RemoteTask because I could not serialize some kinds of objects across an
OS pipe stream. I think this is fixable, but I never actually did anything
about it (I switched to Fuel, which works well for what I was doing).

Dave

> Hi, there!
>
> If you want to serialize an object with the SmartRefStream to support
> addition and removal instance variables in classes, you can do this:
>
> obj := Morph new.
> stream := SmartRefStream on: #[] writeStream.
> stream nextPutObjOnly: obj.
> stream close.
> blob := stream contents.
> objCopy := (SmartRefStream on: blob readStream) next.
>
> Or your can do this, which produces the traditional "file-in format" with
> a
> text header used, for example, when filing out a morph:
>
> obj := Morph new.
> stream := SmartRefStream on: (RWBinaryOrTextStream on: '').
> stream nextPut: obj.
> stream close.
> blob := stream contents.
> objCopy := (SmartRefStream on: blob readStream asBinaryOrTextStream)
> nextAndClose.
>
> This is awkward. It took me some time to figure out that I just cannot use
> the regular stream interface, which I can do with ReferenceStream. And
> SmartRefStream is just a subclass of it. *sigh*
>
> So, I want to use #nextPut: and #next: just as usual:
>
> obj := Morph new.
> stream := SmartRefStream on: #[] writeStream.
> stream nextPut: obj.
> stream close.
> blob := stream contents.
> objCopy := (SmartRefStream on: blob readStream) next.
>
> Also, WriteStream DNU #ascii. *sigh*
>
> Best,
> Marcel
>
>
>
>
> --
> View this message in context:
> http://forum.world.st/SmartRefStream-has-no-usable-Stream-interface-Why-tp4894185.html
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
>