Help "migrating" from classic streams to XStreams

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

Help "migrating" from classic streams to XStreams

Mariano Martinez Peck
Hi guys. We are developing Fuel with Martin Dias. Fuel is a binary serializer similar to Parcels. More info in http://rmod.lille.inria.fr/web/pier/software/Fuel

For the moment, we are using the "classic" streams we want to give it a try to XStreams. My knowledge on streams is very little, so if someone can give me a hint I would really appreciate it.
What I want to do right now is an adaptor of XStreams to classic stream. I mean, I want to create custom subclasses of XTFileWriteStream and XTFileReadStream that implements the same API from classic streams that we use in Fuel. And the implementations of such methods will do just a "self something" where something is the way of doing that in XStreams.

So, the following is the protocol we use in Fuel for streams, and what I would love to know is the associated way to do it it XStreams. The left is classic streams, and after the "->" it is XStreams:

Reading:

nextNumber: -> ??
nextPutAll: -> write:
nextStringPut: -> ??
nextPut:  -> put: 
nextNumber:put: -> ??
nextWordPut: -> ??

Writing:

nextNumber: -> ??
next:  -> read:
nextString -> ??
next  -> get
nextWord -> ??

Thanks a lot in advance,


--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: Help "migrating" from classic streams to XStreams

Nicolas Cellier
Don't do it exclusively for file, but do it for every XTream
One way to do it would be with a wrapper.
I mean create a new subclass of XTReadStream, say
XTCompatibilityReadStream  implement the compatibility methods you
want.
Same for WriteStream.
You'll have to define a few XTream messages too that delegates to the
source/destination

blah
    ^source blah

foo
    ^destination foo


Then define something like

XTReadStream>>classicalStreamAPI
    ^XTCompatibilityReadStream on: self

My 2c.

Nicolas

2011/5/13 Mariano Martinez Peck <[hidden email]>:

> Hi guys. We are developing Fuel with Martin Dias. Fuel is a binary
> serializer similar to Parcels. More info in
> http://rmod.lille.inria.fr/web/pier/software/Fuel
>
> For the moment, we are using the "classic" streams we want to give it a try
> to XStreams. My knowledge on streams is very little, so if someone can give
> me a hint I would really appreciate it.
> What I want to do right now is an adaptor of XStreams to classic stream. I
> mean, I want to create custom subclasses of XTFileWriteStream and
> XTFileReadStream that implements the same API from classic streams that we
> use in Fuel. And the implementations of such methods will do just a "self
> something" where something is the way of doing that in XStreams.
>
> So, the following is the protocol we use in Fuel for streams, and what I
> would love to know is the associated way to do it it XStreams. The left is
> classic streams, and after the "->" it is XStreams:
>
> Reading:
>
> nextNumber: -> ??
> nextPutAll: -> write:
> nextStringPut: -> ??
> nextPut:  -> put:
> nextNumber:put: -> ??
> nextWordPut: -> ??
>
> Writing:
>
> nextNumber: -> ??
> next:  -> read:
> nextString -> ??
> next  -> get
> nextWord -> ??
>
> Thanks a lot in advance,
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Help "migrating" from classic streams to XStreams

Nicolas Cellier
Of course, another way is simply to define a
*XTream-classic-API-compatibility in upper level XTReadStream, but
that's less fun :)

Nicolas

2011/5/13 Nicolas Cellier <[hidden email]>:

> Don't do it exclusively for file, but do it for every XTream
> One way to do it would be with a wrapper.
> I mean create a new subclass of XTReadStream, say
> XTCompatibilityReadStream  implement the compatibility methods you
> want.
> Same for WriteStream.
> You'll have to define a few XTream messages too that delegates to the
> source/destination
>
> blah
>    ^source blah
>
> foo
>    ^destination foo
>
>
> Then define something like
>
> XTReadStream>>classicalStreamAPI
>    ^XTCompatibilityReadStream on: self
>
> My 2c.
>
> Nicolas
>
> 2011/5/13 Mariano Martinez Peck <[hidden email]>:
>> Hi guys. We are developing Fuel with Martin Dias. Fuel is a binary
>> serializer similar to Parcels. More info in
>> http://rmod.lille.inria.fr/web/pier/software/Fuel
>>
>> For the moment, we are using the "classic" streams we want to give it a try
>> to XStreams. My knowledge on streams is very little, so if someone can give
>> me a hint I would really appreciate it.
>> What I want to do right now is an adaptor of XStreams to classic stream. I
>> mean, I want to create custom subclasses of XTFileWriteStream and
>> XTFileReadStream that implements the same API from classic streams that we
>> use in Fuel. And the implementations of such methods will do just a "self
>> something" where something is the way of doing that in XStreams.
>>
>> So, the following is the protocol we use in Fuel for streams, and what I
>> would love to know is the associated way to do it it XStreams. The left is
>> classic streams, and after the "->" it is XStreams:
>>
>> Reading:
>>
>> nextNumber: -> ??
>> nextPutAll: -> write:
>> nextStringPut: -> ??
>> nextPut:  -> put:
>> nextNumber:put: -> ??
>> nextWordPut: -> ??
>>
>> Writing:
>>
>> nextNumber: -> ??
>> next:  -> read:
>> nextString -> ??
>> next  -> get
>> nextWord -> ??
>>
>> Thanks a lot in advance,
>>
>>
>> --
>> Mariano
>> http://marianopeck.wordpress.com
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Help "migrating" from classic streams to XStreams

Nicolas Cellier
And concerning nextNumber nextString etc... this supposes a certain
format, we can't guess.
If you have a DSL for your data with known grammar, you could try a PEG parser.

Otherwise, if your data are in a classical Smalltalk format in ASCII,
you could use Number readFrom: yourXTCompatibilityReadStream.
Otherwise if you have a specific binary encoded data, it's up to you...

Nicolas

2011/5/13 Nicolas Cellier <[hidden email]>:

> Of course, another way is simply to define a
> *XTream-classic-API-compatibility in upper level XTReadStream, but
> that's less fun :)
>
> Nicolas
>
> 2011/5/13 Nicolas Cellier <[hidden email]>:
>> Don't do it exclusively for file, but do it for every XTream
>> One way to do it would be with a wrapper.
>> I mean create a new subclass of XTReadStream, say
>> XTCompatibilityReadStream  implement the compatibility methods you
>> want.
>> Same for WriteStream.
>> You'll have to define a few XTream messages too that delegates to the
>> source/destination
>>
>> blah
>>    ^source blah
>>
>> foo
>>    ^destination foo
>>
>>
>> Then define something like
>>
>> XTReadStream>>classicalStreamAPI
>>    ^XTCompatibilityReadStream on: self
>>
>> My 2c.
>>
>> Nicolas
>>
>> 2011/5/13 Mariano Martinez Peck <[hidden email]>:
>>> Hi guys. We are developing Fuel with Martin Dias. Fuel is a binary
>>> serializer similar to Parcels. More info in
>>> http://rmod.lille.inria.fr/web/pier/software/Fuel
>>>
>>> For the moment, we are using the "classic" streams we want to give it a try
>>> to XStreams. My knowledge on streams is very little, so if someone can give
>>> me a hint I would really appreciate it.
>>> What I want to do right now is an adaptor of XStreams to classic stream. I
>>> mean, I want to create custom subclasses of XTFileWriteStream and
>>> XTFileReadStream that implements the same API from classic streams that we
>>> use in Fuel. And the implementations of such methods will do just a "self
>>> something" where something is the way of doing that in XStreams.
>>>
>>> So, the following is the protocol we use in Fuel for streams, and what I
>>> would love to know is the associated way to do it it XStreams. The left is
>>> classic streams, and after the "->" it is XStreams:
>>>
>>> Reading:
>>>
>>> nextNumber: -> ??
>>> nextPutAll: -> write:
>>> nextStringPut: -> ??
>>> nextPut:  -> put:
>>> nextNumber:put: -> ??
>>> nextWordPut: -> ??
>>>
>>> Writing:
>>>
>>> nextNumber: -> ??
>>> next:  -> read:
>>> nextString -> ??
>>> next  -> get
>>> nextWord -> ??
>>>
>>> Thanks a lot in advance,
>>>
>>>
>>> --
>>> Mariano
>>> http://marianopeck.wordpress.com
>>>
>>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Help "migrating" from classic streams to XStreams

mkobetic
In reply to this post by Mariano Martinez Peck
"Mariano Martinez Peck"<[hidden email]> wrote:

> Hi guys. We are developing Fuel with Martin Dias. Fuel is a binary
> serializer similar to Parcels. More info in
> http://rmod.lille.inria.fr/web/pier/software/Fuel
>
> For the moment, we are using the "classic" streams we want to give it a try
> to XStreams. My knowledge on streams is very little, so if someone can give
> me a hint I would really appreciate it.
> What I want to do right now is an adaptor of XStreams to classic stream. I
> mean, I want to create custom subclasses of XTFileWriteStream and
> XTFileReadStream that implements the same API from classic streams that we
> use in Fuel. And the implementations of such methods will do just a "self
> something" where something is the way of doing that in XStreams.

I'd also recommend generic wrapper for any kind of Xtream rather than subclassing specific terminal. In VW the usual way to create the classic streams is via #readStream or #writeStream, so I'd add something like:

XTReadStream>>readStream

        ^XTClassicReadStream on: self

XTWriteStream>>writeStream

        ^XTClassicWriteStream on: self

The "classic" guys would then implement the classic API by invoking Xtreams API on their source/destination. You can even subclass those from the classic ReadStream and WriteStream to possibly inherit some behavior and only implement some core part of the protocol.

> So, the following is the protocol we use in Fuel for streams, and what I
> would love to know is the associated way to do it it XStreams. The left is
> classic streams, and after the "->" it is XStreams:
>
> *Reading:*
>
> nextNumber: -> ??
> nextPutAll: -> write:
> nextStringPut: -> ??
> nextPut:  -> put:
> nextNumber:put: -> ??
> nextWordPut: -> ??
>
> *Writing:
> *
> nextNumber: -> ??
> next:  -> read:

It's not as simple, there can be subtle differences. For example in VW it should be something like:

next: anInteger
        ^[ source read: anInteger ] on: Incomplete do: [ :incomplete |
                IncompleteNextCountError new parameter: incomplete count;  raiseRequest ]

> nextString -> ??
> next  -> get

Again, in VW it would be more like:

get
        ^[ source get ] on: Incomplete do: [ :incomplete | EndOfStreamNotification raiseRequest ]

> nextWord -> ??

For the specialized element types (Number, String) you can pretty much copy the classic implementations (or even inherit them). Alternatively they seem to fall into a category that we call "interpreting" in Xtreams. What we have is primarily focused on interpreting bytes as various C-types (short, long, float, double,....) for which we have convenient primitives in VW, but the concept can certainly be extended further (the interpretation definitions are pluggable). Unfortunately this part wasn't ported yet from VW. For quick overview you can peek at the end of http://code.google.com/p/xtreams/wiki/Transforms. There's also general marshaling stream available on VW side (built on top of the interpreting streams) which might be helpful example of how one can approach this type of problem with Xtreams.

HTH,

Martin

Reply | Threaded
Open this post in threaded view
|

Re: Help "migrating" from classic streams to XStreams

Sean P. DeNigris
Administrator
In reply to this post by Mariano Martinez Peck
Mariano Martinez Peck wrote
For the moment, we are using the "classic" streams we want to give it a try
to XStreams.
Mariano, was there any progress on this?

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Help "migrating" from classic streams to XStreams

Mariano Martinez Peck


On Fri, Jun 22, 2012 at 8:05 PM, Sean P. DeNigris <[hidden email]> wrote:

Mariano Martinez Peck wrote
>
> For the moment, we are using the "classic" streams we want to give it a
> try
> to XStreams.

Mariano, was there any progress on this?


Not really. The problem was that at that moment, the Fuel's design regarding Streams was not very beatiful and we were depending on a lot of messages on Streams. Now in Fuel 1.8 we have reified FLEncoder and FLDecoder and hence we depend only on a few methods for streams:

Write stream:

nextPut: aSmallInteger
nextBytesPutAll: aBytesObject
nextWordsPut: aWordObject

Read stream:

next
next:numberOfBytes into: aBytesObject
nextInto: aCollection
fuelNextWordsInto: aWordsObject

 
So if someone help me to figure it out how to do it in XStreams let me know and I try.  Moreover, we have also improved the tests and now you can run all of them with the steam you want. Basically, you have to subclass FLStreamStrategy and implement #writeStreamDo: and #readStreamDo:. So far we have FLByteArrayStreamStrategy, FLFileStreamStrategy, FLMultiByteStreamStrategy and FLFileSystemFileStreamStrategy (for FS).

So...the procedure is to create FLXSteamsStrategy accordly and start trying to create (as extensions) the needed methods ;)

cheers,

--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: Help "migrating" from classic streams to XStreams

Sean P. DeNigris
Administrator
Mariano Martinez Peck wrote
So if someone help me to figure it out how to do it in XStreams let me know
and I try
That sounds like a cool project, also as a test possibly to get them in Pharo :) I may have time soon. I'll be in touch...

Sean
Cheers,
Sean