Thanks to Sven's tips I fixed the package and ditched the hacky Stream class. I also cleaned up some messy parts in the implementation. I noticed that the current implementation does not handle blobs and the server packet processing logic could be improved. Also, I am not sure whether recursive bundles are handled correctly (more test cases needed) and to which extent they are used in OSC applications, so one would have to do a fair bit of polishing for an "industry grade" implementation.

In any case, if there are any users that would like to use and test OSC, I am happy to take feedback and make necessary additions/modifications.

Stef, I'll send you a pull request tomorrow, now I have to catch some sleep.

On 5/21/21 6:23 PM, ducasse wrote:
Thanks.
I do not think that it is good to reintroduce this super ugly class. at the minimum it should be in a separate branch.

S

On 21 May 2021, at 18:06, Günter Khyo via Pharo-dev <[email protected] <mailto:[email protected]>> wrote:

Hi Stef,

Great! I'll send you a pull-request for the "hotfix" this evening. As I mentioned to Sven, I'll do some rework on the implementation and documentation when I find the time.

Günter

On 5/21/21 5:55 PM, ducasse wrote:
I checked and all the tests pass on Pharo80.
Now I did a little pass on the tests.
I do not have the time to migrate this lib to P9.
But I would accept Pull Requests :)

S.

On 21 May 2021, at 17:46, ducasse <[email protected] <mailto:[email protected]>> wrote:

The old travis was telling that the code works in 6.1, 7 and 8.0
I added GithubActions for Pharo 80 and I will see.

S

On 21 May 2021, at 17:40, ducasse <[email protected] <mailto:[email protected]>> wrote:

Hi gunter

I’m maintaining OSC
https://github.com/Ducasse/OSC
and TUIO
https://github.com/Ducasse/TUIO

Please do some PR if something does not work.

S

On 21 May 2021, at 14:02, Günter Khyo via Pharo-dev <[email protected] <mailto:[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.

Günter

<OSC.st <http://osc.st/>>




Object subclass: #OSCPacket
        instanceVariableNames: 'byteStream'
        classVariableNames: ''
        package: 'OSC-Kernel'!

!OSCPacket methodsFor: 'action' stamp: 'mga 9/17/2006 19:17'!
sendToYourself
        self sendTo: NetNameResolver localHostAddress port: 57123! !

!OSCPacket methodsFor: 'action' stamp: 'gk 5/21/2021 22:53'!
sendTo: aByteArray port: aPort 
        "Take care, A byte array is not a string.
        If you want to send to e.g. '192.168.0.2' 
        sendToAddressString: port: instead
        But use this one if you want to be fast."
        | aSocket |
        Socket initializeNetwork.
        aSocket := Socket newUDP.
        aSocket
                sendUDPData: self bytes
                toHost: aByteArray
                port: aPort;
                 close;
                 destroy! !

!OSCPacket methodsFor: 'action' stamp: 'mga 9/17/2006 19:17'!
sendToAddressString: anAddressString port: aPort 
        self 
                sendTo: ((anAddressString findTokens: '.') collect: [:e | e 
asNumber]) 
                                asByteArray
                port: aPort! !


!OSCPacket methodsFor: 'initialization' stamp: 'gk 5/21/2021 22:48'!
initializeFor: somePackets
        byteStream := ByteArray new writeStream.
        self print: somePackets onOSCStream: byteStream! !


!OSCPacket methodsFor: 'accessing' stamp: 'gk 5/21/2021 22:53'!
oSCSize
        ^self bytes size! !

!OSCPacket methodsFor: 'accessing' stamp: 'mga 3/16/2005 08:58'!
byteStream
        ^byteStream! !

!OSCPacket methodsFor: 'accessing' stamp: 'gk 5/21/2021 23:00'!
bytes
        ^self byteStream contents! !


!OSCPacket methodsFor: 'printing' stamp: 'mga 6/24/2000 14:09'!
print: somePackets onOSCStream: aStream
        self subclassResponsibility! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

OSCPacket class
        instanceVariableNames: ''!

!OSCPacket class methodsFor: 'access to cache' stamp: 'StephaneDucasse 
9/29/2012 22:59'!
for: somePackets
        ^ self new initializeFor: somePackets ! !


OSCPacket subclass: #OSCBundle
        instanceVariableNames: 'packets'
        classVariableNames: ''
        package: 'OSC-Kernel'!

!OSCBundle methodsFor: 'printing' stamp: 'StephaneDucasse 9/29/2012 23:02'!
printTimeTagOnOSCStream: aStream
        "Not yet implemented, just print 8 empty bytes"
        8 timesRepeat: [ aStream nextPut: 0 ]! !

!OSCBundle methodsFor: 'printing' stamp: 'gk 5/21/2021 22:53'!
print: somePackets onOSCStream: aStream

        '#bundle' printOnOSCStream: aStream.
        self printTimeTagOnOSCStream: aStream.
        somePackets do: [ :aPacket |
                aPacket oSCSize printOnOSCStream: aStream.
                aStream nextPutAll: aPacket bytes ]
        ! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

OSCBundle class
        instanceVariableNames: ''!

!OSCBundle class methodsFor: 'examples' stamp: 'mga 6/24/2000 14:07'!
example1
        ^self for: {OSCMessage example1 .  OSCMessage example2}
        ! !

!OSCBundle class methodsFor: 'examples' stamp: 'mga 6/24/2000 14:08'!
example2
        ^self for: {OSCBundle example1 . OSCMessage example3}! !


OSCPacket subclass: #OSCMessage
        instanceVariableNames: ''
        classVariableNames: ''
        package: 'OSC-Kernel'!

!OSCMessage methodsFor: 'printing' stamp: 'gk 5/21/2021 23:00'!
printTypesOf: someValues on: aStream
        someValues isEmpty ifTrue: [^self].     
        someValues do: [ :each | each printTypeOnOSCStream: aStream ].
        (4 - (aStream position \\ 4)) timesRepeat: [ aStream nextPut: 0 ]
! !

!OSCMessage methodsFor: 'printing' stamp: 'mga 3/29/2005 21:37'!
print: someArguments onOSCStream: aStream

        | someParams |
        self printAddress: someArguments first onOSCStream: aStream.
        "Put the comma, also parameterless messages have one"
        aStream nextPut: 44.
        someParams := someArguments copyFrom: 2 to: someArguments size.
        self    
                printTypesOf: someParams on: aStream;
                printValues: someParams onOSCStream: aStream
! !

!OSCMessage methodsFor: 'printing' stamp: 'StephaneDucasse 9/29/2012 23:02'!
printAddress: anAddress onOSCStream: aStream

        anAddress printOnOSCStream: aStream
        
! !

!OSCMessage methodsFor: 'printing' stamp: 'StephaneDucasse 9/29/2012 23:03'!
printValues: someValues onOSCStream: aStream
        someValues do: [ :each | each printOnOSCStream: aStream ]
! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

OSCMessage class
        instanceVariableNames: ''!

!OSCMessage class methodsFor: 'examples' stamp: 'mga 6/24/2000 14:19'!
example3
        ^self for: {'/example3' . 20 . 30 . 'bla'}! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/30/2005 04:23'!
exampleBerkeley3Message
        ^{'/foo' . 1000 . -1 . 'hello' .1.125 . 4.0625 }! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/29/2005 21:19'!
exampleSCIncreaseVolume
        ^self for: self increaseVolumeMessage! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/29/2005 21:19'!
exampleSCRun
        "self exampleSCRun sendTo: '10.0.1.2' port: 22"
        ^self for: {'/sc/run'}! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 6/24/2000 14:18'!
example2
        ^self for: {'/example2' . 'tester' . 10.4}! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/29/2005 21:19'!
exampleBerkeley2Message
        ^{'/foo' . 1000 . -1 . 'hello' . 1.234 . 5.678}! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/30/2005 04:23'!
exampleBerkeley3
        ^self for: self exampleBerkeley3Message! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/29/2005 21:19'!
exampleBerkeley2
        ^self for: self exampleBerkeley2Message! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 6/24/2000 14:18'!
example1
        ^self for: {'/example1' . 100}! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/29/2005 21:20'!
exampleSCStop
        ^self for: {'/sc/stop'}! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/29/2005 21:20'!
increaseVolumeMessage
        ^{'/sc/mixer/volume' . 1 . 1.0}! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/29/2005 21:19'!
exampleSCA
        ^self for: {'a' . 1 . 0.2}! !

!OSCMessage class methodsFor: 'examples' stamp: 'mga 3/29/2005 21:19'!
exampleSCDecreaseVolume
        ^self for: {'/sc/mixer/volume' . 1 . 0.2}! !


Object subclass: #OSCParser
        instanceVariableNames: 'byteStream message types'
        classVariableNames: ''
        package: 'OSC-Kernel'!

!OSCParser methodsFor: 'action' stamp: 'SimonHolland 9/15/2007 10:28'!
parseBlob
        ^ nil! !

!OSCParser methodsFor: 'action' stamp: 'gk 5/21/2021 23:11'!
parseTypes
        | next |
        byteStream atEnd ifTrue: [^self].
        next := byteStream next.
        next = 0 ifTrue: [
                ((4 - (byteStream position \\ 4)) \\ 4) timesRepeat: 
[byteStream next].
                ^self
        ].
          "i   f   s   b"
        (#[105 102 115 98] includes: next) ifTrue: [types add: next].
        self parseTypes.! !


!OSCParser methodsFor: 'accessing' stamp: 'gk 5/21/2021 23:22'!
parseHeader
        |header|
        header := (byteStream upTo: $, asInteger) copyWithout: 0.
        message add: (ZnCharacterEncoder ascii decodeBytes: header).
! !

!OSCParser methodsFor: 'accessing' stamp: 'gk 5/21/2021 23:07'!
parseInt32
        message add: byteStream nextInt32! !

!OSCParser methodsFor: 'accessing' stamp: 'mga 3/27/2005 18:26'!
parseValues
        | aTypeStream |
        aTypeStream := ReadStream on: types.
        [aTypeStream atEnd] whileFalse: [self parseNextValueTyped: aTypeStream 
next]! !

!OSCParser methodsFor: 'accessing' stamp: 'mga 3/27/2005 18:28'!
parse
        self 
                parseHeader;
                parseTypes;
                parseValues.
        ^message asArray! !

!OSCParser methodsFor: 'accessing' stamp: 'gk 5/21/2021 23:12'!
parseNextValueTyped: aType
        aType = 105 "i" ifTrue: [^self parseInt32].
        aType = 102 "f" ifTrue: [^self parseFloat].
        aType = 115 "s" ifTrue: [^self parseString].
        aType = 98  "b" ifTrue: [^self parseBlob]

! !

!OSCParser methodsFor: 'accessing' stamp: 'mga 3/27/2005 18:26'!
parseFloat
        message add: (Float fromIEEE32Bit: (byteStream binary nextNumber: 4))! !


!OSCParser methodsFor: 'parse' stamp: 'gk 5/21/2021 23:19'!
parseString
        message add: (ZnCharacterEncoder ascii decodeBytes: (byteStream upTo: 
0)).
        (4 - (byteStream position)) \\ 4 timesRepeat: [ byteStream next ]
        ! !


!OSCParser methodsFor: 'initialization' stamp: 'mga 3/27/2005 18:26'!
initializeFor: aByteStream
        byteStream := aByteStream.
        message := OrderedCollection new.
        types := OrderedCollection new.! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

OSCParser class
        instanceVariableNames: ''!

!OSCParser class methodsFor: 'parse' stamp: 'gk 5/21/2021 23:06'!
parse: aByteStream
        | messageArrays messageArray |          
        messageArrays := OrderedCollection new. 
        [aByteStream atEnd] whileFalse: [
                messageArray := (self new initializeFor: aByteStream) parse.
                messageArray ifNotNil: [
                        messageArrays add: messageArray asArray 
                ]
        ].
        ^messageArrays! !


Object subclass: #OSCServer
        instanceVariableNames: 'process socket messageQueue responsePeriod'
        classVariableNames: ''
        package: 'OSC-Kernel'!

!OSCServer methodsFor: 'initialize-release' stamp: 'mga 3/27/2005 22:49'!
terminate
        socket notNil ifTrue: [socket destroy].
        process notNil ifTrue: [process terminate]! !

!OSCServer methodsFor: 'initialize-release' stamp: 'SimonHolland 9/15/2007 
12:43'!
initialize
        super initialize.
        messageQueue := SharedQueue new.
        responsePeriod := 10.! !


!OSCServer methodsFor: 'action' stamp: 'gk 5/22/2021 00:25'!
listenOnPort: aPort
        | buffer bytesReceived |
        self terminate.
        socket := (Socket udpCreateIfFail: [self error: 'Problems connecting 
to:',aPort asString]) setPort: aPort.
        process := 
        [
                buffer := ByteArray new: 2048.
                [
                        bytesReceived := (socket receiveUDPDataInto: buffer) 
first 
                        "N.B.: receiveUDPDataInto: returns an array with 
[bytesReceived | IP Address | port | more datagrams follow?]".
                        bytesReceived > 0 ifTrue: [ self receive: (buffer 
copyFrom: 1 to: bytesReceived) readStream].
                ] repeat 
        ] forkAt: Processor userBackgroundPriority.
! !

!OSCServer methodsFor: 'action' stamp: 'gk 5/22/2021 00:11'!
receive: aByteStream
        (OSCParser parse: aByteStream)
                do: [:eachMessageArray |  messageQueue nextPut: 
eachMessageArray].
        Delay forMilliseconds: responsePeriod.! !


!OSCServer methodsFor: 'accessing' stamp: 'mga 9/17/2006 18:24'!
nextMessage
        ^ messageQueue next! !


!OSCServer methodsFor: 'testing' stamp: 'mga 9/17/2006 18:25'!
hasMessage
        ^messageQueue isEmpty not! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

OSCServer class
        instanceVariableNames: ''!

!OSCServer class methodsFor: 'as yet unclassified' stamp: 'mga 3/15/2005 23:45'!
listenOnPort: aPort
        "(self listenOnPort: 7010) inspect"
        ^self new listenOnPort: aPort! !
TestCase subclass: #OSCMessageEncodingTest
        instanceVariableNames: ''
        classVariableNames: ''
        package: 'OSC-Tests'!

!OSCMessageEncodingTest methodsFor: 'tests' stamp: 'gk 5/21/2021 22:53'!
testByteArrayRun
        self
                assert: OSCMessage exampleSCRun bytes
                equals: ('/sc/run' , (String with: (Character value: 0) with: 
$,)) asByteArray! !

!OSCMessageEncodingTest methodsFor: 'tests' stamp: 'gk 5/21/2021 22:53'!
testByteArrayDecreaseVolume
        self 
                assert: OSCMessage exampleSCDecreaseVolume bytes
                equals: #[47 115 99 47 109 105 120 101 114 47 118 111 108 117 
109 101 0 0 0 0 44 105 102 0 0 0 0 1 62 76 204 205].! !

!OSCMessageEncodingTest methodsFor: 'tests' stamp: 'gk 5/21/2021 22:53'!
testExampleBerkeley2
        "See 
http://www.cnmat.berkeley.edu/OpenSoundControl/OSC-spec-examples.html";
        self 
                assert: OSCMessage exampleBerkeley2 bytes
                equals:  #[
                        16r2F  16r66  16r6F 16r6F 
                        0      0      0     0 
                        16r2C  16r69  16r69  16r73
                        16r66  16r66  0      0 
                        0      0      3      16rE8 
                        16rFF  16rFF  16rFF  16rFF 
                        16r68  16r65  16r6C  16r6C
                        16r6F  0      0      0
                        16r3F  16r9D  16rF3  16rB6
                        16r40  16rB5  16rB2  16r2D].! !

!OSCMessageEncodingTest methodsFor: 'tests' stamp: 'gk 5/21/2021 22:53'!
testByteArrayStop       
        self 
                assert: OSCMessage exampleSCStop bytes
                equals: ('/sc/stop',((String new: 4 withAll: (Character value: 
0)),',')) asByteArray

! !

!OSCMessageEncodingTest methodsFor: 'tests' stamp: 'gk 5/21/2021 22:53'!
testByteArrayIncreaseVolume
        self 
                assert: OSCMessage exampleSCIncreaseVolume bytes
                equals: #[47 115 99 47 109 105 120 101 114 47 118 111 108 117 
109 101 0 0 0 0 44 105 102 0 0 0 0 1 63 128 0 0].
        ! !


TestCase subclass: #OSCParserTest
        instanceVariableNames: 'server'
        classVariableNames: ''
        package: 'OSC-Tests'!

!OSCParserTest methodsFor: 'tests' stamp: 'gk 5/21/2021 23:15'!
testParseIncreaseVolumeMessage
        self
                assert: (OSCParser parse: OSCMessage exampleSCIncreaseVolume 
bytes readStream) first
                equals: OSCMessage increaseVolumeMessage! !

!OSCParserTest methodsFor: 'tests' stamp: 'gk 5/21/2021 23:52'!
testParseBundle
        |messages|
        messages := OSCParser parse: self rawBundle readStream.
        self assert: messages size equals: 13.
        self assert: (messages at: 2) second equals: 'alive'.
        self assert: (messages at: 12) second equals: 'set'.
        self assert: (messages at: 13) second equals: 'fseq'    ! !

!OSCParserTest methodsFor: 'tests' stamp: 'gk 5/21/2021 23:15'!
testParse
        self
                assert: (OSCParser parse: OSCMessage exampleSCIncreaseVolume 
bytes readStream) first
                equals: OSCMessage increaseVolumeMessage! !

!OSCParserTest methodsFor: 'tests' stamp: 'gk 5/21/2021 23:54'!
testParseExampleBerkely3Message
        self
                assert: (OSCParser parse: OSCMessage exampleBerkeley3 bytes 
readStream) first
                equals: OSCMessage exampleBerkeley3Message! !

!OSCParserTest methodsFor: 'tests' stamp: 'gk 5/21/2021 23:50'!
rawBundle
        ^#[35 98 117 110 100 108 101 0 0 0 0 0 0 0 0 1 0 0 0 32 47 116 117 105 
111 47 50 68 111 98 106 0 44 115 115 0 115 111 117 114 99 101 0 0 118 105 115 
105 111 110 0 0 0 0 0 76 47 116 117 105 111 47 50 68 111 98 106 0 44 115 105 
105 105 105 105 105 105 105 105 105 0 0 0 0 97 108 105 118 101 0 0 0 0 0 0 42 0 
0 0 43 0 0 0 44 0 0 0 45 0 0 0 46 0 0 0 47 0 0 0 48 0 0 0 49 0 0 0 50 0 0 0 51 
0 0 0 72 47 116 117 105 111 47 50 68 111 98 106 0 44 115 105 105 102 102 102 
102 102 102 102 102 0 0 0 0 115 101 116 0 0 0 0 42 0 0 0 14 63 88 136 237 63 47 
122 89 62 37 252 84 61 115 94 16 60 154 81 117 0 0 0 0 186 128 127 210 0 0 0 0 
0 0 0 72 47 116 117 105 111 47 50 68 111 98 106 0 44 115 105 105 102 102 102 
102 102 102 102 102 0 0 0 0 115 101 116 0 0 0 0 43 0 0 0 13 63 88 151 24 63 102 
3 195 62 1 60 116 61 137 156 31 60 130 116 93 0 0 0 0 186 105 27 53 0 0 0 0 0 0 
0 72 47 116 117 105 111 47 50 68 111 98 106 0 44 115 105 105 102 102 102 102 
102 102 102 102 0 0 0 0 115 101 116 0 0 0 0 44 0 0 0 7 63 23 3 240 63 92 135 87 
61 238 4 233 61 149 61 24 0 0 0 0 0 0 0 0 186 182 82 171 0 0 0 0 0 0 0 72 47 
116 117 105 111 47 50 68 111 98 106 0 44 115 105 105 102 102 102 102 102 102 
102 102 0 0 0 0 115 101 116 0 0 0 0 45 0 0 0 10 63 56 107 155 63 97 75 217 61 
226 44 41 62 17 0 62 60 161 91 39 0 0 0 0 59 13 245 244 0 0 0 0 0 0 0 72 47 116 
117 105 111 47 50 68 111 98 106 0 44 115 105 105 102 102 102 102 102 102 102 
102 0 0 0 0 115 101 116 0 0 0 0 46 0 0 0 1 62 159 147 223 63 82 44 101 61 217 
161 105 61 147 225 210 0 0 0 0 0 0 0 0 186 211 195 233 0 0 0 0 0 0 0 72 47 116 
117 105 111 47 50 68 111 98 106 0 44 115 105 105 102 102 102 102 102 102 102 
102 0 0 0 0 115 101 116 0 0 0 0 47 0 0 0 4 62 232 110 187 63 87 110 53 61 253 
117 41 61 151 241 117 0 0 0 0 0 0 0 0 186 198 7 73 0 0 0 0 0 0 0 72 47 116 117 
105 111 47 50 68 111 98 106 0 44 115 105 105 102 102 102 102 102 102 102 102 0 
0 0 0 115 101 116 0 0 0 0 48 0 0 0 5 62 241 108 216 63 29 239 197 62 20 220 212 
61 147 100 218 0 0 0 0 0 0 0 0 186 164 190 84 0 0 0 0 0 0 0 72 47 116 117 105 
111 47 50 68 111 98 106 0 44 115 105 105 102 102 102 102 102 102 102 102 0 0 0 
0 115 101 116 0 0 0 0 49 0 0 0 8 63 25 248 194 63 36 28 76 62 18 63 84 61 136 
42 109 0 0 0 0 0 0 0 0 186 172 239 184 0 0 0 0 0 0 0 72 47 116 117 105 111 47 
50 68 111 98 106 0 44 115 105 105 102 102 102 102 102 102 102 102 0 0 0 0 115 
101 116 0 0 0 0 50 0 0 0 11 63 57 145 158 63 41 213 19 62 29 206 148 61 131 164 
93 60 178 155 39 0 0 0 0 186 140 41 253 0 0 0 0 0 0 0 72 47 116 117 105 111 47 
50 68 111 98 106 0 44 115 105 105 102 102 102 102 102 102 102 102 0 0 0 0 115 
101 116 0 0 0 0 51 0 0 0 2 62 172 214 28 63 23 74 151 62 9 116 116 61 137 202 
171 60 188 34 233 0 0 0 0 186 170 24 46 0 0 0 0 0 0 0 28 47 116 117 105 111 47 
50 68 111 98 106 0 44 115 105 0 102 115 101 113 0 0 0 0 0 0 6 70]! !


TestCase subclass: #OSCParserTest3
        instanceVariableNames: 'string endingNumberArray startingNumberArray 
numberArrays streams parsedMessages'
        classVariableNames: ''
        package: 'OSC-Tests'!
!OSCParserTest3 commentStamp: 'SimonHolland 9/15/2007 11:55' prior: 0!
After the null that terminates a string, a well-formed incoming OSC message 
stream will have been padded with nulls if needed to reach a 32-bit word 
boundary, as per the OSC specification. This test checks that the parser 
handles this OK wherever the boundary may fall for a particular string in an 
incoming message.!


!OSCParserTest3 methodsFor: 'tests' stamp: 'gk 5/22/2021 00:36'!
testWordAlignment
        parsedMessages keysAndValuesDo: [ :key :value | "Transcript cr; show:  
' Actual - ' , ((parsedMessages at:key) first second); cr.
                Transcript cr; show:  ' Should be - ', ( string copyFrom: key 
to: string size ); cr."
                self
                        assert: (parsedMessages at: key) first second
                        equals: (string copyFrom: key to: string size) ]! !


!OSCParserTest3 methodsFor: 'setup' stamp: 'StephaneDucasse 9/29/2012 23:07'!
setUpParsedMessages
        parsedMessages := Dictionary new.
        streams keysAndValuesDo: 
                [ :key :value |  parsedMessages at: key put: (OSCParser parse: 
value ascii) ].
                
                
! !

!OSCParserTest3 methodsFor: 'setup' stamp: 'StephaneDucasse 9/29/2012 23:07'!
setUpStartingNumberArray
        | headerString typeMarker sizeOfPad nulls headerArray |
        headerString := 'Head'.
        typeMarker := ',s'.
        sizeOfPad :=  4 -  typeMarker size.
        nulls := Array new: sizeOfPad withAll: 0.
        headerArray := (headerString , typeMarker ) asArray.
        startingNumberArray  := (   headerArray , nulls  ) .
        ! !

!OSCParserTest3 methodsFor: 'setup' stamp: 'StephaneDucasse 9/29/2012 23:08'!
setUpEndingNumberArray
        endingNumberArray := string asArray collect: [ :each | each asInteger ] 
 
        
! !

!OSCParserTest3 methodsFor: 'setup' stamp: 'SimonHolland 9/9/2007 12:34'!
setUp
        self setUpString.
        self setUpStartingNumberArray.
        self setUpEndingNumberArray.
        self setUpNumberArrays.
        self setUpStreams.
        self setUpParsedMessages.! !

!OSCParserTest3 methodsFor: 'setup' stamp: 'StephaneDucasse 9/29/2012 23:08'!
setUpNumberArrays
        |  endArray |
        numberArrays := Dictionary new.
        (1 to: 4) keysAndValuesDo:
                [:key :value | 
                        endArray := endingNumberArray copyFrom: key  to: 
endingNumberArray size.
                        numberArrays at: key put: (startingNumberArray , 
endArray) ].
        
        
! !

!OSCParserTest3 methodsFor: 'setup' stamp: 'SimonHolland 9/9/2007 10:44'!
setUpStreams
        streams := Dictionary new.
        numberArrays keysAndValuesDo: [ :key :value |  streams at: key put: 
(self streamFromArray: value) ].
                
                
! !

!OSCParserTest3 methodsFor: 'setup' stamp: 'StephaneDucasse 9/29/2012 23:07'!
setUpString
        string := 'Reaktivision is  highly Groovy 0123456789' 
        
! !


!OSCParserTest3 methodsFor: 'converting' stamp: 'gk 5/22/2021 00:35'!
streamFromArray: anArray
        ^(ByteArray streamContents: [:out |
                anArray do: [:each | out nextPut: each asInteger ].
        ]) readStream.! !


TestCase subclass: #OSCServerTest
        instanceVariableNames: ''
        classVariableNames: ''
        package: 'OSC-Tests'!

!OSCServerTest methodsFor: 'tests' stamp: 'gk 5/21/2021 22:06'!
testSendAndReceive
        | server |
        server := OSCServer listenOnPort: 5432.
        [ 
        OSCMessage example1
                sendTo: NetNameResolver localHostAddress
                port: 5432.
        (Delay forDuration: (Duration milliSeconds: 30)) wait.
        self assert: server hasMessage.
        self assert: server nextMessage equals: #( '/example1' 100 ) ] 
                ensure: [ server terminate ]! !


TestCase subclass: #OSCTypeEncodingTest
        instanceVariableNames: ''
        classVariableNames: ''
        package: 'OSC-Tests'!

!OSCTypeEncodingTest methodsFor: 'tests' stamp: 'gk 5/21/2021 23:58'!
testEncodeString
        |expectedBytes bytesFromEncoder|
        expectedBytes := ByteArray streamContents: [:out |
                out 
                        nextPutAll: (ZnCharacterEncoder ascii encodeString: 
'abc') ;
                        nextPut: 0.
        ].

        bytesFromEncoder := ByteArray new writeStream.  
        'abc' printOnOSCStream: bytesFromEncoder.
        self assert: expectedBytes equals: bytesFromEncoder contents.
        
        expectedBytes := ByteArray streamContents: [:out |
                out 
                        nextPutAll: (ZnCharacterEncoder ascii encodeString: 
'abcd') ;
                        nextPutAll: (ByteArray new: 4 withAll: 0).
        ].      
        
        bytesFromEncoder := ByteArray new writeStream.
        'abcd' printOnOSCStream: bytesFromEncoder.
        self assert: expectedBytes equals: bytesFromEncoder contents.   ! !

!OSCTypeEncodingTest methodsFor: 'tests' stamp: 'gk 5/21/2021 23:56'!
testEncodeFloat
        |aStream|
        aStream := ByteArray new writeStream.
        10.7567 printOnOSCStream: aStream.
        self assert: aStream contents equals: #[65 44 27 113].! !

!OSCTypeEncodingTest methodsFor: 'tests' stamp: 'gk 5/21/2021 23:57'!
testEncodeSmallInteger
        | aStream |
        aStream := ByteArray new writeStream.
        1124 printOnOSCStream: aStream.
        self assert: aStream contents equals: #[0 0 4 100].! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.79689 am'!

!Symbol methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:54'!
printTypeOnOSCStream: aStream
        aStream nextPut: $s asInteger.! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.797847 am'!

!UndefinedObject methodsFor: '*OSC-printing' stamp: 'mga 6/27/2000 15:19'!
printOnOSCStream: aStream
        ^self! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.79884 am'!

!UndefinedObject methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:54'!
printTypeOnOSCStream: aStream
        aStream nextPut: $N asInteger
! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.799415 am'!

!SequenceableCollection methodsFor: '*OSC-printing' stamp: 'mga 6/27/2000 
15:30'!
printOnOSCStream: aStream
        self do: [:each | each printOnOSCStream: aStream]! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.800353 am'!

!SequenceableCollection methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:54'!
printTypeOnOSCStream: aStream
        aStream nextPut: $[ asInteger.
        self do: [:each | each printTypeOnOSCStream: aStream].
        aStream nextPut: $] asInteger.! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.800919 am'!

!String methodsFor: '*OSC-printing' stamp: 'mga 3/16/2005 09:40'!
printOnOSCStream: aStream

        self isEmpty ifTrue: [^self].
        aStream nextPutAll: self asByteArray.
        (4 - (self size \\ 4)) timesRepeat: [aStream nextPut: 0]
! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.801587 am'!

!String methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:51'!
printTypeOnOSCStream: aStream
        aStream nextPut: $s asInteger
! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.802066 am'!

!Boolean methodsFor: '*OSC-printing' stamp: 'mga 2/28/2005 17:16'!
printOnOSCStream: aStream
        ^self! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.802689 am'!

!True methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:53'!
printTypeOnOSCStream: aStream
        aStream nextPut: $T asInteger! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.803126 am'!

!Float methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:44'!
printOnOSCStream: aStream
        aStream nextNumber: 4 put: self asIEEE32BitWord! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.803595 am'!

!Float methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:50'!
printTypeOnOSCStream: aStream
        aStream nextPut: $f asInteger.! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.80411 am'!

!False methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:53'!
printTypeOnOSCStream: aStream
        aStream nextPut: $F asInteger! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.804615 am'!

!SmallInteger methodsFor: '*OSC-printing' stamp: 'mga 3/2/2005 10:47'!
printOnOSCStream: aStream
        aStream nextInt32Put: self! !
'From Pharo9.0.0 of 6 May 2021 [Build information: 
Pharo-9.0.0+build.1393.sha.9d0b61644429ec81e56888d037d2772f49e627e0 (64 Bit)] 
on 22 May 2021 at 12:36:53.805333 am'!

!SmallInteger methodsFor: '*OSC-printing' stamp: 'gk 5/21/2021 22:50'!
printTypeOnOSCStream: aStream
        aStream nextPut: $i asInteger.! !

Reply via email to