[Glass] How to properly write bytes objects into binary streams?
Mariano Martinez Peck via Glass
glass at lists.gemtalksystems.com
Tue Sep 2 07:09:06 PDT 2014
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?
Thanks in advance,
--
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20140902/aa8fc2fb/attachment.html>
More information about the Glass
mailing list