Stream.st
changeset 25167 fb540653fa2f
parent 24926 459973cfc116
child 25168 f6d06b0efa5d
--- a/Stream.st	Tue Dec 31 04:26:37 2019 +0000
+++ b/Stream.st	Thu Jan 02 11:59:47 2020 +0100
@@ -246,7 +246,6 @@
     "
 ! !
 
-
 !Stream methodsFor:'Compatibility-Dolphin'!
 
 display:someObject
@@ -274,7 +273,6 @@
     self nextPut:(Character nl)
 ! !
 
-
 !Stream methodsFor:'accessing'!
 
 contents
@@ -2225,6 +2223,56 @@
     "Modified: / 17-03-2019 / 14:58:50 / Claus Gittinger"
 !
 
+nextPutInt24:anIntegerOrCharacter MSB:msbFlag
+    "Write the argument, anIntegerOrCharacter as a three byte integer.
+     If msbFlag is true, data is written most-significant byte first;
+     otherwise least first.
+     Returns the receiver.
+     The receiver must support writing of binary bytes.
+
+     This interface is provided to allow talking to external programs,
+     where it's known that the byte order is some definite one.
+     If you don't care (i.e. talk to other smalltalks) or you can control the
+     order, please use the corresponding xxxNet methods, which use a standard
+     network byte order."
+
+    |iNum "{ Class: SmallInteger }" hi mid lo b1 b2 b3|
+
+    iNum := anIntegerOrCharacter asInteger.
+    lo := iNum digitByteAt:1.
+    mid := iNum digitByteAt:2.
+    hi := iNum digitByteAt:3.
+    msbFlag ifTrue:[
+        "high word first"
+        b1 := hi.
+        b2 := mid.
+        b3 := lo.
+    ] ifFalse:[
+        "low word first"
+        b1 := lo.
+        b2 := mid.
+        b3 := hi.
+    ].
+    self nextPutByte:b1.
+    self nextPutByte:b2.
+    self nextPutByte:b3.
+
+    "
+     |s|
+
+     s := #[] writeStream.
+     s nextPutInt24:16r123456 MSB:false.
+     s contents.
+    "
+    "
+     |s|
+
+     s := #[] writeStream.
+     s nextPutInt24:16r123456 MSB:true.
+     s contents.
+    "
+!
+
 nextPutInt32:aNumber MSB:msbFlag
     "Write the argument, aNumber as a long (four bytes).
      If msbFlag is true, data is written most-significant byte first;