Hi Sven,
Thanks for your response! That's a much nicer solution. Indeed, I did
not want to change the implementation (for now) even though I don't
really like the moded behavior RWTextOrBinaryStream and it was removed
for good reason.
I would like to suggest to use the port with that ugly wart as it is for
now, so that others can use OSC. When I get around to it, I will use
your suggestions to retrofit the package and add some more documentation.
Günter
On 5/21/21 5:18 PM, Sven Van Caekenberghe wrote:
Hi Günter,
Thanks for answering, I expected that you would mention this aspect.
I don't know about OSC, but from your description it sounds like it basically
is a binary protocol, where some sequences of bytes are to be interpreted as
ASCII encoded strings.
I would just work on binary streams and do the encoding/decoding as needed.
ASCII is trivial, you can either do:
ZnCharacterEncoder ascii encodeString: 'OSC'
or
'OSC' asByteArray
And the inverse is either
ZnCharacterEncoder ascii decodeBytes: #[79 83 67].
or
#[79 83 67] asString.
The OSC spec says:
OSC-string
A sequence of non-null ASCII characters followed by a null, followed by 0-3
additional null characters to make the total number of bits a multiple of 32.
One approach could be:
#writeOSCString: string on: stream
stream nextPutAll: (ZnCharacterEncoder ascii encodeString: string).
stream nextPut: 0.
(string size + 1) // 4 timesRepeat: [ stream nextPut: 0 ]
#readOSCStringFrom: stream
| string |
string := ByteArray streamContents: [ :out |
[ stream peekFor: 0 ] whileFalse: [ out nextPut: stream next ] ].
(string size + 1) // 4 timesRepeat: [ stream next ].
^ ZnCharacterEncoder ascii decodeBytes: string
My point being that you probably don't need RWTextOrBinaryStream at all.
Of course, if you ported existing code and don't want to change it much, your
solution is acceptable.
Sven
On 21 May 2021, at 15:39, Günter Khyo <[email protected]> wrote:
A RWTextOrBinaryStream instance can operate in binary or ascii mode, the mode
can be switched at any time by sending ascii or binary, and some methods are
mode-sensitive, e.g., contents will respond with a ByteArray in binary mode and
a ByteString in ascii mode. (OSC uses ASCII encoding for addresses and strings,
and binary formats for numbers and blobs.)
The OSC testcases and the parser rely on this behavior.
On 5/21/21 3:00 PM, Sven Van Caekenberghe wrote:
On 21 May 2021, at 14:02, Günter Khyo via Pharo-dev <[email protected]>
wrote:
Hi,
I have ported the Open Sound Control package to Pharo 9.0. Since the Catalog
Browser is marked as legacy, I was wondering how to submit the patch. Is there
a git repository? I attached the fileout to this email in case anybody wants to
take a look at the package or knows how/where to add it to Pharo 9.0,
Patch Note:
OSC relies on the removed RWTextOrBinaryStream class which has very specific
behavior that I could not emulate using the available stream and codec classes,
so I pulled in the class from Squeak 5, renamed it to OSCStream and added it to
the OSC package. This seemed to be the easiest way to do it without changing
the OSC implementation, but I welcome any suggestions for a cleaner solution.
I am curious, what was the specific behaviour that you could not emulate ?
Günter
<OSC.st>