net: Inject the extension into the StreamSocket as well
This is mostly a hack and needs to be cleaned up.
This commit is contained in:
parent
ca50ffe022
commit
0a604c3e9b
|
@ -97,6 +97,37 @@ Sockets.Socket extend [
|
|||
]
|
||||
]
|
||||
|
||||
Sockets.StreamSocket extend [
|
||||
nextUshort [
|
||||
"Return the next 2 bytes in the byte array, interpreted as a 16 bit unsigned int"
|
||||
<category: '*-OsmoCore-message'>
|
||||
^self nextBytes: 2 signed: false
|
||||
]
|
||||
|
||||
nextBytes: n signed: signed [
|
||||
"Private - Get an integer out of the next anInteger bytes in the stream"
|
||||
|
||||
<category: '*-OsmoCore-message'>
|
||||
| int msb |
|
||||
int := 0.
|
||||
0 to: n * 8 - 16
|
||||
by: 8
|
||||
do: [:i | int := int + (self nextByte bitShift: i)].
|
||||
msb := self nextByte.
|
||||
(signed and: [msb > 127]) ifTrue: [msb := msb - 256].
|
||||
^int + (msb bitShift: n * 8 - 8)
|
||||
]
|
||||
|
||||
nextByte [
|
||||
"Return the next byte in the file, or nil at eof"
|
||||
|
||||
<category: '*-OsmoCore-message'>
|
||||
| a |
|
||||
a := self next.
|
||||
^a isNil ifTrue: [a] ifFalse: [a asInteger]
|
||||
]
|
||||
]
|
||||
|
||||
ByteArray extend [
|
||||
castTo: type [
|
||||
<category: '*-OsmoCore-message'>
|
||||
|
|
Reference in New Issue