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

Martin McClure via Glass glass at lists.gemtalksystems.com
Tue Sep 2 14:40:45 PDT 2014


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...

Should the byte object you write out from a GemStone server be readable 
into a non-GemStone Smalltalk (for instance, Pharo)

Should the object be readable into a GemStone server of opposite 
endianness from the server that wrote it out?

If the answer to either of these is "yes," then things get a bit more 
complicated.

Regards,

-Martin



More information about the Glass mailing list