[Glass] How to properly write bytes objects into binary streams?

Mariano Martinez Peck via Glass glass at lists.gemtalksystems.com
Wed Sep 3 06:58:33 PDT 2014


On Tue, Sep 2, 2014 at 6:40 PM, Martin McClure <
martin.mcclure at gemtalksystems.com> wrote:

> On 09/02/2014 07:09 AM, Mariano Martinez Peck via Glass wrote:
>
>> Hi guys,
>>
>> In Pharo (yes, sorry if many of my threads start this way), we are able
>> to directly write a byte object, that is,  variableByteSubclass:... ,
>>   into a binary stream. Example:
>>
>> | buffer position byteObject |
>> buffer := ByteArray new: 100.
>> position := 5.
>> byteObject := 8932479837423648732648237642.
>> buffer replaceFrom: position + 1 to: position + byteObject size with:
>> byteObject.
>>
>> Now buffer is:
>>
>>   #[0 0 0 0 0 74 234 94 86 234 171 88 69 46 198 220 28 0 0 0 0 0 0 0 0 0
>> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>> 0]
>>
>> In the same way I wrote there a large positive integer, I can also write
>> any other byte-like object. This is efficient since I avoid a kind of
>> #asByteArray and mostly, because I have a unified way to write a byte
>> object to a binary stream, and then read it back.
>>
>> In GemStone this doesn't work. I thought I could do a #asByteArray and
>> then a #nextPutAll:   That works, for example, for LargeInteger, but not
>> for Float or Character.
>>
>> So....I wonder...is there a unified way to get a sequence of bytes from
>> byte-like objects and then to instantiate them with such sequence of
>> bytes?
>>
>>
> Hi Mariano,
>
> I'm afraid I need to answer your question with more questions...
>
>
Hi Martin,



> Should the byte object you write out from a GemStone server be readable
> into a non-GemStone Smalltalk (for instance, Pharo)
>
>
Well....as a very very first step, I am hacking a little to see how much
effort would be to have Fuel working in Gemstone (and I already have like
50% tests working!). And as a first step gemstone-to-gemstone would be ok.
If I note that Fuel does work correctly and stable in GemStone, then I
might analyze how to do gemstone-pharo and vice-versa, but this looks like
a much more complex project.


> Should the object be readable into a GemStone server of opposite
> endianness from the server that wrote it out?
>
>
This has less important I think since nowadays we are almost most of the
time in the same order, aren't we? In any case, in Fuel's Pharo version, we
do take care of that. The encoder stores the endianess, and then at
materialization time we compare against current image. If opposite, we do a:

Bitmap
                swapBytesIn: aWordObject
                from: 1
                to: aWordObject basicSize.

But again, I want to go step by step.


> If the answer to either of these is "yes," then things get a bit more
> complicated.
>
>
Even if they would be desired later, right now, I am fine with a "No"
answer.

:)

Thanks,



> Regards,
>
> -Martin
>
>


-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20140903/3f0bf8fd/attachment-0001.html>


More information about the Glass mailing list