author | Jan Vrany <jan.vrany@labware.com> |
Sat, 29 Oct 2022 01:05:05 +0100 | |
branch | jv |
changeset 25446 | 98fb817db6de |
parent 25420 | a18d0d048b1f |
permissions | -rw-r--r-- |
23547
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
23405
diff
changeset
|
1 |
"{ Encoding: utf8 }" |
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
23405
diff
changeset
|
2 |
|
1 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
23107 | 5 |
COPYRIGHT (c) 2018 Jan Vrany |
25414
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
6 |
COPYRIGHT (c) 2021 LabWare |
19368 | 7 |
All Rights Reserved |
1 | 8 |
|
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
" |
|
6492 | 16 |
"{ Package: 'stx:libbasic' }" |
17 |
||
18284 | 18 |
"{ NameSpace: Smalltalk }" |
19 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
20 |
ArrayedCollection subclass:#UninterpretedBytes |
20372 | 21 |
instanceVariableNames:'' |
22 |
classVariableNames:'IsBigEndian' |
|
23 |
poolDictionaries:'' |
|
24 |
category:'Collections-Abstract' |
|
1 | 25 |
! |
26 |
||
3433 | 27 |
!UninterpretedBytes primitiveDefinitions! |
28 |
%{ |
|
29 |
/* |
|
30 |
* Notice: I am abstract, and my subclasses may be anything. |
|
31 |
* Therefore, the code must always handle the fallback case |
|
32 |
* where the receiver is neither an ExternalBytes nor a ByteArray. |
|
33 |
* (which are, however, the most common) |
|
34 |
* |
|
35 |
* macro to fetch my byte address and size-in-bytes; |
|
36 |
* convenient for inline-C code. |
|
37 |
* (yes, C is bad ...) |
|
38 |
*/ |
|
39 |
#define __fetchBytePointerAndSize__(o, pPtr, pSize) \ |
|
40 |
{\ |
|
41 |
if (__isNonNilObject(o)) { \ |
|
19368 | 42 |
if (__isByteArrayLike(o)) { \ |
43 |
*(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \ |
|
44 |
*(pSize) = __byteArraySize(o); \ |
|
45 |
} else if (__qIsExternalBytesLike(o)) { \ |
|
46 |
OBJ __sz__ = __externalBytesSize(o); \ |
|
47 |
if (__isSmallInteger(__sz__)) { \ |
|
48 |
*(pSize) = __intVal(__sz__); \ |
|
49 |
*(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \ |
|
50 |
} else { \ |
|
51 |
*(pSize) = 0; \ |
|
52 |
*(pPtr) = (unsigned char *)0; \ |
|
53 |
} \ |
|
54 |
} else { \ |
|
55 |
*(pSize) /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(o))->c_ninstvars)); \ |
|
56 |
*(pPtr) = (char *)(__InstPtr(self)) + *(pSize) /* nInstBytes */; \ |
|
57 |
*(pSize) = __qSize(self) - *(pSize) /* nInstBytes */; \ |
|
58 |
} \ |
|
3433 | 59 |
} else { \ |
19368 | 60 |
*(pSize) = 0; \ |
61 |
*(pPtr) = (unsigned char *)0; \ |
|
3433 | 62 |
} \ |
63 |
} |
|
64 |
||
65 |
%} |
|
66 |
! ! |
|
67 |
||
68 | 68 |
!UninterpretedBytes class methodsFor:'documentation'! |
1 | 69 |
|
88 | 70 |
copyright |
71 |
" |
|
72 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
23107 | 73 |
COPYRIGHT (c) 2018 Jan Vrany |
25414
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
74 |
COPYRIGHT (c) 2021 LabWare |
19368 | 75 |
All Rights Reserved |
88 | 76 |
|
77 |
This software is furnished under a license and may be used |
|
78 |
only in accordance with the terms of that license and with the |
|
79 |
inclusion of the above copyright notice. This software may not |
|
80 |
be provided or otherwise made available to, or used by, any |
|
81 |
other person. No title to or ownership of the software is |
|
82 |
hereby transferred. |
|
83 |
" |
|
84 |
! |
|
85 |
||
68 | 86 |
documentation |
87 |
" |
|
13575 | 88 |
UninterpretedBytes provides the common protocol for byte-storage |
89 |
containers; concrete subclasses are |
|
19101 | 90 |
ByteArray (which store the bytes within the Smalltalk object memory) |
91 |
String (knows that the bytes represent characters) |
|
13575 | 92 |
and |
19101 | 93 |
ExternalBytes (which store the bytes in the malloc-heap). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
94 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
95 |
UninterpretedBytes itself is abstract, so no instances of it can be created. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
96 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
97 |
[See also:] |
19101 | 98 |
ByteArray String ExternalBytes |
1294 | 99 |
|
100 |
[author:] |
|
19101 | 101 |
Claus Gittinger |
3433 | 102 |
|
103 |
[Notice:] |
|
19101 | 104 |
Notice the confusion due to multiple methods with the same |
105 |
functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:'). |
|
106 |
The reason is that at the time this class was written, |
|
107 |
ST80 did not offer protocol to specify the byteOrder, and |
|
108 |
ST/X provided methods ending in 'MSB:' for this. |
|
109 |
In the meanwhile, VW added protocol ending in 'bigEndian:', |
|
110 |
which has been added here for compatibility. |
|
111 |
(certainly a point, where an ansi-standard will help) |
|
68 | 112 |
" |
113 |
! ! |
|
1 | 114 |
|
18284 | 115 |
!UninterpretedBytes class methodsFor:'initialization'! |
116 |
||
117 |
initialize |
|
118 |
IsBigEndian := self isBigEndian. |
|
119 |
! ! |
|
120 |
||
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
121 |
!UninterpretedBytes class methodsFor:'instance creation'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
122 |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
123 |
from:aByteArray |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
124 |
"return new instance which is a copy of aByteArray" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
125 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
126 |
|len bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
127 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
128 |
len := aByteArray size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
129 |
bytes := self new:len. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
130 |
bytes replaceBytesFrom:1 to:len with:aByteArray startingAt:1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
131 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
132 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
133 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
134 |
String from:#[40 41 42] |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
135 |
String with:#[40 41 42 43 44 45 46 47 48 49 50] from:2 to:5 |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
136 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
137 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
138 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
139 |
fromHexString:aString |
15717 | 140 |
"decode a byteArray from a hex string (as generated by hexPrintOn:)" |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
141 |
|
12551 | 142 |
| sz bytes s hi lo | |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
143 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
144 |
sz := aString size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
145 |
sz == 0 ifTrue:[^ self new]. |
14970 | 146 |
sz odd ifTrue:[ ConversionError raiseWith:aString errorString:'invalid hex string (odd size)' ]. |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
147 |
|
12551 | 148 |
bytes := self new: sz // 2. |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
149 |
s := aString readStream. |
12551 | 150 |
1 to: sz // 2 do: [ :idx | |
19368 | 151 |
hi := s next digitValue. |
152 |
lo := s next digitValue. |
|
153 |
bytes at:idx put: ((hi bitShift:4) bitOr: lo) |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
154 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
155 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
156 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
157 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
158 |
ByteArray fromHexString:'1234FEFF' |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
159 |
ExternalBytes fromHexString:'1234FEFF' |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
160 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
161 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
162 |
|s| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
163 |
s := String streamContents:[:s | #[1 2 3] hexPrintOn:s]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
164 |
ByteArray fromHexString:s |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
165 |
" |
12551 | 166 |
" |
167 |
Time millisecondsToRun:[ |
|
19368 | 168 |
1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ] |
12551 | 169 |
]. |
170 |
" |
|
15717 | 171 |
|
172 |
"Modified (comment): / 28-08-2013 / 20:40:04 / cg" |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
173 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
174 |
|
11874
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
175 |
fromHexStringWithSeparators:aString |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
176 |
"read a bytearray from a printed string representation, where |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
177 |
individual bytes are encoded as two hex digits, optionally separated by whiteSpace. |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
178 |
See also fromHexString:, which does something similar, but does not allow for spaces" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
179 |
|
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
180 |
^ self streamContents:[:outStream | |
19368 | 181 |
|inStream h| |
182 |
||
183 |
inStream := aString readStream. |
|
184 |
||
185 |
[ |
|
186 |
inStream skipSeparators. |
|
187 |
inStream atEnd |
|
188 |
] whileFalse:[ |
|
189 |
h := inStream next:2. |
|
190 |
outStream nextPut:(Integer readFrom:h base:16). |
|
191 |
]. |
|
11874
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
192 |
]. |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
193 |
|
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
194 |
" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
195 |
ByteArray fromHexString:'1234FEFF' |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
196 |
ByteArray fromHexStringWithSeparators:' 12 34 FE FF' |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
197 |
" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
198 |
! |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
199 |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
200 |
fromPackedString:aString |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
201 |
"ST-80 compatibility: decode a byteArray from a packed string in which |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
202 |
6bits are encoded per character. The argument, aString must be a multiple |
18633 | 203 |
of 4 in size (since 24 is the lcm of 6 and 8). |
204 |
Every 6 bit packet is encoded as a character in 32..95. |
|
205 |
Characters below 32 are ignored (so line breaks can be inserted at any place). |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
206 |
An addition final byte defines how many bytes of the last triple are valid. |
18633 | 207 |
This is somewhat like the radix-encoding used in good old PDP11 times ;-) |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
208 |
ST-80 uses this encoding for Images ... |
16798 | 209 |
This is a base64 encoding, very similar (but not equal) to the algorithm used in RFC1421. |
18346 | 210 |
PS: It took a while to figure that one out ... |
18633 | 211 |
PPS: I don't like it ;-)" |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
212 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
213 |
|index "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
214 |
dstIndex "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
215 |
stop "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
216 |
sixBits "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
217 |
n "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
218 |
sz "{ Class: SmallInteger }" |
12551 | 219 |
last bytes| |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
220 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
221 |
sz := aString size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
222 |
sz == 0 ifTrue:[^ self new]. |
12551 | 223 |
sz := sz - (aString count:[:ch | ch codePoint < 32]). |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
224 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
225 |
stop := sz // 4 * 3. |
12551 | 226 |
"the size modulo 3 is encoded in the last character, if it is in the |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
227 |
range 97 .. otherwise, its exact." |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
228 |
|
12551 | 229 |
last := aString last codePoint. |
230 |
last > 96 ifTrue:[ |
|
19368 | 231 |
stop := stop - 3 + (last - 96) |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
232 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
233 |
bytes := self new:stop. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
234 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
235 |
index := 1. dstIndex := 1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
236 |
[dstIndex <= stop] whileTrue:[ |
19368 | 237 |
"/ take 4 characters ... |
238 |
"/ allow a line break before each group of 4 |
|
239 |
sixBits := (aString at:index) codePoint. |
|
240 |
[sixBits < 32] whileTrue:[ |
|
241 |
index := index + 1. |
|
242 |
sixBits := (aString at:index) codePoint. |
|
243 |
]. |
|
244 |
sixBits := sixBits bitAnd:16r3F. |
|
245 |
n := sixBits. |
|
246 |
||
247 |
"/ self assert:(aString at:index+1) codePoint >= 32. |
|
248 |
sixBits := (aString at:index+1) codePoint bitAnd:16r3F. |
|
249 |
n := (n bitShift:6) + sixBits. |
|
250 |
||
251 |
"/ self assert:(aString at:index+2) codePoint >= 32. |
|
252 |
sixBits := (aString at:index+2) codePoint bitAnd:16r3F. |
|
253 |
n := (n bitShift:6) + sixBits. |
|
254 |
||
255 |
"/ self assert:(aString at:index+3) codePoint >= 32. |
|
256 |
sixBits := (aString at:index+3) codePoint bitAnd:16r3F. |
|
257 |
n := (n bitShift:6) + sixBits. |
|
258 |
||
259 |
index := index + 4. |
|
260 |
||
261 |
"/ now have 24 bits in n |
|
262 |
||
263 |
bytes at:dstIndex put:(n bitShift:-16). |
|
264 |
||
265 |
dstIndex < stop ifTrue:[ |
|
266 |
bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF). |
|
267 |
dstIndex+2 <= stop ifTrue:[ |
|
268 |
bytes at:dstIndex+2 put:(n bitAnd:16rFF). |
|
269 |
] |
|
270 |
]. |
|
271 |
dstIndex := dstIndex + 3. |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
272 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
273 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
274 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
275 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
276 |
ByteArray fromPackedString:(#[1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
277 |
ByteArray fromPackedString:(#[1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
278 |
ByteArray fromPackedString:(#[1 1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
279 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
280 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1 1] asPackedString) |
18633 | 281 |
ByteArray fromPackedString:((ByteArray new:256) asPackedString) |
282 |
ByteArray fromPackedString:((ByteArray new:128) asPackedString) |
|
283 |
ByteArray fromPackedString:((ByteArray new:129) asPackedString) |
|
284 |
ByteArray fromPackedString:((ByteArray new:130) asPackedString) |
|
285 |
ByteArray fromPackedString:((ByteArray new:131) asPackedString) |
|
286 |
ByteArray fromPackedString:((ByteArray new:132) asPackedString) |
|
287 |
ByteArray fromPackedString:((ByteArray new:64) asPackedString) |
|
288 |
||
289 |
0 to:256 do:[:l | |
|
19368 | 290 |
|orig copy| |
291 |
||
292 |
0 to:255 do:[:fill | |
|
293 |
orig := ByteArray new:l withAll:fill. |
|
294 |
copy := ByteArray fromPackedString:(orig asPackedString). |
|
295 |
self assert:(orig = copy). |
|
296 |
] |
|
18633 | 297 |
] |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
298 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
299 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
300 |
"Modified: / 6.3.1997 / 15:28:52 / cg" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
301 |
"Modified: / 18.12.1997 / 17:17:11 / stefan" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
302 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
303 |
|
18284 | 304 |
uninitializedNew:anInteger |
305 |
"return a new instance of the receiver with uninitialized |
|
306 |
(i.e. undefined) contents. The indexed elements have any random |
|
307 |
value. However, any named instance variables are still nilled. |
|
308 |
For use, when contents will be set anyway shortly after - this |
|
309 |
is a bit faster than the regular basicNew:, which clears the bytes. |
|
310 |
Of course, it only makes a difference for very big ByteArrays, such |
|
311 |
as used for images/bitmaps. |
|
312 |
||
313 |
Notice: if you want to port code using uninitializedNew: to another |
|
314 |
smalltalk, you have to add an 'uninitializedNew: -> basicNew:'-calling |
|
315 |
method to the ByteArray class of the other smalltalk." |
|
316 |
||
317 |
%{ /* NOCONTEXT */ |
|
318 |
OBJ newobj; |
|
319 |
INT instsize, nInstVars, nindexedinstvars; |
|
320 |
REGISTER OBJ *op; |
|
321 |
||
322 |
if (__isSmallInteger(anInteger)) { |
|
19368 | 323 |
nindexedinstvars = __intVal(anInteger); |
324 |
if (nindexedinstvars >= 0) { |
|
325 |
if (self == ByteArray) { |
|
326 |
/* |
|
327 |
* the most common case |
|
328 |
*/ |
|
329 |
instsize = OHDR_SIZE + nindexedinstvars; |
|
330 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
331 |
__qCheckedNew(newobj, instsize); |
|
332 |
__InstPtr(newobj)->o_class = self; |
|
333 |
__qSTORE(newobj, self); |
|
334 |
RETURN (newobj ); |
|
335 |
} |
|
336 |
} else { |
|
337 |
/* |
|
338 |
* Take care for subclasses like TwoByteString |
|
339 |
*/ |
|
340 |
switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) { |
|
341 |
case BYTEARRAY: |
|
342 |
break; |
|
343 |
||
344 |
case WORDARRAY: |
|
345 |
case SWORDARRAY: |
|
346 |
nindexedinstvars *= 2; |
|
347 |
break; |
|
348 |
||
349 |
case LONGARRAY: |
|
350 |
case SLONGARRAY: |
|
351 |
nindexedinstvars *= 4; |
|
352 |
break; |
|
353 |
||
354 |
default: |
|
355 |
/* don't know about this array type, delegate to super */ |
|
356 |
goto out; |
|
357 |
} |
|
358 |
} |
|
359 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
360 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars; |
|
361 |
__PROTECT_CONTEXT__ |
|
362 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
363 |
__UNPROTECT_CONTEXT__ |
|
364 |
if (newobj != nil) { |
|
365 |
__InstPtr(newobj)->o_class = self; |
|
366 |
__qSTORE(newobj, self); |
|
367 |
if (nInstVars) { |
|
368 |
/* |
|
369 |
* still have to nil out named instvars ... |
|
370 |
*/ |
|
18284 | 371 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) |
19368 | 372 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
18284 | 373 |
#else |
374 |
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES) |
|
19368 | 375 |
/* |
376 |
* knowing that nil is 0 |
|
377 |
*/ |
|
378 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
18284 | 379 |
# else |
19368 | 380 |
op = __InstPtr(newobj)->i_instvars; |
381 |
while (nInstVars--) |
|
382 |
*op++ = nil; |
|
18284 | 383 |
# endif |
384 |
#endif |
|
19368 | 385 |
} |
386 |
RETURN ( newobj ); |
|
387 |
} |
|
388 |
} |
|
18284 | 389 |
} |
390 |
out:; |
|
391 |
%}. |
|
392 |
^ self basicNew:anInteger |
|
393 |
! |
|
394 |
||
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
395 |
with:aByteArray from:start to:stop |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
396 |
"return new instance with a copy of aByteArray |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
397 |
beginning at index start up to and including index stop" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
398 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
399 |
|len bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
400 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
401 |
len := stop-start+1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
402 |
bytes := self new:len. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
403 |
bytes replaceBytesFrom:1 to:len with:aByteArray startingAt:start. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
404 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
405 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
406 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
407 |
String with:#[40 41 42 43 44 45 46 47 48 49 50] from:2 to:5 |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
408 |
" |
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
409 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
410 |
|
1 | 411 |
!UninterpretedBytes class methodsFor:'queries'! |
412 |
||
8893 | 413 |
isAbstract |
11220 | 414 |
"Return if this class is an abstract class. |
415 |
True is returned for UninterpretedBytes here; false for subclasses. |
|
19461 | 416 |
Abstract subclasses must redefine this again." |
11220 | 417 |
|
8893 | 418 |
^ self == UninterpretedBytes |
419 |
! |
|
420 |
||
1 | 421 |
isBigEndian |
77 | 422 |
"return true, if words/shorts store the most-significant |
13575 | 423 |
byte first (MSB), false if least-sign.-first (LSB). |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
424 |
I.e. false for vax, intel; true for m68k, sun. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
425 |
|
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
426 |
Notice: UninterpretedBytes isBigEndian |
19368 | 427 |
this is inlined both by stc and the jit compiler" |
1 | 428 |
|
429 |
%{ /* NOCONTEXT */ |
|
430 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
431 |
#if defined(__MSBFIRST__) |
3936 | 432 |
RETURN (true); |
433 |
#else |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
434 |
# if defined(__LSBFIRST__) |
4275 | 435 |
RETURN (false); |
436 |
# else |
|
1 | 437 |
/* |
20816 | 438 |
* I don't like ifdefs - you always forget some ... |
3433 | 439 |
* therefore we look into a structure at run-time. |
440 |
* (also, there are CPUs around [mips], where the byteorder |
|
441 |
* is programmable, and which come in different flavours) |
|
442 |
* |
|
13575 | 443 |
* NOTICE: |
444 |
* both the JIT and stc may inline this to a |
|
3433 | 445 |
* constant for systems where this is known. |
1 | 446 |
*/ |
447 |
union { |
|
19368 | 448 |
unsigned int u_l; |
449 |
char u_c[sizeof(int)]; |
|
1 | 450 |
} u; |
451 |
||
452 |
u.u_l = 0x87654321; |
|
77 | 453 |
if (u.u_c[0] == 0x21) RETURN (false); |
454 |
RETURN (true); |
|
4275 | 455 |
# endif |
3936 | 456 |
#endif |
18346 | 457 |
%}. |
458 |
^ false "/ an arbitrary default |
|
459 |
||
3433 | 460 |
" |
461 |
UninterpretedBytes isBigEndian |
|
462 |
" |
|
3209 | 463 |
! |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
464 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
465 |
isBuiltInClass |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
466 |
"return true if this class is known by the run-time-system. |
3323 | 467 |
Here, true is returned, since UninterpretedBytes is the superclass of |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
468 |
some builtIn classes (ByteArray & ExternalBytes)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
469 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
470 |
^ self == UninterpretedBytes |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
471 |
|
3323 | 472 |
"Modified: / 23.4.1996 / 15:56:25 / cg" |
473 |
"Modified: / 5.3.1998 / 14:56:22 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
474 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
475 |
|
20961 | 476 |
!UninterpretedBytes methodsFor:'@ OLE Extensions'! |
477 |
||
478 |
addressAtOffset: index0Based |
|
479 |
"Answer the bytes starting at index0Based (0 based offset) |
|
480 |
as anExternalAddress. Answer nil if there is no address. |
|
481 |
Notice: Offsets are zero relative." |
|
482 |
||
483 |
| address | |
|
484 |
||
485 |
address := self pointerValueAt: index0Based + 1. |
|
486 |
^ address = 0 |
|
487 |
ifTrue: [ nil ] |
|
488 |
ifFalse: [ ExternalAddress newAddress: address ] |
|
489 |
||
490 |
"Modified: / 30-03-2016 / 11:00:19 / cg" |
|
491 |
! |
|
492 |
||
493 |
addressAtOffset: index0Based put: anExternalAddress |
|
494 |
"Set the bytes starting at index0Based (0 based offset) |
|
495 |
from the contents of anExternalAddress. |
|
496 |
Notice: Offsets are zero relative." |
|
497 |
||
498 |
|anAddress | |
|
499 |
||
500 |
anAddress := anExternalAddress isNil |
|
501 |
ifTrue:[0] |
|
502 |
ifFalse:[anExternalAddress address]. |
|
503 |
self pointerAt: index0Based + 1 put: anAddress |
|
504 |
! |
|
505 |
||
506 |
addressValueAtOffset: index0Based |
|
507 |
"Answer the pointer-value starting at index0Based (0 based offset) |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
508 |
as unsigned integer. |
20961 | 509 |
Notice: Offsets are zero relative." |
510 |
||
511 |
^ self pointerValueAt: index0Based + 1. |
|
512 |
! |
|
513 |
||
514 |
addressValueAtOffset: index0Based put:anAddress |
|
515 |
"Set the pointer-value starting at index0Based (0 based offset) |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
516 |
as unsigned integer. |
20961 | 517 |
Notice: Offsets are zero relative." |
518 |
||
519 |
self pointerAt: index0Based + 1 put:anAddress. |
|
520 |
! |
|
521 |
||
522 |
byteAtOffset:index0Based |
|
523 |
"return the byte at index0Based. |
|
524 |
For ByteArray, this is the same as basicAt: |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
525 |
however, for strings or symbols, |
20961 | 526 |
this returns a numeric byteValue instead of a character. |
527 |
Notice: Offsets are zero relative." |
|
528 |
||
529 |
^ self byteAt:(index0Based + 1) |
|
530 |
! |
|
531 |
||
532 |
byteAtOffset:index0Based put:value |
|
533 |
"set the byte at index. For ByteArray, this is the same as basicAt:put:. |
|
534 |
However, for Strings, this expects a byteValue to be stored. |
|
535 |
Notice: Offsets are zero relative." |
|
536 |
||
537 |
^ self byteAt:(index0Based + 1) put:value |
|
538 |
! |
|
539 |
||
540 |
bytesAtOffset: index0Based count: count |
|
541 |
"Answer a ByteArray with count bytes copied |
|
542 |
from the receiver starting at index0Based. |
|
543 |
Notice: Offsets are zero relative." |
|
544 |
||
545 |
|newBytes | |
|
546 |
||
547 |
newBytes := ByteArray new: count. |
|
548 |
newBytes replaceBytesFrom:1 to:count with:self startingAt:(index0Based + 1). |
|
549 |
^newBytes |
|
550 |
||
551 |
" |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
552 |
#[83 0 0 0 0 0 0 0 120 237 14 0 4 0 0 ] bytesAtOffset: 9 count: 3 |
20961 | 553 |
" |
554 |
||
555 |
"Modified (comment): / 30-03-2016 / 11:24:41 / cg" |
|
556 |
! |
|
557 |
||
558 |
bytesAtOffset: index0Based put: aByteObject |
|
559 |
"Store aByteObject at anInteger in the receiver. |
|
560 |
Notice: Offsets are zero relative." |
|
561 |
||
562 |
^ self |
|
563 |
replaceBytesFrom:(index0Based + 1) to:(index0Based + aByteObject size) |
|
564 |
with:aByteObject startingAt:1. |
|
565 |
! |
|
566 |
||
567 |
fillFromAddress: anAddress |
|
568 |
"Fill the receiver by copying mySize bytes from host memory at anAddress. |
|
569 |
Warning: because anAddress might not know, how big it is, |
|
570 |
the size of the receiver must already be correct. |
|
571 |
(i.e. the receiver must have been allocated from a returned size value)" |
|
572 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
573 |
self |
20961 | 574 |
replaceFrom:1 to:self size |
575 |
with:anAddress asExternalBytes |
|
576 |
startingAt:1 |
|
577 |
! |
|
578 |
||
579 |
longAtOffset: index0Based |
|
580 |
"same as longAt:, but with a 0-based offset. |
|
581 |
Notice: Offsets are zero relative." |
|
582 |
||
583 |
^self signedInt32At:(index0Based + 1) |
|
584 |
! |
|
585 |
||
586 |
longAtOffset: index0Based put: value |
|
587 |
"same as longAtput::, but with a 0-based offset. |
|
588 |
Notice: Offsets are zero relative." |
|
589 |
||
590 |
^self signedInt32At:index0Based +1 put:value |
|
591 |
! |
|
592 |
||
593 |
shortAtOffset: index0Based |
|
594 |
"same as shortAt:, but with a 0-based offset. |
|
595 |
Notice: Offsets are zero relative." |
|
596 |
||
597 |
^self signedInt16At: index0Based + 1 |
|
598 |
! |
|
599 |
||
600 |
shortAtOffset: index0Based put: value |
|
601 |
"same as shortAt:put:, but with a 0-based offset. |
|
602 |
Notice: Offsets are zero relative." |
|
603 |
||
604 |
^self signedInt16At: index0Based + 1 put: value |
|
605 |
! |
|
606 |
||
607 |
uLongAtOffset: index0Based |
|
608 |
"same as unsignedLongAt:, but with a 0-based offset. |
|
609 |
Notice: Offsets are zero relative." |
|
610 |
||
611 |
^ self unsignedInt32At:(index0Based + 1) |
|
612 |
! |
|
613 |
||
614 |
uLongAtOffset: index0Based put: value |
|
615 |
"same as unsignedLongAt:put:, but with a 0-based offset. |
|
616 |
Notice: Offsets are zero relative." |
|
617 |
||
618 |
^ self unsignedInt32At:(index0Based + 1) put: value |
|
619 |
! |
|
620 |
||
621 |
uShortAtOffset: index0Based |
|
622 |
"same as unsignedShortAt:, but with a 0-based offset. |
|
623 |
Notice: Offsets are zero relative." |
|
624 |
||
625 |
^ self unsignedInt16At:(index0Based + 1) |
|
626 |
! |
|
627 |
||
628 |
uShortAtOffset: index0Based put: value |
|
629 |
"same as unsignedShortAt:put:, but with a 0-based offset. |
|
630 |
Notice: Offsets are zero relative." |
|
631 |
||
632 |
^ self unsignedInt16At:(index0Based + 1) put: value |
|
633 |
! |
|
634 |
||
635 |
unsignedLongAtOffset: index0Based |
|
636 |
"same as unsignedLongAt:, but with a 0-based offset. |
|
637 |
Notice: Offsets are zero relative." |
|
638 |
||
639 |
^self unsignedInt32At: index0Based + 1 |
|
640 |
! |
|
641 |
||
642 |
unsignedLongAtOffset: index0Based put: value |
|
643 |
"same as unsignedLongAt:put:, but with a 0-based offset. |
|
644 |
Notice: Offsets are zero relative." |
|
645 |
||
646 |
^self unsignedInt32At: index0Based + 1 put: value |
|
647 |
! |
|
648 |
||
649 |
unsignedShortAtOffset: index0Based |
|
650 |
"same as unsignedShortAt:, but with a 0-based offset. |
|
651 |
Notice: Offsets are zero relative." |
|
652 |
||
653 |
^self unsignedInt16At: index0Based + 1 |
|
654 |
! |
|
655 |
||
656 |
unsignedShortAtOffset: index0Based put: value |
|
657 |
"same as unsignedShortAt:put:, but with a 0-based offset. |
|
658 |
Notice: Offsets are zero relative." |
|
659 |
||
660 |
^self unsignedInt16At:(index0Based + 1) put: value |
|
661 |
! ! |
|
662 |
||
19349 | 663 |
!UninterpretedBytes methodsFor:'Compatibility'! |
664 |
||
665 |
doubleWordAt:index |
|
666 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
667 |
The index is a smalltalk index (i.e. 1-based). |
|
668 |
The value is retrieved in the machines natural byte order." |
|
669 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
670 |
^ self unsignedInt32At:index MSB:self isBigEndian |
19349 | 671 |
|
672 |
" |
|
673 |
|b| |
|
674 |
||
675 |
b := ByteArray withAll:#(1 2 3 4). |
|
676 |
(b doubleWordAt:1) printStringRadix:16 |
|
677 |
" |
|
678 |
||
679 |
"Modified: / 5.3.1998 / 14:57:35 / stefan" |
|
680 |
! |
|
681 |
||
682 |
doubleWordAt:index MSB:msb |
|
683 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
684 |
The index is a smalltalk index (i.e. 1-based). |
|
685 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
686 |
LSB-first otherwise." |
|
687 |
||
688 |
^ self unsignedInt32At:index MSB:msb |
|
689 |
||
690 |
" |
|
691 |
|b| |
|
692 |
||
693 |
b := ByteArray withAll:#(1 2 3 4). |
|
694 |
(b doubleWordAt:1 MSB:true) printStringRadix:16. |
|
695 |
(b doubleWordAt:1 MSB:false) printStringRadix:16 |
|
696 |
" |
|
697 |
! |
|
698 |
||
699 |
doubleWordAt:byteIndex put:anInteger |
|
700 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
701 |
The index is a smalltalk index (i.e. 1-based). |
|
702 |
The value should be in the range 0 to 16rFFFFFFFF |
|
703 |
(for negative values, the stored value is not defined). |
|
704 |
The value is stored in the machines natural byte order." |
|
705 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
706 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:self isBigEndian |
19349 | 707 |
|
708 |
" |
|
709 |
|b| |
|
710 |
b := ByteArray new:4. |
|
711 |
b doubleWordAt:1 put:16r04030201. |
|
712 |
b inspect |
|
713 |
" |
|
714 |
||
715 |
"Modified: / 5.3.1998 / 14:57:48 / stefan" |
|
716 |
! |
|
717 |
||
718 |
doubleWordAt:byteIndex put:anInteger MSB:msb |
|
719 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
720 |
The index is a smalltalk index (i.e. 1-based). |
|
721 |
The value must be in the range 0 to 16rFFFFFFFF. |
|
722 |
The value is stored MSB-first if msb is true; LSB-first otherwise." |
|
723 |
||
724 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:msb |
|
725 |
||
726 |
" |
|
727 |
|b| |
|
728 |
b := ByteArray new:8. |
|
729 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
|
730 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
731 |
b inspect |
|
732 |
" |
|
733 |
||
734 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
735 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
|
736 |
! |
|
737 |
||
738 |
doubleWordAtDoubleWordIndex:int32Index |
|
739 |
"return the unsigned long (int32) at index, anInteger. |
|
740 |
Fetching in the machine's natural byte order. |
|
741 |
Indices are 1-based and scaled as appropriate to allow |
|
742 |
accessing the memory as an array of doubleWord entries. |
|
743 |
(i.e. indices are 1, 2, ...)" |
|
744 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
745 |
^ self doubleWordAtDoubleWordIndex:int32Index MSB:self isBigEndian |
19349 | 746 |
|
747 |
"Created: / 21.1.1998 / 17:43:53 / cg" |
|
748 |
"Modified: / 5.3.1998 / 14:58:06 / stefan" |
|
749 |
! |
|
750 |
||
751 |
doubleWordAtDoubleWordIndex:int32Index MSB:msb |
|
752 |
"return the unsigned long (int32) at index, anInteger. |
|
753 |
Fetching is MSB if msb is true, LSB otherwise. |
|
754 |
Indices are 1-based and scaled as appropriate to allow |
|
755 |
accessing the memory as an array of doubleWord entries. |
|
756 |
(i.e. indices are 1, 2, ...)" |
|
757 |
||
758 |
^ self unsignedInt32At:((int32Index - 1) * 4 + 1) MSB:msb |
|
759 |
||
760 |
"Created: / 21.1.1998 / 17:44:07 / cg" |
|
761 |
! |
|
762 |
||
763 |
doubleWordAtDoubleWordIndex:int32Index put:anInteger |
|
764 |
"set the long at index, anInteger. |
|
765 |
Storing in the machines natural byte order. |
|
766 |
Indices are 1-based and scaled as appropriate to allow |
|
767 |
accessing the memory as an array of doubleWord entries. |
|
768 |
(i.e. indices are 1, 2, ...)" |
|
769 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
770 |
^ self doubleWordAtDoubleWordIndex:int32Index put:anInteger MSB:self isBigEndian |
19349 | 771 |
|
772 |
"Created: / 21.1.1998 / 17:44:13 / cg" |
|
773 |
"Modified: / 5.3.1998 / 14:58:19 / stefan" |
|
774 |
! |
|
775 |
||
776 |
doubleWordAtDoubleWordIndex:int32Index put:anInteger MSB:msb |
|
777 |
"set the long at index, anInteger. |
|
778 |
Storing is MSB if msb is true, LSB otherwise. |
|
779 |
Indices are 1-based and scaled as appropriate to allow |
|
780 |
accessing the memory as an array of doubleWord entries. |
|
781 |
(i.e. indices are 1, 2, ...)" |
|
782 |
||
783 |
^ self unsignedInt32At:((int32Index - 1) * 4 + 1) put:anInteger MSB:msb |
|
784 |
||
785 |
"Created: / 21.1.1998 / 17:44:19 / cg" |
|
786 |
! |
|
787 |
||
788 |
int16At:byteIndex |
|
789 |
"return the 2-bytes starting at index as a signed Integer. |
|
790 |
The index is a smalltalk index (i.e. 1-based). |
|
791 |
The value is retrieved in the machines natural byte order. |
|
792 |
This may be worth a primitive." |
|
793 |
||
794 |
^ self signedInt16At:byteIndex |
|
795 |
||
796 |
" |
|
797 |
|b| |
|
798 |
b := ByteArray new:2. |
|
799 |
b wordAt:1 put:16rFFFF. |
|
800 |
b signedWordAt:1 |
|
801 |
" |
|
802 |
||
803 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
804 |
! |
|
805 |
||
806 |
int16At:byteIndex MSB:msb |
|
807 |
"return the 2-bytes starting at index as a signed Integer. |
|
808 |
The index is a smalltalk index (i.e. 1-based). |
|
809 |
The value is retrieved in the machines natural byte order. |
|
810 |
This may be worth a primitive." |
|
811 |
||
812 |
^ self signedInt16At:byteIndex MSB:msb |
|
813 |
||
814 |
" |
|
815 |
|b| |
|
816 |
b := ByteArray new:2. |
|
817 |
b wordAt:1 put:16rFFFF. |
|
818 |
b signedWordAt:1 |
|
819 |
" |
|
820 |
||
821 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
822 |
! |
|
823 |
||
824 |
int16At:index put:anInteger |
|
825 |
"set the 2-bytes starting at index from the signed Integer value. |
|
826 |
The index is a smalltalk index (i.e. 1-based). |
|
827 |
The stored value must be in the range -32768 .. +32676. |
|
828 |
The value is stored in the machine's natural byteorder" |
|
829 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
830 |
^ self signedInt16At:index put:anInteger MSB:self isBigEndian |
19349 | 831 |
|
832 |
" |
|
833 |
|b| |
|
834 |
b := ByteArray new:4. |
|
835 |
b shortAt:1 put:1 bigEndian:true. |
|
836 |
b shortAt:3 put:1 bigEndian:false. |
|
837 |
b inspect |
|
838 |
" |
|
839 |
||
840 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
841 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
842 |
! |
|
843 |
||
844 |
int16At:index put:anInteger MSB:bigEndian |
|
845 |
"set the 2-bytes starting at index from the signed Integer value. |
|
846 |
The index is a smalltalk index (i.e. 1-based). |
|
847 |
The stored value must be in the range -32768 .. +32676. |
|
848 |
The value is stored in the byteorder given by bigEndian. |
|
849 |
This may be worth a primitive." |
|
850 |
||
851 |
||
852 |
^ self signedInt16At:index put:anInteger MSB:bigEndian |
|
853 |
||
854 |
" |
|
855 |
|b| |
|
856 |
b := ByteArray new:4. |
|
857 |
b shortAt:1 put:1 bigEndian:true. |
|
858 |
b shortAt:3 put:1 bigEndian:false. |
|
859 |
b inspect |
|
860 |
" |
|
861 |
||
862 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
863 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
864 |
! |
|
865 |
||
866 |
longAt:index |
|
867 |
"return the 4-bytes starting at index as a signed Integer. |
|
868 |
The index is a smalltalk index (i.e. 1-based). |
|
869 |
The value is retrieved in the machines natural byte order, |
|
870 |
therefore, this should only be used for byte-data which is |
|
871 |
only used inside this machine. |
|
872 |
To setup data packets which are to be sent to other machines, |
|
873 |
or stored into a file, always use longAt:MSB: and specify |
|
874 |
a definite byteOrder." |
|
875 |
||
876 |
^ self signedInt32At:index |
|
877 |
||
878 |
" |
|
879 |
|b| |
|
880 |
b := ByteArray new:4. |
|
881 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
882 |
(b longAt:1) |
|
883 |
" |
|
884 |
||
885 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
886 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
887 |
! |
|
888 |
||
889 |
longAt:index bigEndian:msb |
|
890 |
"return the 4-bytes starting at index as a signed Integer. |
|
891 |
The index is a smalltalk index (i.e. 1-based). |
|
892 |
Depending on msb, the value is retrieved MSB-first or LSB-first. |
|
893 |
This may be worth a primitive." |
|
894 |
||
895 |
^ self signedInt32At:index MSB:msb |
|
896 |
||
897 |
" |
|
898 |
|b| |
|
899 |
b := ByteArray new:4. |
|
900 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
901 |
(b longAt:1) |
|
902 |
" |
|
903 |
||
904 |
"Modified: / 1.7.1996 / 21:11:33 / cg" |
|
905 |
"Created: / 5.3.1998 / 14:02:03 / stefan" |
|
906 |
! |
|
907 |
||
908 |
longAt:index put:value |
|
909 |
"set the 4-bytes starting at index from the signed Integer value. |
|
910 |
The index is a smalltalk index (i.e. 1-based). |
|
911 |
The value is stored in the machine's natural byte order." |
|
912 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
913 |
^ self signedInt32At:index put:value MSB:self isBigEndian |
19349 | 914 |
|
915 |
" |
|
916 |
|b| |
|
917 |
b := ByteArray new:4. |
|
918 |
b longAt:1 put:-1. |
|
919 |
(b unsignedLongAt:1) printStringRadix:16 |
|
920 |
" |
|
921 |
||
922 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
|
923 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
924 |
! |
|
925 |
||
926 |
longAt:byteIndex put:anInteger bigEndian:msb |
|
927 |
"store a signed long (32bit) integer. |
|
928 |
The index is a smalltalk index (i.e. 1-based)." |
|
929 |
||
930 |
^ self signedInt32At:byteIndex put:anInteger MSB:msb |
|
931 |
||
932 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
933 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
934 |
! |
|
935 |
||
936 |
longLongAt:index |
|
937 |
"return the 8-bytes starting at index as a signed Integer. |
|
938 |
The index is a smalltalk index (i.e. 1-based). |
|
23547
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
23405
diff
changeset
|
939 |
The value is retrieved in the machineÄs natural byte order. |
19349 | 940 |
This may be worth a primitive." |
941 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
942 |
^ self signedInt64At:index MSB:self isBigEndian |
19349 | 943 |
|
944 |
" |
|
945 |
|b| |
|
946 |
b := ByteArray new:4. |
|
947 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
948 |
(b longLongAt:1) |
|
949 |
" |
|
950 |
||
951 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
952 |
"Created: / 5.3.1998 / 14:40:05 / stefan" |
|
953 |
"Modified: / 5.3.1998 / 14:58:32 / stefan" |
|
954 |
! |
|
955 |
||
956 |
longLongAt:index bigEndian:msb |
|
957 |
"return the 8-bytes starting at index as a signed Integer. |
|
958 |
The index is a smalltalk index (i.e. 1-based). |
|
959 |
The value is retrieved in the given byte order. |
|
960 |
This may be worth a primitive." |
|
961 |
||
962 |
^ self signedInt64At:index MSB:msb |
|
963 |
||
964 |
" |
|
965 |
|b| |
|
966 |
b := ByteArray new:4. |
|
967 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
968 |
(b longLongAt:1 msb:true) |
|
969 |
" |
|
970 |
||
971 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
972 |
"Created: / 5.3.1998 / 14:40:54 / stefan" |
|
973 |
"Modified: / 9.5.1998 / 01:10:59 / cg" |
|
974 |
! |
|
975 |
||
976 |
longLongAt:byteIndex put:anInteger |
|
977 |
"store a signed longLong (64bit) integer. |
|
978 |
The index is a smalltalk index (i.e. 1-based). |
|
979 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
980 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
981 |
^ self signedInt64At:byteIndex put:anInteger MSB:self isBigEndian |
19349 | 982 |
! |
983 |
||
984 |
longLongAt:byteIndex put:anInteger bigEndian:msb |
|
985 |
"store a signed longLong (64bit) integer. |
|
986 |
The index is a smalltalk index (i.e. 1-based). |
|
987 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
988 |
||
989 |
^ self signedInt64At:byteIndex put:anInteger MSB:msb |
|
990 |
||
991 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
992 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
993 |
! |
|
994 |
||
995 |
quadWordAt:index MSB:msb |
|
996 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
997 |
The index is a smalltalk index (i.e. 1-based). |
|
998 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
999 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1000 |
^ self unsignedInt64At:index MSB:msb |
19349 | 1001 |
|
1002 |
" |
|
1003 |
|b| |
|
1004 |
||
1005 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
1006 |
(b quadWordAt:1 MSB:false) printStringRadix:16 |
|
1007 |
" |
|
1008 |
||
1009 |
"Modified: 5.11.1996 / 14:06:21 / cg" |
|
1010 |
! |
|
1011 |
||
1012 |
quadWordAt:index put:anInteger MSB:msb |
|
1013 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1014 |
The index is a smalltalk index (i.e. 1-based). |
|
1015 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1016 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
1017 |
||
1018 |
^ self unsignedInt64At:index put:anInteger MSB:msb |
|
1019 |
||
1020 |
" |
|
1021 |
|b| |
|
1022 |
b := ByteArray new:8. |
|
1023 |
b quadWordAtIndex:1 put:16r0807060504030201 MSB:false. |
|
1024 |
b inspect |
|
1025 |
" |
|
1026 |
! |
|
1027 |
||
1028 |
shortAt:index |
|
1029 |
"return the 2-bytes starting at index as a signed Integer. |
|
1030 |
The index is a smalltalk index (i.e. 1-based). |
|
1031 |
The value is retrieved in the machines natural byte order. |
|
1032 |
This may be worth a primitive. |
|
1033 |
This is the ST80 equivalent of #signedWordAt:" |
|
1034 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1035 |
^ self signedInt16At:index MSB:self isBigEndian |
19349 | 1036 |
|
1037 |
" |
|
1038 |
|b| |
|
1039 |
b := ByteArray new:2. |
|
1040 |
b unsignedShortAt:1 put:16rFFFF. |
|
1041 |
b shortAt:1 |
|
1042 |
" |
|
1043 |
||
1044 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
|
1045 |
"Created: / 5.3.1998 / 10:59:57 / stefan" |
|
1046 |
"Modified: / 5.3.1998 / 23:39:38 / stefan" |
|
1047 |
! |
|
1048 |
||
1049 |
shortAt:index bigEndian:msb |
|
1050 |
"return the 2-bytes starting at index as a signed Integer. |
|
1051 |
The index is a smalltalk index (i.e. 1-based). |
|
1052 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
1053 |
LSB-first otherwise. |
|
1054 |
This is the ST80 equivalent of #signedWordAt:" |
|
1055 |
||
19368 | 1056 |
^ self signedInt16At:index MSB:msb |
19349 | 1057 |
|
1058 |
" |
|
1059 |
|b| |
|
1060 |
b := ByteArray new:2. |
|
1061 |
b unsignedShortAt:1 put:16rFFFF. |
|
1062 |
b shortAt:1 |
|
1063 |
" |
|
1064 |
||
1065 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
|
1066 |
"Created: / 5.3.1998 / 23:41:21 / stefan" |
|
1067 |
! |
|
1068 |
||
1069 |
shortAt:index put:value |
|
1070 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1071 |
The index is a smalltalk index (i.e. 1-based). |
|
1072 |
The stored value must be in the range -32768 .. +32676. |
|
1073 |
The value is stored in the machines natural byteorder. |
|
1074 |
This may be worth a primitive. |
|
1075 |
This is the ST80 equivalent of #signedWordAt:put:" |
|
1076 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1077 |
^ self signedInt16At:index put:value MSB:self isBigEndian |
19349 | 1078 |
|
1079 |
" |
|
1080 |
|b| |
|
1081 |
b := ByteArray new:6. |
|
1082 |
b shortAt:1 put:-1. |
|
1083 |
b shortAt:3 put:-2. |
|
1084 |
b shortAt:5 put:0. |
|
1085 |
b inspect |
|
1086 |
" |
|
1087 |
||
1088 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1089 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
1090 |
! |
|
1091 |
||
1092 |
shortAt:index put:value bigEndian:bigEndian |
|
1093 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1094 |
The index is a smalltalk index (i.e. 1-based). |
|
1095 |
The stored value must be in the range -32768 .. +32676. |
|
1096 |
The value is stored in the byteorder given by bigEndian. |
|
1097 |
This may be worth a primitive." |
|
1098 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1099 |
^ self signedInt16At:index put:value MSB:self isBigEndian |
19349 | 1100 |
|
1101 |
" |
|
1102 |
|b| |
|
1103 |
b := ByteArray new:4. |
|
1104 |
b shortAt:1 put:1 bigEndian:true. |
|
1105 |
b shortAt:3 put:1 bigEndian:false. |
|
1106 |
b inspect |
|
1107 |
" |
|
1108 |
||
1109 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1110 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
1111 |
! |
|
1112 |
||
1113 |
signedDoubleWordAt:index |
|
1114 |
"return the 4-bytes starting at index as a signed Integer. |
|
1115 |
The index is a smalltalk index (i.e. 1-based). |
|
1116 |
The value is retrieved in the machines natural byte order. |
|
1117 |
This may be worth a primitive." |
|
1118 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1119 |
^ self signedInt32At:index MSB:self isBigEndian |
19349 | 1120 |
|
1121 |
" |
|
1122 |
|b| |
|
1123 |
b := ByteArray new:4. |
|
1124 |
b doubleWordAt:1 put:16rFFFFFFFF. |
|
1125 |
(b signedDoubleWordAt:1) |
|
1126 |
" |
|
1127 |
" |
|
1128 |
|b| |
|
1129 |
b := ByteArray new:4. |
|
1130 |
b signedDoubleWordAt:1 put:-1. |
|
1131 |
(b doubleWordAt:1) |
|
1132 |
" |
|
1133 |
||
1134 |
"Modified: 1.7.1996 / 21:11:28 / cg" |
|
1135 |
! |
|
1136 |
||
1137 |
signedDoubleWordAt:index MSB:msb |
|
1138 |
"return the 4-bytes starting at index as a (signed) Integer. |
|
1139 |
The index is a smalltalk index (i.e. 1-based). |
|
1140 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
1141 |
LSB-first otherwise." |
|
1142 |
||
1143 |
^ self signedInt32At:index MSB:msb |
|
1144 |
||
1145 |
" |
|
1146 |
|b| |
|
1147 |
||
1148 |
b := ByteArray withAll:#(1 2 3 4). |
|
1149 |
(b signedDoubleWordAt:1 MSB:true) printStringRadix:16. |
|
1150 |
(b signedDoubleWordAt:1 MSB:false) printStringRadix:16 |
|
1151 |
" |
|
1152 |
! |
|
1153 |
||
1154 |
signedDoubleWordAt:index put:value |
|
1155 |
"set the 4-bytes starting at index from the signed Integer value. |
|
1156 |
The index is a smalltalk index (i.e. 1-based). |
|
1157 |
The value is stored in the machines natural byte order. |
|
1158 |
This may be worth a primitive." |
|
1159 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1160 |
^ self signedInt32At:index put:value MSB:self isBigEndian |
19349 | 1161 |
|
1162 |
" |
|
1163 |
|b| |
|
1164 |
b := ByteArray new:4. |
|
1165 |
b signedDoubleWordAt:1 put:-1. |
|
1166 |
(b doubleWordAt:1) printStringRadix:16 |
|
1167 |
" |
|
1168 |
||
1169 |
"Modified: 1.7.1996 / 21:11:39 / cg" |
|
1170 |
! |
|
1171 |
||
1172 |
signedDoubleWordAt:index put:value MSB:msb |
|
1173 |
"set the 4-bytes starting at index from the signed Integer value. |
|
1174 |
The index is a smalltalk index (i.e. 1-based). |
|
1175 |
Depending on msb, the value is stored MSB-first or LSB-first. |
|
1176 |
This may be worth a primitive." |
|
1177 |
||
1178 |
^ self signedInt32At:index put:value MSB:msb |
|
1179 |
||
1180 |
" |
|
1181 |
|b| |
|
1182 |
b := ByteArray new:4. |
|
1183 |
b signedDoubleWordAt:1 put:-1. |
|
1184 |
(b doubleWordAt:1) printStringRadix:16 |
|
1185 |
" |
|
1186 |
||
1187 |
"Modified: 1.7.1996 / 21:11:46 / cg" |
|
15087 | 1188 |
! |
1189 |
||
1190 |
signedLongAt:index |
|
1191 |
"return the 4-bytes starting at index as a signed Integer. |
|
1192 |
The index is a smalltalk index (i.e. 1-based). |
|
19415 | 1193 |
The value is retrieved in the machine's natural byte order." |
1194 |
||
1195 |
^ self signedInt32At:index |
|
15087 | 1196 |
|
1197 |
" |
|
1198 |
|b| |
|
1199 |
b := ByteArray new:4. |
|
1200 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
1201 |
b signedLongAt:1 |
|
1202 |
" |
|
1203 |
||
1204 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
1205 |
! |
|
1206 |
||
1207 |
signedLongAt:index put:newValue |
|
19415 | 1208 |
"store a 4-bytes signed value starting at index. |
15087 | 1209 |
The index is a smalltalk index (i.e. 1-based). |
19415 | 1210 |
The value is in the machine's natural byte order." |
1211 |
||
1212 |
^ self signedInt32At:index put:newValue |
|
15087 | 1213 |
|
1214 |
" |
|
1215 |
|b| |
|
1216 |
b := ByteArray new:4. |
|
1217 |
b signedLongAt:1 put:-1. |
|
1218 |
b unsignedLongAt:1 |
|
1219 |
" |
|
1220 |
||
1221 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
19349 | 1222 |
! |
1223 |
||
1224 |
signedWordAt:index |
|
1225 |
"return the 2-bytes starting at index as a signed Integer. |
|
1226 |
The index is a smalltalk index (i.e. 1-based). |
|
1227 |
The value is retrieved in the machines natural byte order. |
|
1228 |
This may be worth a primitive." |
|
1229 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1230 |
^ (self unsignedInt16At:index MSB:self isBigEndian) signExtendedShortValue |
19349 | 1231 |
|
1232 |
" |
|
1233 |
|b| |
|
1234 |
b := ByteArray new:2. |
|
1235 |
b wordAt:1 put:16rFFFF. |
|
1236 |
b signedWordAt:1 |
|
1237 |
" |
|
1238 |
||
1239 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
1240 |
! |
|
1241 |
||
1242 |
signedWordAt:index MSB:msb |
|
1243 |
"return the 2-bytes starting at index as a signed Integer. |
|
1244 |
The index is a smalltalk index (i.e. 1-based). |
|
1245 |
The value is retrieved MSB-first if the msb-arg is true, |
|
1246 |
LSB-first otherwise. |
|
1247 |
This may be worth a primitive." |
|
1248 |
||
1249 |
^ (self unsignedInt16At:index MSB:msb) signExtendedShortValue |
|
1250 |
||
1251 |
" |
|
1252 |
|b| |
|
1253 |
b := ByteArray new:2. |
|
1254 |
b wordAt:1 put:16r0080. |
|
1255 |
b signedWordAt:1 MSB:true. |
|
1256 |
b signedWordAt:1 MSB:false. |
|
1257 |
" |
|
1258 |
||
1259 |
"Modified: 1.7.1996 / 21:15:57 / cg" |
|
1260 |
! |
|
1261 |
||
1262 |
signedWordAt:byteIndex put:anInteger |
|
1263 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1264 |
The index is a smalltalk index (i.e. 1-based). |
|
1265 |
The stored value must be in the range -32768 .. +32676. |
|
1266 |
The value is stored in the machine's natural byteorder." |
|
1267 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1268 |
^ self signedInt16At:byteIndex put:anInteger MSB:self isBigEndian |
19349 | 1269 |
|
1270 |
" |
|
1271 |
|b| |
|
1272 |
b := ByteArray new:6. |
|
1273 |
b shortAt:1 put:-1. |
|
1274 |
b shortAt:3 put:-2. |
|
1275 |
b shortAt:5 put:0. |
|
1276 |
b inspect |
|
1277 |
" |
|
1278 |
||
1279 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1280 |
"Modified: / 5.3.1998 / 11:01:30 / stefan" |
|
1281 |
! |
|
1282 |
||
1283 |
signedWordAt:byteIndex put:anInteger MSB:msb |
|
1284 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1285 |
The index is a smalltalk index (i.e. 1-based). |
|
1286 |
The stored value must be in the range -32768 .. +32676. |
|
1287 |
The value is stored MSB-first, if the msb-arg is true; |
|
1288 |
LSB-first otherwise." |
|
1289 |
||
19415 | 1290 |
^ self signedInt16At:byteIndex put:anInteger MSB:msb |
19349 | 1291 |
|
1292 |
" |
|
1293 |
|b| |
|
1294 |
b := ByteArray new:4. |
|
1295 |
b signedWordAt:1 put:-1. |
|
1296 |
b signedWordAt:3 put:-2. |
|
1297 |
b inspect |
|
1298 |
" |
|
1299 |
||
1300 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
1301 |
! |
|
1302 |
||
25414
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1303 |
unsignedByteAt:index |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1304 |
"return the 1 byte at index as an (unsigned) Integer. |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1305 |
The index is a smalltalk index (i.e. 1-based)." |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1306 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1307 |
^ self at:index |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1308 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1309 |
" |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1310 |
|b| |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1311 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1312 |
b := ByteArray withAll:#(255 2 3 4). |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1313 |
(b unsignedByteAt:1) printStringRadix:16 |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1314 |
" |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1315 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1316 |
"Created: / 13-05-2021 / 11:19:13 / Jan Vrany <jan.vrany@labware.com>" |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1317 |
! |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1318 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1319 |
unsignedByteAt:index put: value |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1320 |
^ self at:index put: value |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1321 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1322 |
"Created: / 13-05-2021 / 11:20:00 / Jan Vrany <jan.vrany@labware.com>" |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1323 |
! |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1324 |
|
19349 | 1325 |
unsignedLongAt:index |
1326 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1327 |
The index is a smalltalk index (i.e. 1-based). |
|
1328 |
The value is retrieved in the machine's natural byte order. |
|
1329 |
Subclasses may redefine this for better performance. |
|
1330 |
Same as doubleWordAt: for protocol completeness" |
|
1331 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1332 |
^ self unsignedInt32At:index MSB:self isBigEndian |
19349 | 1333 |
|
1334 |
" |
|
1335 |
|b| |
|
1336 |
||
1337 |
b := ByteArray withAll:#(1 2 3 4). |
|
1338 |
(b unsignedLongAt:1) printStringRadix:16 |
|
1339 |
" |
|
1340 |
||
1341 |
"Created: / 5.3.1998 / 11:56:53 / stefan" |
|
1342 |
"Modified: / 5.3.1998 / 14:58:48 / stefan" |
|
1343 |
! |
|
1344 |
||
1345 |
unsignedLongAt:index bigEndian:msb |
|
1346 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1347 |
The index is a smalltalk index (i.e. 1-based). |
|
1348 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
1349 |
LSB-first otherwise. |
|
1350 |
Subclasses may redefine this for better performance. |
|
1351 |
Same as doubleWordAt:MSB: for protocol completeness" |
|
1352 |
||
1353 |
^ self unsignedInt32At:index MSB:msb |
|
1354 |
||
1355 |
" |
|
1356 |
|b| |
|
1357 |
||
1358 |
b := ByteArray withAll:#(1 2 3 4). |
|
1359 |
(b unsignedLongAt:1 bigEndian:true) printStringRadix:16. |
|
1360 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1361 |
" |
|
1362 |
||
1363 |
"Modified: / 21.1.1998 / 17:42:30 / cg" |
|
1364 |
"Created: / 5.3.1998 / 11:46:05 / stefan" |
|
1365 |
! |
|
1366 |
||
1367 |
unsignedLongAt:index put:value |
|
1368 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1369 |
The index is a smalltalk index (i.e. 1-based). |
|
1370 |
The value should be in the range 0 to 16rFFFFFFFF |
|
1371 |
(for negative values, the stored value is not defined). |
|
1372 |
The value is stored in the machines natural byte order. |
|
1373 |
Subclasses may redefine this for better performance. |
|
1374 |
Same as doubleWordAt:put: for protocol completeness" |
|
1375 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1376 |
^ self unsignedInt32At:index put:value MSB:self isBigEndian |
19349 | 1377 |
|
1378 |
" |
|
1379 |
|b| |
|
1380 |
b := ByteArray new:4. |
|
1381 |
b unsignedLongAt:1 put:16r04030201. |
|
1382 |
b inspect |
|
1383 |
" |
|
1384 |
||
1385 |
"Created: / 5.3.1998 / 11:57:44 / stefan" |
|
1386 |
"Modified: / 5.3.1998 / 14:58:59 / stefan" |
|
1387 |
! |
|
1388 |
||
1389 |
unsignedLongAt:index put:aNumber bigEndian:msb |
|
1390 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1391 |
The index is a smalltalk index (i.e. 1-based). |
|
1392 |
The value must be in the range 0 to 16rFFFFFFFF. |
|
1393 |
The value is stored MSB-first if msb is true; LSB-first otherwise. |
|
1394 |
Subclasses may redefine this for better performance. |
|
1395 |
Same as doubleWordAt:put:MSB: for protocol completeness" |
|
1396 |
||
1397 |
^ self unsignedInt32At:index put:aNumber MSB:msb |
|
1398 |
||
1399 |
" |
|
1400 |
|b| |
|
1401 |
b := ByteArray new:8. |
|
1402 |
b unsignedLongAt:1 put:16r04030201 bigEndian:true. |
|
1403 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1404 |
" |
|
1405 |
||
1406 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
1407 |
"Created: / 5.3.1998 / 11:43:53 / stefan" |
|
1408 |
"Modified: / 5.3.1998 / 11:47:30 / stefan" |
|
1409 |
! |
|
1410 |
||
25414
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1411 |
unsignedLongLongAt:index |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1412 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1413 |
The index is a smalltalk index (i.e. 1-based). |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1414 |
The value is retrieved in the machine's natural byte order. |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1415 |
Subclasses may redefine this for better performance. |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1416 |
Same as doubleWordAt: for protocol completeness" |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1417 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1418 |
^ self unsignedInt64At:index MSB:self isBigEndian |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1419 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1420 |
" |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1421 |
|b| |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1422 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1423 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1424 |
(b unsignedLongLongAt:1) printStringRadix:16 |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1425 |
" |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1426 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1427 |
"Created: / 13-05-2021 / 11:15:34 / Jan Vrany <jan.vrany@labware.com>" |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1428 |
! |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
1429 |
|
19349 | 1430 |
unsignedLongLongAt:index bigEndian:msb |
1431 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
1432 |
The index is a smalltalk index (i.e. 1-based). |
|
1433 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
1434 |
||
1435 |
^ self unsignedInt64At:index MSB:msb |
|
1436 |
||
1437 |
" |
|
1438 |
|b| |
|
1439 |
||
1440 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
1441 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
|
1442 |
" |
|
1443 |
||
1444 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
1445 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
1446 |
! |
|
1447 |
||
1448 |
unsignedLongLongAt:index put:anInteger |
|
1449 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1450 |
The index is a smalltalk index (i.e. 1-based). |
|
1451 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1452 |
The value is stored in natural byte order." |
|
1453 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1454 |
^ self unsignedInt64At:index put:anInteger MSB:self isBigEndian |
19349 | 1455 |
|
1456 |
"Created: / 5.3.1998 / 14:44:00 / stefan" |
|
1457 |
"Modified: / 5.3.1998 / 15:02:32 / stefan" |
|
1458 |
! |
|
1459 |
||
1460 |
unsignedLongLongAt:index put:anInteger bigEndian:msb |
|
1461 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1462 |
The index is a smalltalk index (i.e. 1-based). |
|
1463 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1464 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
1465 |
||
1466 |
^ self unsignedInt64At:index put:anInteger MSB:msb |
|
1467 |
||
1468 |
" |
|
1469 |
|b| |
|
1470 |
b := ByteArray new:8. |
|
1471 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
1472 |
b inspect |
|
1473 |
" |
|
1474 |
||
1475 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
1476 |
! |
|
1477 |
||
1478 |
unsignedShortAt:index |
|
1479 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1480 |
The index is a smalltalk index (i.e. 1-based). |
|
1481 |
The value is retrieved in the machines natural byte order |
|
1482 |
Subclasses may redefine this for better performance. |
|
1483 |
This is the ST80 equivalent of #wordAt:" |
|
1484 |
||
1485 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1486 |
^ self unsignedInt16At:index MSB:self isBigEndian |
19349 | 1487 |
|
1488 |
"Created: / 5.3.1998 / 11:38:25 / stefan" |
|
1489 |
"Modified: / 5.3.1998 / 14:59:25 / stefan" |
|
1490 |
! |
|
1491 |
||
1492 |
unsignedShortAt:index bigEndian:msb |
|
1493 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1494 |
The index is a smalltalk index (i.e. 1-based). |
|
1495 |
The value is retrieved MSB-first (high 8 bits at lower index) if msb is true; |
|
1496 |
LSB-first (i.e. low 8-bits at lower byte index) if its false)" |
|
1497 |
||
1498 |
^ self unsignedInt16At:index MSB:msb |
|
1499 |
||
1500 |
"Modified: / 21.1.1998 / 17:46:07 / cg" |
|
1501 |
"Created: / 5.3.1998 / 11:49:29 / stefan" |
|
1502 |
! |
|
1503 |
||
1504 |
unsignedShortAt:index put:value |
|
1505 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1506 |
The index is a smalltalk index (i.e. 1-based). |
|
1507 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1508 |
The value is stored in the machines natural byteorder." |
|
1509 |
||
1510 |
^ self unsignedInt16At:index put:value |
|
1511 |
||
1512 |
" |
|
1513 |
|b| |
|
1514 |
b := ByteArray new:4. |
|
1515 |
b unsignedShortAt:1 put:16r0102. |
|
1516 |
b unsignedShortAt:3 put:16r0304. |
|
1517 |
b inspect |
|
1518 |
" |
|
1519 |
||
1520 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
1521 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
1522 |
! |
|
1523 |
||
1524 |
unsignedShortAt:index put:value bigEndian:msb |
|
1525 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1526 |
The index is a smalltalk index (i.e. 1-based). |
|
1527 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1528 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
|
1529 |
lower index) if msb is false, MSB-first otherwise" |
|
1530 |
||
1531 |
^ self unsignedInt16At:index put:value MSB:msb |
|
1532 |
||
1533 |
" |
|
1534 |
|b| |
|
1535 |
b := ByteArray new:8. |
|
1536 |
b unsignedShortAt:1 put:16r0102 bigEndian:false. |
|
1537 |
b unsignedShortAt:3 put:16r0304 bigEndian:false. |
|
1538 |
b unsignedShortAt:5 put:16r0102 bigEndian:true. |
|
1539 |
b unsignedShortAt:7 put:16r0304 bigEndian:true. |
|
1540 |
b inspect |
|
1541 |
" |
|
1542 |
||
1543 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
1544 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
1545 |
! |
|
1546 |
||
1547 |
wordAt:index |
|
1548 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1549 |
The index is a smalltalk index (i.e. 1-based). |
|
1550 |
The value is retrieved in the machines natural byte order |
|
1551 |
Subclasses may redefine this for better performance." |
|
1552 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1553 |
^ self unsignedInt16At:index MSB:self isBigEndian |
19349 | 1554 |
|
1555 |
"Modified: / 5.3.1998 / 14:59:51 / stefan" |
|
1556 |
! |
|
1557 |
||
1558 |
wordAt:index MSB:msb |
|
1559 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1560 |
The index is a smalltalk index (i.e. 1-based). |
|
1561 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
|
1562 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1563 |
Notice: |
19349 | 1564 |
the index is a byte index; thus, this allows for unaligned access to |
1565 |
words on any boundary. |
|
1566 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)" |
|
1567 |
||
1568 |
^ self unsignedInt16At:index MSB:msb |
|
1569 |
! |
|
1570 |
||
1571 |
wordAt:index put:value |
|
1572 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1573 |
The index is a smalltalk index (i.e. 1-based). |
|
1574 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1575 |
The value is stored in the machines natural byteorder. |
|
1576 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
|
1577 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1578 |
^ self unsignedInt16At:index put:value MSB:self isBigEndian |
19349 | 1579 |
|
1580 |
" |
|
1581 |
|b| |
|
1582 |
b := ByteArray new:4. |
|
1583 |
b wordAt:1 put:16r0102. |
|
1584 |
b wordAt:3 put:16r0304. |
|
1585 |
b inspect |
|
1586 |
" |
|
1587 |
||
1588 |
"Modified: / 5.3.1998 / 15:00:03 / stefan" |
|
1589 |
! |
|
1590 |
||
1591 |
wordAt:index put:value MSB:msb |
|
1592 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1593 |
The index is a smalltalk index (i.e. 1-based). |
|
1594 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1595 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
|
1596 |
lower index) if msb is false, MSB-first otherwise. |
|
1597 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
|
1598 |
||
1599 |
^ self unsignedInt16At:index put:value MSB:msb |
|
1600 |
||
1601 |
" |
|
1602 |
b := ByteArray new:8. |
|
1603 |
b wordAt:1 put:16r0102 MSB:false. |
|
1604 |
b wordAt:3 put:16r0304 MSB:false. |
|
1605 |
b wordAt:5 put:16r0102 MSB:true. |
|
1606 |
b wordAt:7 put:16r0304 MSB:true. |
|
1607 |
b inspect |
|
1608 |
" |
|
1609 |
||
1610 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
1611 |
! |
|
1612 |
||
1613 |
wordAtWordIndex:int16Index |
|
1614 |
"return the unsigned short (uint16) at index, anInteger. |
|
1615 |
Fetching in the machines natural byte order. |
|
1616 |
Indices are 1-based and scaled as appropriate to allow |
|
1617 |
accessing the memory as an array of word entries. |
|
1618 |
(i.e. indices are 1, 2, ...)" |
|
1619 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1620 |
^ self unsignedInt16At:int16Index MSB:self isBigEndian |
19349 | 1621 |
|
1622 |
"Created: / 21.1.1998 / 17:48:26 / cg" |
|
1623 |
"Modified: / 5.3.1998 / 15:00:16 / stefan" |
|
1624 |
! |
|
1625 |
||
1626 |
wordAtWordIndex:int16Index MSB:msb |
|
1627 |
"return the unsigned short (uint16) at index, anInteger. |
|
1628 |
Fetching is MSB if msb is true, LSB otherwise. |
|
1629 |
Indices are 1-based and scaled as appropriate to allow |
|
1630 |
accessing the memory as an array of word entries. |
|
1631 |
(i.e. indices are 1, 2, ...)" |
|
1632 |
||
1633 |
^ self unsignedInt16At:((int16Index - 1) * 2 + 1) MSB:msb |
|
1634 |
||
1635 |
"Created: / 21.1.1998 / 17:48:30 / cg" |
|
1636 |
! |
|
1637 |
||
1638 |
wordAtWordIndex:int16Index put:anInteger |
|
1639 |
"set the unsigned short (uint16) at index, anInteger. |
|
1640 |
Storing in the machine's natural byte order. |
|
1641 |
Indices are 1-based and scaled as appropriate to allow |
|
1642 |
accessing the memory as an array of word entries. |
|
1643 |
(i.e. indices are 1, 2, ...)" |
|
1644 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1645 |
^ self unsignedInt16At:int16Index put:anInteger MSB:self isBigEndian |
19349 | 1646 |
|
1647 |
"Created: / 21.1.1998 / 17:48:34 / cg" |
|
1648 |
"Modified: / 5.3.1998 / 15:00:27 / stefan" |
|
1649 |
! |
|
1650 |
||
1651 |
wordAtWordIndex:int16Index put:anInteger MSB:msb |
|
1652 |
"set the short at index, anInteger. |
|
1653 |
Storing is MSB if msb is true, LSB otherwise. |
|
1654 |
Indices are 1-based and scaled as appropriate to allow |
|
1655 |
accessing the memory as an array of word entries. |
|
1656 |
(i.e. indices are 1, 2, ...)" |
|
1657 |
||
1658 |
^ self unsignedInt16At:((int16Index - 1) * 2 + 1) put:anInteger MSB:msb |
|
1659 |
||
1660 |
"Created: / 21.1.1998 / 17:48:38 / cg" |
|
1661 |
! ! |
|
1662 |
||
1663 |
!UninterpretedBytes methodsFor:'Compatibility-Squeak'! |
|
1664 |
||
1665 |
copyFromByteArray:aByteArray |
|
1666 |
"copy as much as possible from aByteArray" |
|
1667 |
||
1668 |
self replaceBytesFrom:1 to:(self size min:aByteArray size) with:aByteArray startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
1669 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
1670 |
|
9185 | 1671 |
!UninterpretedBytes methodsFor:'Compatibility-V''Age'! |
1672 |
||
1673 |
uint32At:zeroBasedIndex |
|
1674 |
"return the 4-bytes starting at index as (unsigned) Integer. |
|
19415 | 1675 |
WARNING: The index is a C index (i.e. 0-based). |
19301 | 1676 |
The value is retrieved in the machine's natural byte order. |
19415 | 1677 |
Similar to unsignedInt32At:, except for the index base" |
1678 |
||
1679 |
^ self unsignedInt32At:zeroBasedIndex+1 |
|
9185 | 1680 |
|
1681 |
" |
|
1682 |
|b| |
|
1683 |
||
1684 |
b := ByteArray withAll:#(0 0 0 0). |
|
1685 |
b uint32At:0 put:16r12345678. |
|
1686 |
b uint32At:0. |
|
1687 |
b |
|
1688 |
" |
|
1689 |
! |
|
1690 |
||
1691 |
uint32At:zeroBasedIndex put:anInteger |
|
1692 |
"set the 4-bytes starting at index to the value given by (unsigned) Integer. |
|
19415 | 1693 |
WARNING: The index is a C index (i.e. 0-based). |
1694 |
The value is stored in the machine's natural byte order. |
|
1695 |
Similar to unsignedInt32At:put:, except for the index base" |
|
1696 |
||
1697 |
^ self unsignedInt32At:zeroBasedIndex+1 put:anInteger |
|
9185 | 1698 |
|
1699 |
" |
|
1700 |
|b| |
|
1701 |
||
1702 |
b := ByteArray withAll:#(0 0 0 0). |
|
1703 |
b uint32At:0 put:16r12345678. |
|
1704 |
b |
|
1705 |
" |
|
1706 |
! ! |
|
1707 |
||
16796 | 1708 |
!UninterpretedBytes methodsFor:'accessing-arbitrary-long ints'! |
1709 |
||
19349 | 1710 |
nativeIntAt:index |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1711 |
"return the 4- or 8-bytes (depending on the native integer/pointer size) |
19349 | 1712 |
starting at index as a signed Integer. |
1713 |
The index is a smalltalk index (i.e. 1-based). |
|
1714 |
The value is retrieved in the machines natural byte order, |
|
1715 |
therefore, this should only be used for byte-data which is |
|
1716 |
only used inside this machine." |
|
1717 |
||
1718 |
|w| |
|
1719 |
||
1720 |
%{ |
|
1721 |
/* |
|
1722 |
* handle the most common cases fast ... |
|
1723 |
*/ |
|
1724 |
if (__isSmallInteger(index)) { |
|
1725 |
unsigned char *cp; |
|
1726 |
INT sz; |
|
1727 |
||
1728 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1729 |
if (cp) { |
|
1730 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1731 |
||
1732 |
if ((idx+(sizeof(INT)-1)) < sz) { |
|
1733 |
cp += idx; |
|
1734 |
#if defined(__i386__) |
|
1735 |
/* |
|
20816 | 1736 |
* aligned or not, we don't care (i386 can do both) |
19349 | 1737 |
*/ |
1738 |
{ |
|
1739 |
INT iVal = ((INT *)cp)[0]; |
|
1740 |
||
1741 |
RETURN (__MKINT(iVal)); |
|
1742 |
} |
|
1743 |
#else |
|
1744 |
/* |
|
1745 |
* aligned |
|
1746 |
*/ |
|
1747 |
if (((INT)cp & (sizeof(INT)-1)) == 0) { |
|
1748 |
INT iVal = ((INT *)cp)[0]; |
|
1749 |
||
1750 |
RETURN (__MKINT(iVal)); |
|
1751 |
} |
|
1752 |
#endif |
|
1753 |
} |
|
1754 |
} |
|
1755 |
} |
|
1756 |
%}. |
|
19402 | 1757 |
SmallInteger maxBytes == 8 ifTrue:[ |
19349 | 1758 |
^ self signedInt64At:index |
1759 |
]. |
|
1760 |
^ self signedInt32At:index |
|
1761 |
||
1762 |
" |
|
1763 |
|b| |
|
1764 |
b := ByteArray new:8. |
|
1765 |
b nativeIntAt:1 put:SmallInteger maxVal. |
|
1766 |
b nativeIntAt:1 |
|
1767 |
" |
|
1768 |
! |
|
1769 |
||
1770 |
nativeIntAt:index put:value |
|
1771 |
"set the 4- or 8-bytes (depending on INT-/pointer size) starting at index from the signed Integer value. |
|
1772 |
The index is a smalltalk index (i.e. 1-based). |
|
1773 |
The value is stored in the machine's natural byte order." |
|
1774 |
||
1775 |
%{ /* NOCONTEXT */ |
|
1776 |
/* |
|
1777 |
* handle the most common cases fast ... |
|
1778 |
*/ |
|
1779 |
if (__isSmallInteger(index)) { |
|
1780 |
unsigned char *cp; |
|
1781 |
INT sz; |
|
1782 |
||
1783 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1784 |
if (cp) { |
|
1785 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1786 |
||
1787 |
if ((idx+(sizeof(INT)-1)) < sz) { |
|
1788 |
cp += idx; |
|
1789 |
/* |
|
1790 |
* aligned |
|
1791 |
*/ |
|
1792 |
if (((INT)cp & (sizeof(INT)-1)) == 0) { |
|
1793 |
INT __v; |
|
1794 |
||
1795 |
if (__isSmallInteger(value)) { |
|
1796 |
// how about a range check? |
|
1797 |
((INT *)cp)[0] = (INT)(__intVal(value)); |
|
1798 |
RETURN (value); |
|
1799 |
} |
|
1800 |
if ((__v = __signedLongIntVal(value)) != 0) { |
|
1801 |
// how about a range check? |
|
1802 |
((INT *)cp)[0] = (INT)(__v); |
|
1803 |
RETURN (value); |
|
1804 |
} |
|
1805 |
} |
|
1806 |
} |
|
1807 |
} |
|
1808 |
} |
|
1809 |
%}. |
|
19402 | 1810 |
SmallInteger maxBytes == 8 ifTrue:[ |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1811 |
^ self signedInt64At:index put:value MSB:self isBigEndian |
19349 | 1812 |
]. |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1813 |
^ self signedInt32At:index put:value MSB:self isBigEndian |
19349 | 1814 |
|
1815 |
" |
|
1816 |
|b| |
|
1817 |
b := ByteArray new:8. |
|
1818 |
b nativeIntAt:1 put:SmallInteger maxVal. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1819 |
(b nativeIntAt:1) |
19349 | 1820 |
" |
1821 |
! |
|
1822 |
||
19402 | 1823 |
signedIntegerAt:index length:len bigEndian:bigEndian |
19197 | 1824 |
"return the n-byte signed integer starting at index. |
1825 |
With n=1, this returns the single signed byte's value, |
|
1826 |
n=2, a signed short, n=4 a signed int etc. |
|
1827 |
Useful to extract arbitrary long integers" |
|
1828 |
||
19402 | 1829 |
|val highByte |
1830 |
iIndex "{ Class:SmallInteger }" |
|
1831 |
last "{ Class:SmallInteger }"| |
|
1832 |
||
1833 |
iIndex := index. |
|
1834 |
last := iIndex + len - 1. |
|
19197 | 1835 |
|
1836 |
val := 0. |
|
1837 |
bigEndian ifTrue:[ |
|
19402 | 1838 |
highByte := self at:iIndex. |
1839 |
iIndex to:last do:[:i | |
|
19351 | 1840 |
val := (val<<8) + (self byteAt:i) |
19197 | 1841 |
] |
1842 |
] ifFalse:[ |
|
19402 | 1843 |
highByte := self at:last. |
1844 |
last to:iIndex by:-1 do:[:i | |
|
19351 | 1845 |
val := (val<<8) + (self byteAt:i) |
19197 | 1846 |
] |
1847 |
]. |
|
1848 |
(highByte bitTest:16r80) ifTrue:[ |
|
19402 | 1849 |
^ val - (1 bitShift:(len*8)) |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1850 |
]. |
19197 | 1851 |
^ val |
1852 |
||
1853 |
" |
|
1854 |
|b| |
|
1855 |
b := #[ 16r01 16rFF 16r00 16r04 16r05 ]. |
|
1856 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> 255 (00FF) '. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1857 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> -256 (FF00) '. |
19197 | 1858 |
|
1859 |
b := #[ 16r01 16r00 16rFF 16r04 16r05 ]. |
|
1860 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> -256 (FF00) '. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1861 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> 255 (00FF) '. |
19197 | 1862 |
|
1863 |
b := #[ 16r01 16r7F 16r00 16r04 16r05 ]. |
|
1864 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> 127 (007F) '. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1865 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> 32512 (7F00) '. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1866 |
" |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1867 |
|
19197 | 1868 |
" |
1869 |
|b| |
|
1870 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ]. |
|
1871 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
1872 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
1873 |
||
1874 |
b := #[ 16r01 16r82 16r03 16r04 16r05 ]. |
|
1875 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
1876 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
1877 |
||
1878 |
b := #[ 16r01 16r82 16r03 16r04 16r85 ]. |
|
1879 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
1880 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
1881 |
" |
|
1882 |
! |
|
1883 |
||
19402 | 1884 |
unsignedIntegerAt:index length:len bigEndian:bigEndian |
16796 | 1885 |
"return the n-byte unsigned integer starting at index. |
1886 |
With n=1, this returns the single byte's value, |
|
1887 |
n=2, an unsigned short, n=4 an unsigned int etc. |
|
1888 |
Useful to extract arbitrary long integers" |
|
1889 |
||
19402 | 1890 |
|val |
1891 |
iIndex "{ Class:SmallInteger }" |
|
1892 |
last "{ Class:SmallInteger }"| |
|
1893 |
||
1894 |
iIndex := index. |
|
1895 |
last := iIndex + len - 1. |
|
16796 | 1896 |
|
1897 |
val := 0. |
|
18346 | 1898 |
bigEndian ifTrue:[ |
19402 | 1899 |
iIndex to:last do:[:i | |
19351 | 1900 |
val := (val<<8) + (self byteAt:i) |
1901 |
] |
|
18346 | 1902 |
] ifFalse:[ |
19402 | 1903 |
last to:iIndex by:-1 do:[:i | |
19351 | 1904 |
val := (val<<8) + (self byteAt:i) |
1905 |
] |
|
16796 | 1906 |
]. |
1907 |
^ val |
|
1908 |
||
1909 |
" |
|
1910 |
|b| |
|
1911 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ]. |
|
18346 | 1912 |
(b unsignedIntegerAt:2 length:4 bigEndian:false). |
1913 |
(b unsignedIntegerAt:2 length:4 bigEndian:true). |
|
16796 | 1914 |
" |
19301 | 1915 |
! |
1916 |
||
19402 | 1917 |
unsignedIntegerAt:index put:newValue length:len bigEndian:bigEndian |
19301 | 1918 |
"store the n-byte unsigned integer starting at index. |
1919 |
With n=1, this stores a single byte's value, |
|
1920 |
n=2, an unsigned short, n=4 an unsigned int etc. |
|
1921 |
Useful to replace arbitrary long integers" |
|
1922 |
||
19402 | 1923 |
|val |
1924 |
iIndex "{ Class:SmallInteger }" |
|
1925 |
last "{ Class:SmallInteger }"| |
|
1926 |
||
1927 |
iIndex := index. |
|
1928 |
last := iIndex + len - 1. |
|
19301 | 1929 |
|
1930 |
val := newValue. |
|
1931 |
bigEndian ifTrue:[ |
|
19402 | 1932 |
iIndex to:last do:[:i | |
19351 | 1933 |
self byteAt:i put:(val bitAnd:16rFF). |
19301 | 1934 |
val := val bitShift:-8. |
1935 |
] |
|
1936 |
] ifFalse:[ |
|
19402 | 1937 |
last to:iIndex by:-1 do:[:i | |
19351 | 1938 |
self byteAt:i put:(val bitAnd:16rFF). |
19301 | 1939 |
val := val bitShift:-8. |
1940 |
] |
|
1941 |
]. |
|
1942 |
||
1943 |
" |
|
1944 |
|b| |
|
1945 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ] copy. |
|
1946 |
(b unsignedIntegerAt:2 put:16r11223344 length:3 bigEndian:false). b. |
|
1947 |
(b unsignedIntegerAt:2 put:16r11223344 length:3 bigEndian:true). b. |
|
1948 |
" |
|
16796 | 1949 |
! ! |
1950 |
||
3459 | 1951 |
!UninterpretedBytes methodsFor:'accessing-bytes'! |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1952 |
|
4422 | 1953 |
bcdByteAt:index |
13724 | 1954 |
"return the bcd-value for a byte at index in the range 0..99. |
1955 |
BCD treats nibbles (4-bit) as an encoded decimal number's digits |
|
1956 |
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)" |
|
4422 | 1957 |
|
4425 | 1958 |
^ (self byteAt:index) decodeFromBCD |
4422 | 1959 |
|
1960 |
" |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1961 |
#[ 16r55 ] bcdByteAt:1 |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
1962 |
#[ 16r99 ] bcdByteAt:1 |
19352 | 1963 |
#[ 16rAA ] bcdByteAt:1 |
4422 | 1964 |
" |
13724 | 1965 |
|
1966 |
"Modified (comment): / 26-09-2011 / 11:57:33 / cg" |
|
4422 | 1967 |
! |
1968 |
||
1969 |
bcdByteAt:index put:aNumber |
|
13724 | 1970 |
"set the byte at index as bcd-value in the range 0..99. |
1971 |
BCD treats nibbles (4-bit) as an encoded decimal number's digits |
|
1972 |
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)" |
|
4422 | 1973 |
|
1974 |
(aNumber between:0 and:99) ifFalse:[ |
|
19368 | 1975 |
self error:'invalid value for BCD encoding' |
4422 | 1976 |
]. |
4425 | 1977 |
^ self byteAt:index put:aNumber encodeAsBCD |
4422 | 1978 |
|
1979 |
" |
|
13575 | 1980 |
(((ByteArray new:1) bcdByteAt:1 put:55; yourself) at:1) hexPrintString |
1981 |
(((ByteArray new:1) bcdByteAt:1 put:99; yourself) at:1) hexPrintString |
|
1982 |
(((ByteArray new:1) bcdByteAt:1 put:100; yourself) at:1) hexPrintString |
|
1983 |
(((ByteArray new:1) bcdByteAt:1 put:-1; yourself) at:1) hexPrintString |
|
4422 | 1984 |
" |
13724 | 1985 |
|
1986 |
"Modified (comment): / 26-09-2011 / 11:57:36 / cg" |
|
4422 | 1987 |
! |
1988 |
||
19351 | 1989 |
byteAt:byteIndex |
1990 |
"return the byte at byteIndex as an unsigned 8 bit value in the range 0..255. |
|
1991 |
The index is a smalltalk index (i.e. 1-based)." |
|
1992 |
||
1993 |
%{ |
|
1994 |
if (__isSmallInteger(byteIndex)) { |
|
1995 |
unsigned char *cp; |
|
1996 |
INT sz; |
|
1997 |
||
1998 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1999 |
if (cp) { |
|
2000 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
2001 |
||
2002 |
if (idx < sz) { |
|
19830 | 2003 |
unsigned char ch = cp[idx] & 0xFF; |
19351 | 2004 |
RETURN (__mkSmallInteger( ch )); |
2005 |
} |
|
2006 |
} |
|
2007 |
} |
|
2008 |
%}. |
|
2009 |
||
2010 |
^ self at:byteIndex |
|
3459 | 2011 |
|
2012 |
" |
|
2013 |
|b| |
|
19351 | 2014 |
b := ByteArray new:3. |
3459 | 2015 |
b at:1 put:16rFF. |
2016 |
b at:2 put:16r7F. |
|
19351 | 2017 |
b at:3 put:16r80. |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2018 |
b byteAt:1. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2019 |
b byteAt:2. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2020 |
b byteAt:3. |
19351 | 2021 |
" |
2022 |
||
2023 |
"Modified: / 01-07-1996 / 21:13:53 / cg" |
|
2024 |
"Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
|
2025 |
! |
|
2026 |
||
2027 |
byteAt:byteIndex put:anInteger |
|
2028 |
"set the byte at byteIndex as an unsigned 8 bit value in the range 0..255. |
|
2029 |
The index is a smalltalk index (i.e. 1-based)." |
|
2030 |
||
2031 |
%{ |
|
2032 |
if (__isSmallInteger(byteIndex) && __isSmallInteger(anInteger)) { |
|
2033 |
unsigned char *cp; |
|
2034 |
INT sz; |
|
2035 |
INT val = __intVal(anInteger); |
|
2036 |
||
2037 |
if ( ((unsigned INT)val) <= 0xFF ) { |
|
2038 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2039 |
if (cp) { |
|
2040 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
2041 |
||
2042 |
if (idx < sz) { |
|
2043 |
cp[idx] = val & 0xFF; |
|
2044 |
RETURN (anInteger); |
|
2045 |
} |
|
2046 |
} |
|
2047 |
} |
|
2048 |
} |
|
2049 |
%}. |
|
2050 |
||
2051 |
^ self at:byteIndex put:anInteger |
|
2052 |
||
2053 |
" |
|
2054 |
|b| |
|
2055 |
b := ByteArray new:3. |
|
2056 |
b byteAt:1 put:16rFF. |
|
2057 |
b byteAt:2 put:16r7F. |
|
2058 |
b byteAt:3 put:16r80. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2059 |
b signedByteAt:1. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2060 |
b signedByteAt:2. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2061 |
b signedByteAt:3. |
19351 | 2062 |
" |
2063 |
! |
|
2064 |
||
2065 |
signedByteAt:byteIndex |
|
2066 |
"return the byte at byteIndex as a signed 8 bit value in the range -128..+127. |
|
2067 |
The index is a smalltalk index (i.e. 1-based). |
|
2068 |
This may be worth a primitive." |
|
2069 |
||
2070 |
%{ |
|
2071 |
/* |
|
2072 |
* handle the most common cases fast ... |
|
2073 |
*/ |
|
2074 |
if (__isSmallInteger(byteIndex)) { |
|
2075 |
unsigned char *cp; |
|
2076 |
INT sz; |
|
2077 |
||
2078 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2079 |
if (cp) { |
|
2080 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
2081 |
char ch; |
|
2082 |
||
2083 |
if (idx < sz) { |
|
2084 |
cp += idx; |
|
2085 |
ch = cp[0]; |
|
2086 |
# ifndef HAS_SIGNED_CHAR |
|
2087 |
if ( (unsigned int)ch >= 0x80 ) { |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2088 |
ch = ch - 0x100; |
19351 | 2089 |
} |
2090 |
#endif |
|
2091 |
RETURN (__mkSmallInteger( ch )); |
|
2092 |
} |
|
2093 |
} |
|
2094 |
} |
|
2095 |
%}. |
|
2096 |
||
2097 |
^ (self byteAt:byteIndex) signExtendedByteValue |
|
2098 |
||
2099 |
" |
|
2100 |
|b| |
|
2101 |
b := ByteArray new:3. |
|
2102 |
b at:1 put:16rFF. |
|
2103 |
b at:2 put:16r7F. |
|
2104 |
b at:3 put:16r80. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2105 |
b byteAt:1. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2106 |
b byteAt:2. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2107 |
b byteAt:3. |
3459 | 2108 |
" |
2109 |
||
13724 | 2110 |
"Modified: / 01-07-1996 / 21:13:53 / cg" |
2111 |
"Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
|
3459 | 2112 |
! |
2113 |
||
2114 |
signedByteAt:index put:aSignedByteValue |
|
13724 | 2115 |
"return the byte at index as a signed 8 bit value in the range -128..+127. |
3459 | 2116 |
The index is a smalltalk index (i.e. 1-based). |
2117 |
Return the signedByteValue argument. |
|
2118 |
This may be worth a primitive." |
|
2119 |
||
2120 |
|b "{ Class: SmallInteger }"| |
|
2121 |
||
2122 |
aSignedByteValue >= 0 ifTrue:[ |
|
19351 | 2123 |
b := aSignedByteValue |
3459 | 2124 |
] ifFalse:[ |
19351 | 2125 |
b := 16r100 + aSignedByteValue |
3459 | 2126 |
]. |
19351 | 2127 |
self byteAt:index put:b. |
3459 | 2128 |
^ aSignedByteValue |
2129 |
||
2130 |
" |
|
2131 |
|b| |
|
2132 |
b := ByteArray new:2. |
|
2133 |
b signedByteAt:1 put:-1. |
|
13575 | 2134 |
b at:1 |
3459 | 2135 |
" |
2136 |
||
13724 | 2137 |
"Modified: / 01-07-1996 / 21:12:37 / cg" |
2138 |
"Modified (comment): / 26-09-2011 / 11:57:18 / cg" |
|
3459 | 2139 |
! ! |
2140 |
||
2141 |
!UninterpretedBytes methodsFor:'accessing-floats & doubles'! |
|
2142 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2143 |
doubleAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2144 |
"return the 8-bytes starting at index as a Float. |
3433 | 2145 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2146 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
19415 | 2147 |
Notice also, that the bytes are expected to be in this machine's |
19629 | 2148 |
float representation and byte order - if the bytearray originated from another |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2149 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2150 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2151 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2152 |
|
3433 | 2153 |
%{ |
2154 |
/* |
|
2155 |
* handle the most common cases fast ... |
|
2156 |
*/ |
|
2157 |
if (__isSmallInteger(index)) { |
|
19351 | 2158 |
unsigned char *cp; |
2159 |
INT sz; |
|
2160 |
||
2161 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2162 |
if (cp) { |
|
19415 | 2163 |
INT idx = __intVal(index) - 1; |
2164 |
||
2165 |
if ((idx >= 0) && ((idx+(sizeof(double)-1)) < sz)) { |
|
19351 | 2166 |
cp += idx; |
2167 |
/* |
|
2168 |
* aligned |
|
2169 |
*/ |
|
2170 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
2171 |
double dVal = ((double *)cp)[0]; |
|
2172 |
OBJ f; |
|
2173 |
||
2174 |
__qMKFLOAT(f, dVal); |
|
2175 |
RETURN (f); |
|
2176 |
} |
|
2177 |
} |
|
2178 |
} |
|
3433 | 2179 |
} |
2180 |
%}. |
|
2181 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2182 |
newFloat := Float basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2183 |
1 to:8 do:[:destIndex| |
19351 | 2184 |
newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex)) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2185 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2186 |
^ newFloat. |
3433 | 2187 |
|
2188 |
" |
|
2189 |
|b| |
|
2190 |
||
2191 |
b := ByteArray new:20. |
|
2192 |
b doubleAt:1 put:(Float pi). |
|
2193 |
Transcript showCR:b. |
|
2194 |
Transcript showCR:(b doubleAt:1) |
|
2195 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2196 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2197 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2198 |
doubleAt:index MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2199 |
"return the 8-bytes starting at index as a Float. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2200 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2201 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2202 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2203 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2204 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2205 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2206 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2207 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2208 |
msb == self isBigEndian ifTrue:[ |
19351 | 2209 |
^ self doubleAt:index. |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2210 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2211 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2212 |
newFloat := Float basicNew. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2213 |
1 to:8 do:[:destIndex| |
19351 | 2214 |
newFloat basicAt:(9-destIndex) put:(self byteAt:(index - 1 + destIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2215 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2216 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2217 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2218 |
"Created: / 15.5.1998 / 17:21:45 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2219 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2220 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2221 |
doubleAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2222 |
"store the value of the argument, aFloat into the receiver |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2223 |
starting at index. |
3433 | 2224 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2225 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
19415 | 2226 |
Notice also, that the bytes are expected to be in this machine's |
19629 | 2227 |
float representation and byte order - if the bytearray originated from another |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2228 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2229 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2230 |
|flt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2231 |
|
3433 | 2232 |
%{ |
2233 |
/* |
|
2234 |
* handle the most common cases fast ... |
|
2235 |
*/ |
|
16320 | 2236 |
if (__isSmallInteger(index)) { |
19351 | 2237 |
unsigned char *cp; |
2238 |
INT sz; |
|
2239 |
||
2240 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2241 |
if (cp) { |
|
19415 | 2242 |
INT idx = __intVal(index) - 1; |
2243 |
||
2244 |
if ((idx >= 0) && ((idx+(sizeof(double)-1)) < sz)) { |
|
19351 | 2245 |
cp += idx; |
2246 |
/* |
|
2247 |
* aligned |
|
2248 |
*/ |
|
2249 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
2250 |
if (__isFloat(aFloat)) { |
|
2251 |
((double *)cp)[0] = __floatVal(aFloat); |
|
2252 |
RETURN (aFloat); |
|
2253 |
} |
|
2254 |
if (__isShortFloat(aFloat)) { |
|
2255 |
((double *)cp)[0] = (double)(__shortFloatVal(aFloat)); |
|
2256 |
RETURN (aFloat); |
|
2257 |
} |
|
2258 |
if (__isSmallInteger(aFloat)) { |
|
2259 |
((double *)cp)[0] = (double)(__intVal(aFloat)); |
|
2260 |
RETURN (aFloat); |
|
2261 |
} |
|
2262 |
} |
|
2263 |
} |
|
2264 |
} |
|
3433 | 2265 |
} |
2266 |
%}. |
|
2267 |
||
16320 | 2268 |
flt := aFloat asFloat. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2269 |
1 to:8 do:[:srcIndex| |
19351 | 2270 |
self byteAt:(index - 1 + srcIndex) put:(flt basicAt:srcIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2271 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2272 |
^ aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2273 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2274 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2275 |
doubleAt:index put:aFloat MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2276 |
"store the value of the argument, aFloat into the receiver |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2277 |
starting at index. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2278 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2279 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
19415 | 2280 |
Notice also, that the bytes are expected to be in this machine's |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2281 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2282 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2283 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2284 |
|flt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2285 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2286 |
msb == self isBigEndian ifTrue:[ |
19351 | 2287 |
^ self doubleAt:index put:aFloat. |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2288 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2289 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2290 |
flt := aFloat asFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2291 |
1 to:8 do:[:srcIndex| |
19351 | 2292 |
self byteAt:(index - 1 + srcIndex) put:(flt basicAt:(9-srcIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2293 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2294 |
^ aFloat |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2295 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2296 |
"Created: / 15.5.1998 / 17:22:27 / cg" |
3447 | 2297 |
"Modified: / 15.5.1998 / 17:26:29 / cg" |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2298 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2299 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2300 |
floatAt:index |
3434 | 2301 |
"return the 4-bytes starting at index as a ShortFloat. |
3433 | 2302 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2303 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80; |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2304 |
therefore this method reads a 4-byte float from the byteArray and returns |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2305 |
a float object which keeps an 8-byte double internally. |
19415 | 2306 |
Notice also, that the bytes are expected to be in this machine's |
19629 | 2307 |
float representation and byte order - if the bytearray originated from another |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2308 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2309 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2310 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2311 |
|
3434 | 2312 |
%{ |
2313 |
/* |
|
2314 |
* handle the most common cases fast ... |
|
2315 |
*/ |
|
2316 |
if (__isSmallInteger(index)) { |
|
19351 | 2317 |
unsigned char *cp; |
2318 |
INT sz; |
|
2319 |
||
2320 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2321 |
if (cp) { |
|
19415 | 2322 |
INT idx = __intVal(index) - 1; |
2323 |
||
2324 |
if ((idx >= 0) && ((idx+(sizeof(float)-1)) < sz)) { |
|
19351 | 2325 |
cp += idx; |
2326 |
/* |
|
2327 |
* aligned |
|
2328 |
*/ |
|
2329 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
2330 |
float fVal = ((float *)cp)[0]; |
|
2331 |
OBJ f; |
|
2332 |
||
2333 |
__qMKSFLOAT(f, fVal); |
|
2334 |
RETURN (f); |
|
2335 |
} |
|
2336 |
} |
|
2337 |
} |
|
3434 | 2338 |
} |
2339 |
%}. |
|
2340 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2341 |
newFloat := ShortFloat basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2342 |
1 to:4 do:[:destIndex| |
19351 | 2343 |
newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex)) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2344 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2345 |
^ newFloat. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2346 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2347 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2348 |
floatAt:index MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2349 |
"return the 4-bytes starting at index as a ShortFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2350 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2351 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80; |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2352 |
therefore this method reads a 4-byte float from the byteArray and returns |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2353 |
a float object which keeps an 8-byte double internally. |
19415 | 2354 |
Notice also, that the bytes are expected to be in this machine's |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2355 |
float representation and order - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2356 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2357 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2358 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2359 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2360 |
msb == self isBigEndian ifTrue:[ |
19351 | 2361 |
^ self floatAt:index |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2362 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2363 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2364 |
newFloat := ShortFloat basicNew. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2365 |
1 to:4 do:[:destIndex| |
19351 | 2366 |
newFloat basicAt:(5-destIndex) put:(self byteAt:(index - 1 + destIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2367 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2368 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2369 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2370 |
"Modified: / 15.5.1998 / 17:20:19 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2371 |
"Created: / 15.5.1998 / 17:20:35 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2372 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2373 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2374 |
floatAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2375 |
"store the 4 bytes of value of the argument, aFloat into the receiver |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2376 |
starting at index. |
3433 | 2377 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2378 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2379 |
Notice also, that the bytes are expected to be in this machines |
19629 | 2380 |
float representation and byte order - if the bytearray originated from another |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2381 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2382 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2383 |
|sflt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2384 |
|
3434 | 2385 |
%{ |
2386 |
/* |
|
2387 |
* handle the most common cases fast ... |
|
2388 |
*/ |
|
16320 | 2389 |
if (__isSmallInteger(index)) { |
19351 | 2390 |
unsigned char *cp; |
2391 |
INT sz; |
|
2392 |
||
2393 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2394 |
if (cp) { |
|
19415 | 2395 |
INT idx = __intVal(index) - 1; |
2396 |
||
2397 |
if ((idx >= 0) && ((idx+(sizeof(float)-1)) < sz)) { |
|
19351 | 2398 |
cp += idx; |
2399 |
/* |
|
2400 |
* aligned |
|
2401 |
*/ |
|
2402 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
2403 |
if (__isShortFloat(aFloat)) { |
|
2404 |
((float *)cp)[0] = __shortFloatVal(aFloat); |
|
2405 |
RETURN (self); |
|
2406 |
} |
|
2407 |
if (__isFloat(aFloat)) { |
|
2408 |
((float *)cp)[0] = (float)__floatVal(aFloat); |
|
2409 |
RETURN (self); |
|
2410 |
} |
|
2411 |
if (__isSmallInteger(aFloat)) { |
|
2412 |
((float *)cp)[0] = (float)__intVal(aFloat); |
|
2413 |
RETURN (self); |
|
2414 |
} |
|
2415 |
// bail out to smalltalk code |
|
2416 |
} |
|
2417 |
} |
|
2418 |
} |
|
3434 | 2419 |
} |
2420 |
%}. |
|
2421 |
||
16320 | 2422 |
sflt := aFloat asShortFloat. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2423 |
1 to:4 do:[:srcIndex| |
19351 | 2424 |
self byteAt:index - 1 + srcIndex put:(sflt basicAt:srcIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2425 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2426 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2427 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2428 |
floatAt:index put:aFloat MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2429 |
"store the 4 bytes of value of the argument, aFloat into the receiver |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2430 |
starting at index. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2431 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2432 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2433 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2434 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2435 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2436 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2437 |
|sflt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2438 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2439 |
msb == self isBigEndian ifTrue:[ |
19351 | 2440 |
self floatAt:index put:aFloat. |
2441 |
^ self. |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2442 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2443 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2444 |
sflt := aFloat asShortFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2445 |
1 to:4 do:[:srcIndex| |
19351 | 2446 |
self byteAt:(index - 1 + srcIndex) put:(sflt basicAt:(5-srcIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2447 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2448 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2449 |
"Created: / 15.5.1998 / 17:20:41 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2450 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2451 |
|
3323 | 2452 |
ieeeDoubleAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2453 |
"retrieve the 8 bytes starting at index as a float. |
3433 | 2454 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2455 |
The 8 bytes are assumed to be in IEEE floating point single precision |
19629 | 2456 |
number format in the native byte order." |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2457 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2458 |
" |
19415 | 2459 |
currently, we assume that the machine's native number format is already |
3323 | 2460 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2461 |
to an IBM 370 or old VAX etc. |
3323 | 2462 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2463 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2464 |
" |
9258 | 2465 |
Float isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2466 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2467 |
^ self doubleAt:index |
3323 | 2468 |
|
2469 |
"Created: / 5.3.1998 / 10:50:03 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2470 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2471 |
|
3323 | 2472 |
ieeeDoubleAt:index put:aFloat |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2473 |
"store the value of the argument, aFloat into the receiver |
3433 | 2474 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2475 |
starting at index. Storage is in IEEE floating point double precision format. |
19629 | 2476 |
(i.e. 8 bytes are stored in the native byte order)." |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2477 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2478 |
" |
19415 | 2479 |
currently, we assume that the machine's native number format is already |
3323 | 2480 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2481 |
to an IBM 370 or old VAX etc. |
3323 | 2482 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2483 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2484 |
" |
9258 | 2485 |
Float isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2486 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2487 |
^ self doubleAt:index put:aFloat |
3323 | 2488 |
|
2489 |
"Created: / 5.3.1998 / 10:50:26 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2490 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2491 |
|
3323 | 2492 |
ieeeFloatAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2493 |
"retrieve the 4 bytes starting at index as a float. |
3433 | 2494 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2495 |
The 4 bytes are assumed to be in IEEE floating point single precision |
19629 | 2496 |
number format in the native byte order." |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2497 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2498 |
" |
19415 | 2499 |
currently, we assume that the machine's native number format is already |
3323 | 2500 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2501 |
to an IBM 370 or old VAX etc. |
3323 | 2502 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2503 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2504 |
" |
9258 | 2505 |
ShortFloat isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2506 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2507 |
^ self floatAt:index |
3323 | 2508 |
|
2509 |
"Created: / 5.3.1998 / 10:50:45 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2510 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2511 |
|
3323 | 2512 |
ieeeFloatAt:index put:aFloat |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2513 |
"store the value of the argument, aFloat into the receiver |
13575 | 2514 |
starting at index, which is a smalltalk index (i.e. 1-based). |
3433 | 2515 |
Storage is in IEEE floating point single precision format. |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2516 |
(i.e. 4 bytes are stored in the native byte order). |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2517 |
Since ST/X floats are really doubles, |
19629 | 2518 |
the low- order 4 bytes of the precision are lost." |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2519 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2520 |
" |
19415 | 2521 |
currently, we assume that the machine's native number format is already |
3323 | 2522 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2523 |
to an IBM 370 or old VAX etc. |
3323 | 2524 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2525 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2526 |
" |
9258 | 2527 |
ShortFloat isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2528 |
|
16320 | 2529 |
self floatAt:index put:aFloat |
3323 | 2530 |
|
2531 |
"Created: / 5.3.1998 / 10:51:11 / stefan" |
|
3459 | 2532 |
! ! |
2533 |
||
13724 | 2534 |
!UninterpretedBytes methodsFor:'accessing-longlongs (64bit)'! |
3459 | 2535 |
|
19349 | 2536 |
signedInt64At:index |
3459 | 2537 |
"return the 8-bytes starting at index as a signed Integer. |
2538 |
The index is a smalltalk index (i.e. 1-based). |
|
2539 |
The value is retrieved in the machines natural byte order. |
|
2540 |
This may be worth a primitive." |
|
2541 |
||
2542 |
|w| |
|
2543 |
||
19629 | 2544 |
w := self unsignedInt64At:index MSB:(UninterpretedBytes isBigEndian). |
3459 | 2545 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
19349 | 2546 |
^ w - (16r10000000000000000) |
3459 | 2547 |
]. |
2548 |
^ w |
|
2549 |
||
2550 |
" |
|
2551 |
|b| |
|
2552 |
b := ByteArray new:4. |
|
19349 | 2553 |
b unsignedInt64At:1 put:16rFFFFFFFFFFFFFFFF. |
2554 |
(b signedInt64At:1) |
|
3459 | 2555 |
" |
2556 |
||
2557 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
2558 |
"Created: / 5.3.1998 / 14:40:05 / stefan" |
|
2559 |
"Modified: / 5.3.1998 / 14:58:32 / stefan" |
|
2560 |
! |
|
2561 |
||
19349 | 2562 |
signedInt64At:index MSB:msb |
3459 | 2563 |
"return the 8-bytes starting at index as a signed Integer. |
2564 |
The index is a smalltalk index (i.e. 1-based). |
|
2565 |
The value is retrieved in the given byte order. |
|
2566 |
This may be worth a primitive." |
|
2567 |
||
2568 |
|w| |
|
2569 |
||
19349 | 2570 |
w := self unsignedInt64At:index MSB:msb. |
3459 | 2571 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
19349 | 2572 |
^ w - (16r10000000000000000) |
3459 | 2573 |
]. |
2574 |
^ w |
|
2575 |
||
2576 |
" |
|
2577 |
|b| |
|
2578 |
b := ByteArray new:4. |
|
2579 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
13575 | 2580 |
(b longLongAt:1 msb:true) |
3459 | 2581 |
" |
2582 |
||
2583 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
2584 |
"Created: / 5.3.1998 / 14:40:54 / stefan" |
|
2585 |
"Modified: / 9.5.1998 / 01:10:59 / cg" |
|
2586 |
! |
|
2587 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2588 |
signedInt64At:byteIndex put:anInteger |
19349 | 2589 |
"store a signed longLong (64bit) integer. |
2590 |
The index is a smalltalk index (i.e. 1-based). |
|
2591 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
2592 |
||
19629 | 2593 |
^ self signedInt64At:byteIndex put:anInteger MSB:(UninterpretedBytes isBigEndian) |
19349 | 2594 |
! |
2595 |
||
2596 |
signedInt64At:byteIndex put:anInteger MSB:msb |
|
3459 | 2597 |
"store a signed longLong (64bit) integer. |
2598 |
The index is a smalltalk index (i.e. 1-based). |
|
2599 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
2600 |
||
7813 | 2601 |
|v| |
3459 | 2602 |
|
7813 | 2603 |
v := anInteger. |
2604 |
anInteger < 0 ifTrue:[ |
|
19349 | 2605 |
v := v + 16r10000000000000000 |
7813 | 2606 |
]. |
19349 | 2607 |
self unsignedInt64At:byteIndex put:v MSB:msb. |
2608 |
^ anInteger |
|
3459 | 2609 |
|
2610 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
2611 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
2612 |
! |
|
2613 |
||
19629 | 2614 |
signedInt64AtLSB:byteIndex |
2615 |
"return the 8-bytes starting at index as a signed 64bit Integer. |
|
2616 |
The index is a smalltalk index (i.e. 1-based). |
|
2617 |
The value is retrieved with least significant byte first" |
|
2618 |
||
2619 |
^ self signedInt64At:byteIndex MSB:false |
|
2620 |
! |
|
2621 |
||
2622 |
signedInt64AtLSB:byteIndex put:anInteger |
|
2623 |
"set the 8-bytes starting at index from the signed Integer anInteger. |
|
2624 |
The index is a smalltalk index (i.e. 1-based). |
|
2625 |
The integer is stored with least significant byte first." |
|
2626 |
||
2627 |
^ self signedInt64At:byteIndex put:anInteger MSB:false |
|
2628 |
! |
|
2629 |
||
2630 |
signedInt64AtMSB:byteIndex |
|
2631 |
"return the 8-bytes starting at index as a signed 64bit Integer. |
|
2632 |
The index is a smalltalk index (i.e. 1-based). |
|
2633 |
The value is retrieved with most significant byte first" |
|
2634 |
||
2635 |
^ self signedInt64At:byteIndex MSB:true |
|
2636 |
! |
|
2637 |
||
2638 |
signedInt64AtMSB:byteIndex put:anInteger |
|
2639 |
"set the 8-bytes starting at index from the signed Integer anInteger. |
|
2640 |
The index is a smalltalk index (i.e. 1-based). |
|
2641 |
The integer is stored with least significant byte first." |
|
2642 |
||
2643 |
^ self signedInt64At:byteIndex put:anInteger MSB:true |
|
2644 |
! |
|
2645 |
||
19349 | 2646 |
unsignedInt64At:byteIndex |
2647 |
"return the 8-bytes starting at index in the machine's native |
|
2648 |
byteorder as an unsigned integer. |
|
2649 |
The index is a smalltalk index (i.e. 1-based)" |
|
2650 |
||
19629 | 2651 |
^ self unsignedInt64At:byteIndex MSB:(UninterpretedBytes isBigEndian) |
19349 | 2652 |
|
2653 |
" |
|
2654 |
|b| |
|
2655 |
||
2656 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
2657 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
|
2658 |
" |
|
2659 |
||
2660 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
2661 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
2662 |
! |
|
2663 |
||
2664 |
unsignedInt64At:byteIndex MSB:msb |
|
2665 |
"return the 8-bytes starting at index as an unsigned integer. |
|
3459 | 2666 |
The index is a smalltalk index (i.e. 1-based). |
2667 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
2668 |
||
13575 | 2669 |
|l |
3459 | 2670 |
bIdx "{ Class: SmallInteger }" |
2671 |
delta "{ Class: SmallInteger }"| |
|
2672 |
||
2673 |
l := LargeInteger basicNew numberOfDigits:8. |
|
2674 |
msb ifTrue:[ |
|
19349 | 2675 |
bIdx := byteIndex + 7. |
2676 |
delta := -1 |
|
3459 | 2677 |
] ifFalse:[ |
19349 | 2678 |
bIdx := byteIndex. |
2679 |
delta := 1 |
|
3459 | 2680 |
]. |
2681 |
1 to:8 do:[:i | |
|
19351 | 2682 |
l digitAt:i put:(self byteAt:bIdx). |
19349 | 2683 |
bIdx := bIdx + delta |
3459 | 2684 |
]. |
2685 |
^ l compressed |
|
2686 |
||
2687 |
" |
|
2688 |
|b| |
|
2689 |
||
2690 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
13575 | 2691 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
3459 | 2692 |
" |
2693 |
||
2694 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
2695 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
2696 |
! |
|
2697 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2698 |
unsignedInt64At:byteIndex put:anInteger |
3459 | 2699 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
2700 |
The index is a smalltalk index (i.e. 1-based). |
|
2701 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
19349 | 2702 |
The value is stored in the machine's natural byteorder." |
2703 |
||
19629 | 2704 |
^ self unsignedInt64At:byteIndex put:anInteger MSB:(UninterpretedBytes isBigEndian) |
19349 | 2705 |
|
2706 |
" |
|
2707 |
|b| |
|
2708 |
b := ByteArray new:10. |
|
2709 |
b unsignedInt64At:1 put:16r0807060504030201 MSB:false. |
|
2710 |
b unsignedInt64At:1 put:16r0807060504030201 MSB:true. |
|
2711 |
b inspect |
|
2712 |
" |
|
2713 |
||
2714 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
3459 | 2715 |
! |
2716 |
||
19349 | 2717 |
unsignedInt64At:byteIndex put:anInteger MSB:msb |
3459 | 2718 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
2719 |
The index is a smalltalk index (i.e. 1-based). |
|
2720 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
2721 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
2722 |
||
2723 |
|bIdx "{ Class: SmallInteger }" |
|
2724 |
delta "{ Class: SmallInteger }"| |
|
2725 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2726 |
((anInteger < 0) |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2727 |
or:[anInteger class ~~ SmallInteger |
20595 | 2728 |
and:[anInteger > 16rFFFFFFFFFFFFFFFF]]) ifTrue:[ |
19349 | 2729 |
^ self elementBoundsError:anInteger |
3459 | 2730 |
]. |
2731 |
||
2732 |
msb ifTrue:[ |
|
19349 | 2733 |
bIdx := byteIndex + 7. |
2734 |
delta := -1 |
|
3459 | 2735 |
] ifFalse:[ |
19349 | 2736 |
bIdx := byteIndex. |
2737 |
delta := 1 |
|
3459 | 2738 |
]. |
2739 |
1 to:8 do:[:i | |
|
19351 | 2740 |
self byteAt:bIdx put:(anInteger digitAt:i). |
19349 | 2741 |
bIdx := bIdx + delta. |
3459 | 2742 |
]. |
2743 |
^ anInteger |
|
2744 |
||
2745 |
" |
|
2746 |
|b| |
|
2747 |
b := ByteArray new:8. |
|
2748 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
2749 |
b inspect |
|
2750 |
" |
|
2751 |
||
2752 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
19629 | 2753 |
! |
2754 |
||
2755 |
unsignedInt64AtLSB:byteIndex |
|
2756 |
"return the 8-bytes starting at index as an unsigned 64bit Integer. |
|
2757 |
The index is a smalltalk index (i.e. 1-based). |
|
2758 |
The value is retrieved with most significant byte first" |
|
2759 |
||
2760 |
^ self unsignedInt64At:byteIndex MSB:false |
|
2761 |
! |
|
2762 |
||
2763 |
unsignedInt64AtLSB:byteIndex put:anInteger |
|
2764 |
"set the 8-bytes starting at index from the unsigned Integer anInteger. |
|
2765 |
The index is a smalltalk index (i.e. 1-based). |
|
2766 |
The integer is stored with least significant byte first." |
|
2767 |
||
2768 |
^ self unsignedInt64At:byteIndex put:anInteger MSB:false |
|
2769 |
! |
|
2770 |
||
2771 |
unsignedInt64AtMSB:byteIndex |
|
2772 |
"return the 8-bytes starting at index as an unsigned 64bit Integer. |
|
2773 |
The index is a smalltalk index (i.e. 1-based). |
|
2774 |
The value is retrieved with most significant byte first" |
|
2775 |
||
2776 |
^ self unsignedInt64At:byteIndex MSB:true |
|
2777 |
! |
|
2778 |
||
2779 |
unsignedInt64AtMSB:byteIndex put:anInteger |
|
2780 |
"set the 8-bytes starting at index from the unsigned Integer anInteger. |
|
2781 |
The index is a smalltalk index (i.e. 1-based). |
|
2782 |
The integer is stored with least significant byte first." |
|
2783 |
||
2784 |
^ self unsignedInt64At:byteIndex put:anInteger MSB:true |
|
3459 | 2785 |
! ! |
2786 |
||
13724 | 2787 |
!UninterpretedBytes methodsFor:'accessing-longs (32bit)'! |
3459 | 2788 |
|
19349 | 2789 |
signedInt32At:byteIndex |
2790 |
"return the 4-bytes starting at byteIndex as a signed Integer. |
|
3433 | 2791 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 2792 |
The value is retrieved in the machine's natural byte order, |
2793 |
therefore, this should only be used for byte-data which is |
|
2794 |
only used inside this machine. |
|
19415 | 2795 |
To setup binary data packets which are to be sent to other machines, |
2796 |
or stored into a file, always use the corresponding xxx:MSB: method |
|
2797 |
and specify a definite byteOrder." |
|
19349 | 2798 |
|
2799 |
|w| |
|
2800 |
||
2801 |
%{ |
|
2802 |
/* |
|
2803 |
* handle the most common cases fast ... |
|
2804 |
*/ |
|
2805 |
if (__isSmallInteger(byteIndex)) { |
|
2806 |
unsigned char *cp; |
|
2807 |
INT sz; |
|
2808 |
||
2809 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2810 |
if (cp) { |
|
19415 | 2811 |
INT idx = __intVal(byteIndex) - 1; |
2812 |
||
2813 |
if ((idx >= 0) && ((idx+(4-1)) < sz)) { |
|
2814 |
int iVal; |
|
2815 |
||
19349 | 2816 |
cp += idx; |
2817 |
#if defined(__i386__) |
|
2818 |
/* |
|
19415 | 2819 |
* aligned or not, we don't care (i386 can do both) |
19349 | 2820 |
*/ |
2821 |
{ |
|
19415 | 2822 |
iVal = ((int *)cp)[0]; |
19349 | 2823 |
RETURN (__MKINT(iVal)); |
2824 |
} |
|
2825 |
#else |
|
19415 | 2826 |
# if defined(__x86_64__) |
19349 | 2827 |
/* |
19415 | 2828 |
* aligned or not, we don't care (i386 can do both) |
2829 |
*/ |
|
2830 |
{ |
|
2831 |
iVal = ((int *)cp)[0]; |
|
2832 |
RETURN (__mkSmallInteger(iVal)); |
|
2833 |
} |
|
2834 |
# else |
|
2835 |
/* |
|
2836 |
* aligned ? |
|
19349 | 2837 |
*/ |
2838 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
19415 | 2839 |
iVal = ((int *)cp)[0]; |
2840 |
} else { |
|
2841 |
# ifdef __LSBFIRST__ |
|
2842 |
iVal = cp[0] & 0xFF; |
|
2843 |
iVal += (cp[1] & 0xFF)<<8; |
|
2844 |
iVal += (cp[2] & 0xFF)<<16; |
|
2845 |
iVal += (cp[3] & 0xFF)<<24; |
|
2846 |
# else |
|
2847 |
# ifdef __MSBFIRST__ |
|
2848 |
iVal = cp[0] & 0xFF; |
|
2849 |
iVal = (iVal<<8)+(cp[1] & 0xFF); |
|
2850 |
iVal = (iVal<<8)+(cp[2] & 0xFF); |
|
2851 |
iVal = (iVal<<8)+(cp[3] & 0xFF); |
|
2852 |
# else |
|
2853 |
{ |
|
2854 |
union { |
|
2855 |
int i; |
|
2856 |
char c[4]; |
|
2857 |
} u; |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2858 |
u.c[0] = cp[0]; |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2859 |
u.c[1] = cp[1]; |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2860 |
u.c[2] = cp[2]; |
19415 | 2861 |
u.c[3] = cp[3]; |
2862 |
iVal = u.i; |
|
2863 |
} |
|
2864 |
# endif |
|
2865 |
# endif |
|
2866 |
||
2867 |
# if __POINTER_SIZE__ == 8 |
|
19349 | 2868 |
RETURN (__mkSmallInteger(iVal)); |
19415 | 2869 |
# else |
19349 | 2870 |
RETURN (__MKINT(iVal)); |
19415 | 2871 |
# endif |
2872 |
} |
|
19349 | 2873 |
# endif |
2874 |
#endif |
|
2875 |
} |
|
2876 |
} |
|
2877 |
} |
|
2878 |
%}. |
|
2879 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2880 |
^ self signedInt32At:byteIndex MSB:self isBigEndian. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2881 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2882 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2883 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2884 |
b := ByteArray new:4. |
19349 | 2885 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
2886 |
(b longAt:1) |
|
4515 | 2887 |
" |
19349 | 2888 |
|
2889 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
2890 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2891 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2892 |
|
19349 | 2893 |
signedInt32At:byteIndex MSB:msb |
2894 |
"return the 4-bytes starting at byteIndex as a (signed) Integer. |
|
2895 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
4515 | 2896 |
The value is retrieved MSB-first, if the msb-arg is true; |
2897 |
LSB-first otherwise." |
|
2898 |
||
13575 | 2899 |
|val |
4515 | 2900 |
ival "{ Class: SmallInteger }" |
2901 |
i "{ Class: SmallInteger }" |
|
19349 | 2902 |
bHH "{ Class: SmallInteger }" |
2903 |
bHL "{ Class: SmallInteger }" |
|
2904 |
bLH "{ Class: SmallInteger }" |
|
2905 |
bLL "{ Class: SmallInteger }"| |
|
4515 | 2906 |
|
2907 |
%{ |
|
2908 |
/* |
|
2909 |
* handle the most common cases fast ... |
|
2910 |
*/ |
|
19349 | 2911 |
if (__isSmallInteger(byteIndex)) { |
19047 | 2912 |
unsigned char *cp; |
2913 |
INT sz; |
|
2914 |
||
2915 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2916 |
if (cp) { |
|
19415 | 2917 |
INT idx = __intVal(byteIndex) - 1; |
19047 | 2918 |
int iVal; |
2919 |
||
19349 | 2920 |
cp += idx; |
19415 | 2921 |
if ((idx >= 0) && ((idx+(sizeof(int)-1)) < sz)) { |
19047 | 2922 |
|
2923 |
if (msb == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2924 |
#if defined(__MSBFIRST__) |
19047 | 2925 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
2926 |
/* |
|
2927 |
* aligned |
|
2928 |
*/ |
|
2929 |
iVal = ((int *)cp)[0]; |
|
2930 |
} else |
|
4515 | 2931 |
#endif |
19047 | 2932 |
{ |
2933 |
iVal = cp[0]; |
|
2934 |
iVal = (iVal << 8) | cp[1]; |
|
2935 |
iVal = (iVal << 8) | cp[2]; |
|
2936 |
iVal = (iVal << 8) | cp[3]; |
|
2937 |
} |
|
2938 |
} else { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2939 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
19047 | 2940 |
/* |
19349 | 2941 |
* aligned or not - we don't care |
19047 | 2942 |
* (i386 can fetch unaligned) |
2943 |
*/ |
|
2944 |
iVal = ((int *)cp)[0]; |
|
4515 | 2945 |
#else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2946 |
# if defined(__LSBFIRST__) |
19047 | 2947 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
2948 |
/* |
|
2949 |
* aligned |
|
2950 |
*/ |
|
2951 |
iVal = ((int *)cp)[0]; |
|
2952 |
} else |
|
4515 | 2953 |
# endif |
19047 | 2954 |
{ |
2955 |
iVal = cp[3]; |
|
2956 |
iVal = (iVal << 8) | cp[2]; |
|
2957 |
iVal = (iVal << 8) | cp[1]; |
|
2958 |
iVal = (iVal << 8) | cp[0]; |
|
2959 |
} |
|
4515 | 2960 |
#endif |
19047 | 2961 |
} |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2962 |
#if __POINTER_SIZE__ == 8 |
19047 | 2963 |
RETURN (__mkSmallInteger(iVal)); |
4515 | 2964 |
#else |
19047 | 2965 |
RETURN (__MKINT(iVal)); |
4515 | 2966 |
#endif |
19047 | 2967 |
} |
2968 |
} |
|
4515 | 2969 |
} |
2970 |
%}. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2971 |
|
19415 | 2972 |
val := self unsignedInt32At:byteIndex MSB:msb. |
4515 | 2973 |
(val > (16r7FFFFFFF)) ifTrue:[ |
19047 | 2974 |
^ val - (16r100000000) |
4515 | 2975 |
]. |
2976 |
^ val |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2977 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2978 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2979 |
|b| |
4515 | 2980 |
|
2981 |
b := ByteArray withAll:#(1 2 3 4). |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2982 |
(b signedInt32At:1 MSB:true) printStringRadix:16. |
19349 | 2983 |
(b signedInt32At:1 MSB:false) printStringRadix:16 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2984 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2985 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2986 |
|
19349 | 2987 |
signedInt32At:byteIndex put:anInteger |
2988 |
"set the 4-bytes starting at index from the signed Integer anInteger. |
|
3433 | 2989 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 2990 |
The integer is stored in the machine's natural byte order." |
2991 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
2992 |
^ self signedInt32At:byteIndex put:anInteger MSB:self isBigEndian |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2993 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2994 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2995 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2996 |
b := ByteArray new:4. |
19349 | 2997 |
b longAt:1 put:-1. |
2998 |
(b unsignedLongAt:1) printStringRadix:16 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2999 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3000 |
|
19349 | 3001 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
3002 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3003 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3004 |
|
19349 | 3005 |
signedInt32At:byteIndex put:anInteger MSB:msb |
3006 |
"set the 4-bytes starting at byteIndex from the signed Integer value. |
|
3007 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3008 |
||
3009 |
This is the ST80 version of #signedDoubleWordAt:put:" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3010 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3011 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3012 |
|
19349 | 3013 |
%{ |
3014 |
/* |
|
3015 |
* handle the most common case fast ... |
|
3016 |
*/ |
|
3017 |
if (__isSmallInteger(byteIndex)) { |
|
3018 |
unsigned char *cp; |
|
3019 |
INT sz; |
|
3020 |
||
3021 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3022 |
if (cp) { |
|
19415 | 3023 |
INT idx = __intVal(byteIndex) - 1; |
3024 |
||
3025 |
if ((idx >= 0) && ((idx+3) < sz)) { |
|
19349 | 3026 |
cp += idx; |
3027 |
||
3028 |
if (__isSmallInteger(anInteger)) { |
|
3029 |
INT __v = __intVal(anInteger); |
|
3030 |
||
3031 |
# if __POINTER_SIZE__ == 8 |
|
3032 |
if ((__v < -0x80000000L) || (__v > 0x7FFFFFFF)) { |
|
3033 |
goto badArg; |
|
3034 |
} |
|
3035 |
# endif |
|
3036 |
if (((INT)cp & 3) == 0) { |
|
3037 |
/* |
|
3038 |
* aligned |
|
3039 |
*/ |
|
3040 |
if ( |
|
3041 |
# ifdef __LSBFIRST__ |
|
3042 |
(msb == false) |
|
3043 |
# else |
|
3044 |
# ifdef __MSBFIRST__ |
|
3045 |
(msb == true) |
|
3046 |
# else |
|
3047 |
(0) |
|
3048 |
# endif |
|
3049 |
# endif |
|
3050 |
) { |
|
3051 |
((int *)cp)[0] = (int)__v; |
|
3052 |
RETURN (anInteger); |
|
3053 |
} |
|
3054 |
} |
|
3055 |
if (msb == false) { |
|
3056 |
cp[0] = __v & 0xFF; |
|
3057 |
cp[1] = (__v>>8) & 0xFF; |
|
3058 |
cp[2] = (__v>>16) & 0xFF; |
|
3059 |
cp[3] = (__v>>24) & 0xFF; |
|
3060 |
} else { |
|
3061 |
cp[0] = (__v>>24) & 0xFF; |
|
3062 |
cp[1] = (__v>>16) & 0xFF; |
|
3063 |
cp[2] = (__v>>8) & 0xFF; |
|
3064 |
cp[3] = __v & 0xFF; |
|
3065 |
} |
|
3066 |
RETURN (anInteger); |
|
3067 |
} |
|
3068 |
} |
|
3069 |
} |
|
3070 |
} |
|
3071 |
badArg: ; |
|
3072 |
%}. |
|
3073 |
||
3074 |
anInteger >= 0 ifTrue:[ |
|
3075 |
v := anInteger |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3076 |
] ifFalse:[ |
19349 | 3077 |
v := anInteger + 16r100000000 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3078 |
]. |
19349 | 3079 |
self unsignedInt32At:byteIndex put:v MSB:msb. |
3080 |
^ anInteger |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3081 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3082 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3083 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3084 |
b := ByteArray new:4. |
19349 | 3085 |
b longAt:1 put:-1. |
3086 |
(b unsignedLongAt:1) printStringRadix:16 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3087 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3088 |
|
19349 | 3089 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
3090 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3091 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3092 |
|
19629 | 3093 |
signedInt32AtLSB:byteIndex |
3094 |
"return the 4-bytes starting at index as a signed 32bit Integer. |
|
3095 |
The index is a smalltalk index (i.e. 1-based). |
|
3096 |
The value is retrieved with least significant byte first" |
|
3097 |
||
3098 |
^ self signedInt32At:byteIndex MSB:false |
|
3099 |
! |
|
3100 |
||
3101 |
signedInt32AtLSB:byteIndex put:anInteger |
|
3102 |
"set the 4-bytes starting at index from the signed Integer anInteger. |
|
3103 |
The index is a smalltalk index (i.e. 1-based). |
|
3104 |
The integer is stored with least significant byte first." |
|
3105 |
||
3106 |
^ self signedInt32At:byteIndex put:anInteger MSB:false |
|
3107 |
! |
|
3108 |
||
3109 |
signedInt32AtMSB:byteIndex |
|
3110 |
"return the 4-bytes starting at index as a signed 32bit Integer. |
|
3111 |
The index is a smalltalk index (i.e. 1-based). |
|
3112 |
The value is retrieved with most significant byte first" |
|
3113 |
||
3114 |
^ self signedInt32At:byteIndex MSB:true |
|
3115 |
! |
|
3116 |
||
3117 |
signedInt32AtMSB:byteIndex put:anInteger |
|
3118 |
"set the 4-bytes starting at index from the signed Integer anInteger. |
|
3119 |
The index is a smalltalk index (i.e. 1-based). |
|
3120 |
The integer is stored with most significant byte first." |
|
3121 |
||
3122 |
^ self signedInt32At:byteIndex put:anInteger MSB:true |
|
3123 |
! |
|
3124 |
||
19349 | 3125 |
unsignedInt32At:byteIndex |
3323 | 3126 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
3433 | 3127 |
The index is a smalltalk index (i.e. 1-based). |
19415 | 3128 |
The value is retrieved in the machine's natural byte order." |
19349 | 3129 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3130 |
^ self unsignedInt32At:byteIndex MSB:self isBigEndian |
3323 | 3131 |
|
3132 |
" |
|
3133 |
|b| |
|
3134 |
||
3135 |
b := ByteArray withAll:#(1 2 3 4). |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3136 |
(b unsignedInt32At:1) printStringRadix:16 |
3323 | 3137 |
" |
3138 |
||
19349 | 3139 |
"Modified: / 5.3.1998 / 14:57:35 / stefan" |
3323 | 3140 |
! |
3141 |
||
19349 | 3142 |
unsignedInt32At:byteIndex MSB:msb |
3143 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 3144 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 3145 |
The value is retrieved MSB-first, if the msb-arg is true; |
3146 |
LSB-first otherwise." |
|
3147 |
||
3148 |
|val |
|
3149 |
ival "{ Class: SmallInteger }" |
|
3150 |
i "{ Class: SmallInteger }" |
|
3151 |
bHH "{ Class: SmallInteger }" |
|
3152 |
bHL "{ Class: SmallInteger }" |
|
3153 |
bLH "{ Class: SmallInteger }" |
|
3154 |
bLL "{ Class: SmallInteger }"| |
|
3155 |
||
3156 |
%{ |
|
3157 |
/* |
|
3158 |
* handle the most common cases fast ... |
|
3159 |
*/ |
|
3160 |
if (__isSmallInteger(byteIndex)) { |
|
3161 |
unsigned char *cp; |
|
3162 |
INT sz; |
|
3163 |
||
3164 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3165 |
if (cp) { |
|
19415 | 3166 |
INT idx = __intVal(byteIndex) - 1; |
19349 | 3167 |
unsigned int iVal; |
3168 |
||
19415 | 3169 |
if ((idx >= 0) && ((idx+(sizeof(int)-1)) < sz)) { |
19349 | 3170 |
cp += idx; |
3171 |
||
3172 |
if (msb == true) { |
|
3173 |
#if defined(__MSBFIRST__) |
|
3174 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
|
3175 |
/* |
|
3176 |
* aligned |
|
3177 |
*/ |
|
3178 |
iVal = ((unsigned int *)cp)[0]; |
|
3179 |
} else |
|
3180 |
#endif |
|
3181 |
{ |
|
3182 |
iVal = cp[0]; |
|
3183 |
iVal = (iVal << 8) | cp[1]; |
|
3184 |
iVal = (iVal << 8) | cp[2]; |
|
3185 |
iVal = (iVal << 8) | cp[3]; |
|
3186 |
} |
|
3187 |
} else { |
|
3188 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
|
3189 |
/* |
|
20816 | 3190 |
* aligned or not - we don't care |
19349 | 3191 |
* (i386 can fetch unaligned) |
3192 |
*/ |
|
3193 |
iVal = ((unsigned int *)cp)[0]; |
|
3194 |
#else |
|
3195 |
# if defined(__LSBFIRST__) |
|
3196 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
|
3197 |
/* |
|
3198 |
* aligned |
|
3199 |
*/ |
|
3200 |
iVal = ((unsigned int *)cp)[0]; |
|
3201 |
} else |
|
3202 |
# endif |
|
3203 |
{ |
|
3204 |
iVal = cp[3]; |
|
3205 |
iVal = (iVal << 8) | cp[2]; |
|
3206 |
iVal = (iVal << 8) | cp[1]; |
|
3207 |
iVal = (iVal << 8) | cp[0]; |
|
3208 |
} |
|
3209 |
#endif |
|
3210 |
} |
|
3211 |
#if __POINTER_SIZE__ == 8 |
|
3212 |
RETURN (__mkSmallInteger(iVal)); |
|
3213 |
#else |
|
3214 |
RETURN (__MKUINT(iVal)); |
|
3215 |
#endif |
|
3216 |
} |
|
3217 |
} |
|
3218 |
} |
|
3219 |
%}. |
|
3220 |
||
3221 |
"/ fallBack code - non ByteArray-like receiver |
|
3222 |
"/ or funny byteIndex |
|
3223 |
||
3224 |
i := byteIndex. |
|
3225 |
msb ifFalse:[ |
|
3226 |
bLL := self byteAt:i. |
|
3227 |
bLH := self byteAt:(i+1). |
|
3228 |
bHL := self byteAt:(i+2). |
|
3229 |
bHH := self byteAt:(i+3). |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3230 |
] ifTrue:[ |
19349 | 3231 |
bHH := self byteAt:i. |
3232 |
bHL := self byteAt:(i+1). |
|
3233 |
bLH := self byteAt:(i+2). |
|
3234 |
bLL := self byteAt:(i+3). |
|
3235 |
]. |
|
3236 |
ival := (bHH bitShift:8) + bHL. |
|
3237 |
ival := (ival bitShift:8) + bLH. |
|
3238 |
val := (ival bitShift:8) + bLL. |
|
3239 |
^ val |
|
3323 | 3240 |
|
3241 |
" |
|
3242 |
|b| |
|
19349 | 3243 |
|
3244 |
b := ByteArray withAll:#(1 2 3 4). |
|
3245 |
(b unsignedInt32At:1 MSB:true) printStringRadix:16. |
|
3246 |
(b unsignedInt32At:1 MSB:false) printStringRadix:16 |
|
3323 | 3247 |
" |
3248 |
! |
|
3249 |
||
19349 | 3250 |
unsignedInt32At:byteIndex put:anInteger |
3251 |
"set the 4-bytes starting at index from the (unsigned) integer value. |
|
3433 | 3252 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 3253 |
The value must be in the range 0 to 16rFFFFFFFF. |
19349 | 3254 |
The value is stored in the machine's native byte order" |
3255 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3256 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:self isBigEndian |
3323 | 3257 |
|
3258 |
" |
|
3259 |
|b| |
|
3260 |
b := ByteArray new:8. |
|
19349 | 3261 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
3262 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
3263 |
b inspect |
|
3323 | 3264 |
" |
3265 |
||
3266 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
19349 | 3267 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
3268 |
! |
|
3269 |
||
3270 |
unsignedInt32At:byteIndex put:anInteger MSB:msb |
|
19415 | 3271 |
"set the 4-bytes starting at byteIndex from the unsigned Integer value. |
3272 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3273 |
||
3274 |
This is the ST80 version of #doubleWordAt:put:" |
|
3275 |
||
3276 |
|v i b1 b2 b3 b4| |
|
3277 |
||
3278 |
%{ |
|
3279 |
/* |
|
3280 |
* handle the most common case fast ... |
|
3281 |
*/ |
|
3282 |
if (__isSmallInteger(byteIndex)) { |
|
3283 |
unsigned char *cp; |
|
3284 |
INT sz; |
|
3285 |
||
3286 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3287 |
if (cp) { |
|
3288 |
INT idx = __intVal(byteIndex) - 1; |
|
3289 |
||
3290 |
if ((idx >= 0) && ((idx+3) < sz)) { |
|
3291 |
cp += idx; |
|
3292 |
||
3293 |
if (__isSmallInteger(anInteger)) { |
|
3294 |
INT __v = __intVal(anInteger); |
|
3295 |
||
3296 |
# if __POINTER_SIZE__ == 8 |
|
3297 |
if ((__v < 0) || (__v > 0xFFFFFFFF)) { |
|
3298 |
goto badArg; |
|
3299 |
} |
|
3300 |
# endif |
|
3301 |
if (((INT)cp & 3) == 0) { |
|
3302 |
/* |
|
3303 |
* aligned |
|
3304 |
*/ |
|
3305 |
if ( |
|
3306 |
# ifdef __LSBFIRST__ |
|
3307 |
(msb == false) |
|
3308 |
# else |
|
3309 |
# ifdef __MSBFIRST__ |
|
3310 |
(msb == true) |
|
3311 |
# else |
|
3312 |
(0) |
|
3313 |
# endif |
|
3314 |
# endif |
|
3315 |
) { |
|
3316 |
((int *)cp)[0] = (int)__v; |
|
3317 |
RETURN (anInteger); |
|
3318 |
} |
|
3319 |
} |
|
3320 |
if (msb == false) { |
|
3321 |
cp[0] = __v & 0xFF; |
|
3322 |
cp[1] = (__v>>8) & 0xFF; |
|
3323 |
cp[2] = (__v>>16) & 0xFF; |
|
3324 |
cp[3] = (__v>>24) & 0xFF; |
|
3325 |
} else { |
|
3326 |
cp[0] = (__v>>24) & 0xFF; |
|
3327 |
cp[1] = (__v>>16) & 0xFF; |
|
3328 |
cp[2] = (__v>>8) & 0xFF; |
|
3329 |
cp[3] = __v & 0xFF; |
|
3330 |
} |
|
3331 |
RETURN (anInteger); |
|
3332 |
} |
|
3333 |
} |
|
3334 |
} |
|
3335 |
} |
|
3336 |
badArg: ; |
|
3337 |
%}. |
|
19349 | 3338 |
|
3339 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFF]) ifTrue:[ |
|
3340 |
^ self elementBoundsError:anInteger |
|
3341 |
]. |
|
3342 |
||
3343 |
i := byteIndex. |
|
3344 |
msb ifTrue:[ |
|
3345 |
b1 := (anInteger digitAt:4). |
|
3346 |
b2 := (anInteger digitAt:3). |
|
3347 |
b3 := (anInteger digitAt:2). |
|
3348 |
b4 := (anInteger digitAt:1). |
|
3349 |
] ifFalse:[ |
|
3350 |
b1 := (anInteger digitAt:1). |
|
3351 |
b2 := (anInteger digitAt:2). |
|
3352 |
b3 := (anInteger digitAt:3). |
|
3353 |
b4 := (anInteger digitAt:4). |
|
3354 |
]. |
|
3355 |
self byteAt:i put:b1. |
|
3356 |
self byteAt:(i+1) put:b2. |
|
3357 |
self byteAt:(i+2) put:b3. |
|
3358 |
self byteAt:(i+3) put:b3. |
|
3359 |
^ anInteger |
|
3459 | 3360 |
|
3361 |
" |
|
3362 |
|b| |
|
19415 | 3363 |
b := ByteArray new:4. |
3364 |
b signedInt32At:1 put:-1. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3365 |
(b unsignedInt32At:1) printStringRadix:16 |
19415 | 3366 |
" |
3367 |
" |
|
3368 |
|b| |
|
3369 |
b := ByteArray new:4. |
|
3370 |
b unsignedInt32At:1 put:16rFFFFFFFF. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3371 |
(b signedInt32At:1) |
19415 | 3372 |
" |
19629 | 3373 |
! |
3374 |
||
3375 |
unsignedInt32AtLSB:byteIndex |
|
3376 |
"return the 4-bytes starting at index as an unsigned 32bit Integer. |
|
3377 |
The index is a smalltalk index (i.e. 1-based). |
|
3378 |
The value is retrieved with least significant byte first" |
|
3379 |
||
3380 |
^ self unsignedInt32At:byteIndex MSB:false |
|
3381 |
! |
|
3382 |
||
3383 |
unsignedInt32AtLSB:byteIndex put:anInteger |
|
3384 |
"set the 4-bytes starting at index from the unsigned Integer anInteger. |
|
3385 |
The index is a smalltalk index (i.e. 1-based). |
|
3386 |
The integer is stored with least significant byte first." |
|
3387 |
||
3388 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:false |
|
3389 |
! |
|
3390 |
||
3391 |
unsignedInt32AtMSB:byteIndex |
|
3392 |
"return the 4-bytes starting at index as an unsigned 32bit Integer. |
|
3393 |
The index is a smalltalk index (i.e. 1-based). |
|
3394 |
The value is retrieved with most significant byte first" |
|
3395 |
||
3396 |
^ self unsignedInt32At:byteIndex MSB:true |
|
3397 |
! |
|
3398 |
||
3399 |
unsignedInt32AtMSB:byteIndex put:anInteger |
|
3400 |
"set the 4-bytes starting at index from the unsigned Integer anInteger. |
|
3401 |
The index is a smalltalk index (i.e. 1-based). |
|
3402 |
The integer is stored with most significant byte first." |
|
3403 |
||
3404 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:true |
|
19349 | 3405 |
! ! |
3406 |
||
20961 | 3407 |
!UninterpretedBytes methodsFor:'accessing-pointers'! |
3408 |
||
3409 |
pointerAt:byteIndex |
|
3410 |
"get a pointer starting at byteIndex as ExternalAddress. |
|
3411 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3412 |
Only aligned accesses are allowed. |
|
3413 |
The pointer is of native cpu's size (4 or 8 bytes)" |
|
3414 |
||
3415 |
%{ |
|
3416 |
if (__isSmallInteger(byteIndex)) { |
|
3417 |
unsigned char *cp; |
|
3418 |
INT sz; |
|
3419 |
||
3420 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3421 |
if (cp) { |
|
3422 |
INT idx = __smallIntegerVal(byteIndex) - 1; |
|
3423 |
char *pointer; |
|
3424 |
||
3425 |
if ((idx >= 0) && ((idx+(sizeof(pointer)-1)) < sz)) { |
|
3426 |
cp += idx; |
|
3427 |
/* |
|
3428 |
* aligned |
|
3429 |
*/ |
|
3430 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
3431 |
pointer = ((char **)cp)[0]; |
|
3432 |
RETURN (__MKEXTERNALADDRESS(pointer)); |
|
3433 |
} else { |
|
3434 |
#if 0 |
|
3435 |
printf("cp UNALIGNED (%"_lx_")\n", (INT)cp); |
|
3436 |
#endif |
|
3437 |
} |
|
3438 |
} else { |
|
3439 |
#if 0 |
|
3440 |
printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n", |
|
3441 |
idx, (int)(sizeof(pointer)-1), sz); |
|
3442 |
#endif |
|
3443 |
} |
|
3444 |
} else { |
|
3445 |
#if 0 |
|
3446 |
printf("cp is NULL\n"); |
|
3447 |
#endif |
|
3448 |
} |
|
3449 |
} else { |
|
3450 |
#if 0 |
|
3451 |
printf("bad index\n"); |
|
3452 |
#endif |
|
3453 |
} |
|
3454 |
bad:; |
|
3455 |
%}. |
|
3456 |
||
3457 |
self primitiveFailed. |
|
3458 |
||
3459 |
" |
|
3460 |
|b| |
|
3461 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
3462 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
3463 |
Transcript showCR:((b unsignedInt32At:1) printStringRadix:16). |
|
3464 |
Transcript showCR:((b pointerAt:1)). |
|
3465 |
||
3466 |
|b| |
|
3467 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
3468 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678abcdef). |
|
3469 |
Transcript showCR:((b unsignedInt64At:1) printStringRadix:16). |
|
3470 |
Transcript showCR:((b pointerAt:1)). |
|
3471 |
" |
|
3472 |
||
3473 |
"Modified (comment): / 14-11-2016 / 17:32:23 / cg" |
|
3474 |
! |
|
3475 |
||
3476 |
pointerAt:byteIndex put:value |
|
3477 |
"set the pointer starting at byteIndex from the integer or externalAddress value. |
|
3478 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3479 |
Only aligned accesses are allowed. |
|
3480 |
The pointer is of native cpu's size (4 or 8 bytes). |
|
3481 |
The value may be either an ExternalAddress, ExternalBytes or an Integer" |
|
3482 |
||
3483 |
%{ |
|
3484 |
OBJ *pointer; |
|
3485 |
||
3486 |
if (__isExternalAddressLike(value)) { |
|
3487 |
pointer = __externalAddressVal(value); |
|
3488 |
} else if (__isExternalBytesLike(value)) { |
|
3489 |
pointer = __externalBytesVal(value); |
|
3490 |
if (pointer == (OBJ *)0) |
|
3491 |
pointer = 0; |
|
3492 |
} else if (value == nil) { |
|
3493 |
pointer = 0; |
|
3494 |
} else if (__isSmallInteger(value)) { |
|
3495 |
pointer = (OBJ *)__intVal(value); |
|
3496 |
} else { |
|
3497 |
if ((pointer = (OBJ *)__unsignedLongIntVal(value)) == 0) { |
|
3498 |
goto bad; |
|
3499 |
} |
|
3500 |
} |
|
3501 |
||
3502 |
if (__isSmallInteger(byteIndex)) { |
|
3503 |
unsigned char *cp; |
|
3504 |
INT sz; |
|
3505 |
||
3506 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3507 |
if (cp) { |
|
3508 |
INT idx = __smallIntegerVal(byteIndex) - 1; |
|
3509 |
||
3510 |
if ((idx >= 0) && ((idx+(sizeof(pointer)-1)) < sz)) { |
|
3511 |
cp += idx; |
|
3512 |
/* |
|
3513 |
* aligned |
|
3514 |
*/ |
|
3515 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
3516 |
((char **)cp)[0] = (char *) pointer; |
|
3517 |
RETURN (value); |
|
3518 |
} |
|
3519 |
} |
|
3520 |
} |
|
3521 |
} |
|
3522 |
bad:; |
|
3523 |
%}. |
|
3524 |
||
3525 |
self primitiveFailed. |
|
3526 |
||
3527 |
" |
|
3528 |
|b| |
|
3529 |
b := ByteArray new:ExternalAddress pointerSize. |
|
3530 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
3531 |
(b unsignedLongAt:1) printStringRadix:16 |
|
3532 |
" |
|
3533 |
||
3534 |
"Created: / 05-03-1998 / 10:57:18 / stefan" |
|
3535 |
"Modified (comment): / 14-11-2016 / 17:28:27 / cg" |
|
3536 |
! |
|
3537 |
||
3538 |
pointerValueAt:byteIndex |
|
3539 |
"get a pointer value starting at byteIndex as unsigned integer. |
|
3540 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3541 |
Only aligned accesses are allowed. |
|
3542 |
The pointer is of native cpu's size (4 or 8 bytes). |
|
3543 |
This returns an int with sizeof the machines's native pointer (4 or 8 bytes)" |
|
3544 |
||
3545 |
%{ |
|
3546 |
if (__isSmallInteger(byteIndex)) { |
|
3547 |
unsigned char *cp; |
|
3548 |
INT sz; |
|
3549 |
||
3550 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3551 |
if (cp) { |
|
3552 |
INT idx = __smallIntegerVal(byteIndex) - 1; |
|
3553 |
char *pointer; |
|
3554 |
||
3555 |
if ((idx >= 0) && ((idx+(sizeof(pointer)-1)) < sz)) { |
|
3556 |
cp += idx; |
|
3557 |
/* |
|
3558 |
* aligned |
|
3559 |
*/ |
|
3560 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
3561 |
pointer = ((char **)cp)[0]; |
|
3562 |
RETURN (__MKUINT((INT)(pointer))); |
|
3563 |
} else { |
|
3564 |
// printf("cp UNALIGNED (%"_lx_")\n", (INT)cp); |
|
3565 |
} |
|
3566 |
} else { |
|
3567 |
// printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n", |
|
3568 |
// idx, (int)(sizeof(pointer)-1), sz); |
|
3569 |
} |
|
3570 |
} else { |
|
3571 |
// printf("cp is NULL\n"); |
|
3572 |
} |
|
3573 |
} else { |
|
3574 |
// printf("bad index\n"); |
|
3575 |
} |
|
3576 |
bad:; |
|
3577 |
%}. |
|
3578 |
||
3579 |
self primitiveFailed. |
|
3580 |
||
3581 |
" |
|
3582 |
|b| |
|
3583 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
3584 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
3585 |
Transcript showCR:((b unsignedLongAt:1) printStringRadix:16). |
|
3586 |
Transcript showCR:((b pointerAt:1)). |
|
3587 |
Transcript showCR:((b pointerValueAt:1)). |
|
3588 |
" |
|
3589 |
||
3590 |
"Modified (comment): / 14-11-2016 / 17:28:33 / cg" |
|
3591 |
! ! |
|
3592 |
||
19349 | 3593 |
!UninterpretedBytes methodsFor:'accessing-shorts (16bit)'! |
3594 |
||
3595 |
signedInt16At:byteIndex |
|
3459 | 3596 |
"return the 2-bytes starting at index as a signed Integer. |
3597 |
The index is a smalltalk index (i.e. 1-based). |
|
19415 | 3598 |
The value is retrieved in the machine's natural byte order." |
3459 | 3599 |
|
19349 | 3600 |
^ (self unsignedInt16At:byteIndex) signExtendedShortValue |
3323 | 3601 |
|
3602 |
" |
|
3603 |
|b| |
|
3459 | 3604 |
b := ByteArray new:2. |
3605 |
b wordAt:1 put:16rFFFF. |
|
13575 | 3606 |
b signedWordAt:1 |
3323 | 3607 |
" |
3608 |
||
3459 | 3609 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
3323 | 3610 |
! |
3611 |
||
19349 | 3612 |
signedInt16At:byteIndex MSB:msb |
3459 | 3613 |
"return the 2-bytes starting at index as a signed Integer. |
3433 | 3614 |
The index is a smalltalk index (i.e. 1-based). |
19366 | 3615 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
3616 |
LSB-first (i.e. low 8-bits at lower byte index) if it's false. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3617 |
Notice: |
19366 | 3618 |
the index is a byte index; thus, this allows for unaligned access to |
3619 |
words on any boundary." |
|
3620 |
||
3621 |
|b1 "{ Class: SmallInteger }" |
|
3622 |
b2 "{ Class: SmallInteger }"| |
|
3623 |
||
3624 |
%{ |
|
3625 |
/* |
|
3626 |
* handle the most common cases fast ... |
|
3627 |
*/ |
|
3628 |
if (__isSmallInteger(byteIndex)) { |
|
3629 |
unsigned char *cp; |
|
3630 |
INT sz; |
|
3631 |
||
3632 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3633 |
if (cp) { |
|
19415 | 3634 |
INT idx = __intVal(byteIndex) - 1; |
3635 |
||
3636 |
if ((idx >= 0) && ((idx+(2-1)) < sz)) { |
|
19366 | 3637 |
short sVal; |
3638 |
||
3639 |
cp += idx; |
|
3640 |
if (msb == false) { |
|
3641 |
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK)) |
|
3642 |
/* |
|
20816 | 3643 |
* aligned or not, we don't care (i386 can do both) |
19366 | 3644 |
*/ |
3645 |
sVal = ((short *)cp)[0]; |
|
3646 |
#else |
|
3647 |
sVal = (cp[0] & 0xFF) | ((cp[1] & 0xFF) << 8); |
|
3648 |
#endif |
|
3649 |
} else { |
|
3650 |
sVal = ((cp[0] & 0xFF) << 8) | (cp[1] & 0xFF); |
|
3651 |
} |
|
3652 |
RETURN (__mkSmallInteger(sVal)); |
|
3653 |
} |
|
3654 |
} |
|
3655 |
} |
|
3656 |
%}. |
|
3657 |
||
3658 |
b1 := self byteAt:byteIndex. |
|
3659 |
b2 := self byteAt:(byteIndex + 1). |
|
3660 |
msb ifTrue:[ |
|
3661 |
^ ((b1 bitShift:8) + b2) signExtendedShortValue |
|
3662 |
]. |
|
3663 |
^ ((b2 bitShift:8) + b1) signExtendedShortValue |
|
3459 | 3664 |
! |
3665 |
||
19349 | 3666 |
signedInt16At:index put:anInteger |
3459 | 3667 |
"set the 2-bytes starting at index from the signed Integer value. |
3668 |
The index is a smalltalk index (i.e. 1-based). |
|
3669 |
The stored value must be in the range -32768 .. +32676. |
|
19349 | 3670 |
The value is stored in the machine's natural byte order." |
3671 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3672 |
^ self signedInt16At:index put:anInteger MSB:self isBigEndian |
3459 | 3673 |
|
3674 |
" |
|
3675 |
|b| |
|
19349 | 3676 |
b := ByteArray new:4. |
3677 |
b signedInt16At:1 put:-2. |
|
3678 |
b signedInt16At:3 put:-3. |
|
3323 | 3679 |
b inspect |
3680 |
" |
|
3681 |
||
19349 | 3682 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
3459 | 3683 |
! |
3684 |
||
19366 | 3685 |
signedInt16At:byteIndex put:anInteger MSB:msb |
3686 |
"set the 2-bytes starting at byteIndex from the signed integer value. |
|
3687 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3459 | 3688 |
The stored value must be in the range -32768 .. +32676. |
3689 |
The value is stored MSB-first, if the msb-arg is true; |
|
19366 | 3690 |
LSB-first otherwise." |
3691 |
||
3692 |
%{ /* NOCONTEXT */ |
|
3693 |
/* |
|
3694 |
* handle the most common case fast ... |
|
3695 |
*/ |
|
3696 |
if (__isSmallInteger(byteIndex)) { |
|
3697 |
unsigned char *cp; |
|
3698 |
INT sz; |
|
3699 |
||
3700 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3701 |
if (cp) { |
|
19415 | 3702 |
INT idx = __intVal(byteIndex) - 1; |
3703 |
||
3704 |
if ((idx >= 0) && ((idx+1) < sz)) { |
|
19366 | 3705 |
cp += idx; |
3706 |
||
3707 |
if (__isSmallInteger(anInteger)) { |
|
3708 |
INT __v = __intVal(anInteger); |
|
3709 |
||
3710 |
if ((__v < -0x8000L) || (__v > 0x7FFF)) { |
|
3711 |
goto badArg; |
|
3712 |
} |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3713 |
if (msb == false) { |
19366 | 3714 |
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK)) |
3715 |
((short *)cp)[0] = (short)__v; |
|
3716 |
#else |
|
3717 |
cp[0] = __v & 0xFF; |
|
3718 |
cp[1] = (__v >> 8) & 0xFF; |
|
3719 |
#endif |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3720 |
} else { |
19366 | 3721 |
cp[0] = (__v >> 8) & 0xFF; |
3722 |
cp[1] = __v & 0xFF; |
|
3723 |
} |
|
3724 |
RETURN (anInteger); |
|
3725 |
} |
|
3726 |
} |
|
3727 |
} |
|
3728 |
} |
|
3729 |
badArg: ; |
|
3730 |
%}. |
|
19349 | 3731 |
anInteger >= 0 ifTrue:[ |
19366 | 3732 |
self unsignedInt16At:byteIndex put:anInteger MSB:msb. |
3459 | 3733 |
] ifFalse:[ |
19366 | 3734 |
self unsignedInt16At:byteIndex put:(16r10000 + anInteger) MSB:msb. |
3459 | 3735 |
]. |
19349 | 3736 |
^ anInteger |
3459 | 3737 |
|
3738 |
" |
|
3739 |
|b| |
|
3740 |
b := ByteArray new:4. |
|
19366 | 3741 |
b signedInt16At:1 put:-1. |
3742 |
b signedInt16At:3 put:-2. |
|
3459 | 3743 |
b inspect |
3744 |
" |
|
3745 |
||
3746 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
3323 | 3747 |
! |
3748 |
||
19629 | 3749 |
signedInt16AtLSB:byteIndex |
3750 |
"return the 2-bytes starting at index as a signed Integer. |
|
3751 |
The index is a smalltalk index (i.e. 1-based). |
|
3752 |
The value is retrieved with least significant byte first" |
|
3753 |
||
3754 |
^ self signedInt16At:byteIndex MSB:false |
|
3755 |
||
3756 |
" |
|
3757 |
|b| |
|
3758 |
b := ByteArray new:2. |
|
3759 |
b wordAt:1 put:16rFFFE. |
|
3760 |
b signedInt16AtLSB:1. |
|
3761 |
b signedInt16AtMSB:1. |
|
3762 |
" |
|
3763 |
||
3764 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
3765 |
! |
|
3766 |
||
3767 |
signedInt16AtLSB:index put:anInteger |
|
3768 |
"set the 2-bytes starting at index from the signed Integer value. |
|
3769 |
The index is a smalltalk index (i.e. 1-based). |
|
3770 |
The stored value must be in the range 0 .. 16rFFFF. |
|
3771 |
The value is stored with least significant byte first" |
|
3772 |
||
3773 |
^ self signedInt16At:index put:anInteger MSB:false |
|
3774 |
||
3775 |
" |
|
3776 |
|b| |
|
3777 |
b := ByteArray new:4. |
|
3778 |
b signedInt16At:1 put:16r0102. |
|
3779 |
b signedInt16At:3 put:16r0304. |
|
3780 |
b inspect |
|
3781 |
" |
|
3782 |
||
3783 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
3784 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3785 |
! |
|
3786 |
||
3787 |
signedInt16AtMSB:byteIndex |
|
3788 |
"return the 2-bytes starting at index as a signed Integer. |
|
3789 |
The index is a smalltalk index (i.e. 1-based). |
|
3790 |
The value is retrieved with most significant byte first" |
|
3791 |
||
3792 |
^ self signedInt16At:byteIndex MSB:true |
|
3793 |
||
3794 |
" |
|
3795 |
|b| |
|
3796 |
b := ByteArray new:2. |
|
3797 |
b wordAt:1 put:16rFFFE. |
|
3798 |
b signedInt16AtLSB:1. |
|
3799 |
b signedInt16AtMSB:1. |
|
3800 |
" |
|
3801 |
||
3802 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
3803 |
! |
|
3804 |
||
3805 |
signedInt16AtMSB:index put:anInteger |
|
3806 |
"set the 2-bytes starting at index from the signed Integer value. |
|
3807 |
The index is a smalltalk index (i.e. 1-based). |
|
3808 |
The stored value must be in the range 0 .. 16rFFFF. |
|
3809 |
The value is stored with most significant byte first" |
|
3810 |
||
3811 |
^ self signedInt16At:index put:anInteger MSB:true |
|
3812 |
||
3813 |
" |
|
3814 |
|b| |
|
3815 |
b := ByteArray new:4. |
|
3816 |
b signedInt16At:1 put:16r0102. |
|
3817 |
b signedInt16At:3 put:16r0304. |
|
3818 |
b inspect |
|
3819 |
" |
|
3820 |
||
3821 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
3822 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3823 |
! |
|
3824 |
||
19349 | 3825 |
unsignedInt16At:index |
3323 | 3826 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 3827 |
The index is a smalltalk index (i.e. 1-based). |
19415 | 3828 |
The value is retrieved in the machine's natural byte order" |
19349 | 3829 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3830 |
^ self unsignedInt16At:index MSB:self isBigEndian |
3323 | 3831 |
! |
3832 |
||
19366 | 3833 |
unsignedInt16At:byteIndex MSB:msb |
3323 | 3834 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 3835 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 3836 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
19366 | 3837 |
LSB-first (i.e. low 8-bits at lower byte index) if it's false. |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3838 |
Notice: |
19349 | 3839 |
the index is a byte index; thus, this allows for unaligned access to |
3840 |
words on any boundary." |
|
3323 | 3841 |
|
13575 | 3842 |
|b1 "{ Class: SmallInteger }" |
3323 | 3843 |
b2 "{ Class: SmallInteger }"| |
3844 |
||
19366 | 3845 |
%{ |
3846 |
/* |
|
3847 |
* handle the most common cases fast ... |
|
3848 |
*/ |
|
3849 |
if (__isSmallInteger(byteIndex)) { |
|
3850 |
unsigned char *cp; |
|
3851 |
INT sz; |
|
3852 |
||
3853 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3854 |
if (cp) { |
|
19415 | 3855 |
INT idx = __intVal(byteIndex) - 1; |
3856 |
||
3857 |
if ((idx >= 0) && ((idx+(2-1)) < sz)) { |
|
19366 | 3858 |
int iVal; |
19506 | 3859 |
|
19366 | 3860 |
cp += idx; |
3861 |
if (msb == false) { |
|
3862 |
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK)) |
|
3863 |
/* |
|
20816 | 3864 |
* aligned or not, we don't care (i386 can do both) |
19366 | 3865 |
*/ |
3866 |
iVal = ((unsigned short *)cp)[0]; |
|
3867 |
#else |
|
3868 |
iVal = (cp[0] & 0xFF) | ((cp[1] & 0xFF) << 8); |
|
3869 |
#endif |
|
3870 |
} else { |
|
3871 |
iVal = ((cp[0] & 0xFF) << 8) | (cp[1] & 0xFF); |
|
3872 |
} |
|
3873 |
RETURN (__mkSmallInteger(iVal)); |
|
3874 |
} |
|
3875 |
} |
|
3876 |
} |
|
3877 |
%}. |
|
3878 |
||
3879 |
b1 := self byteAt:byteIndex. |
|
3880 |
b2 := self byteAt:(byteIndex + 1). |
|
3323 | 3881 |
msb ifTrue:[ |
19046 | 3882 |
^ (b1 bitShift:8) + b2 |
3323 | 3883 |
]. |
3884 |
^ (b2 bitShift:8) + b1 |
|
19415 | 3885 |
|
3886 |
" |
|
3887 |
#[ 16rFF 16r00 ] unsignedInt16At:1 MSB:true |
|
3888 |
#[ 16rFF 16r00 ] unsignedInt16At:1 MSB:false |
|
3889 |
||
3890 |
#[ 16rFF 16r00 ] unsignedInt16At:2 MSB:true |
|
3891 |
#[ 16rFF 16r00 ] unsignedInt16At:2 MSB:false |
|
3892 |
" |
|
3323 | 3893 |
! |
3894 |
||
19349 | 3895 |
unsignedInt16At:index put:anInteger |
3323 | 3896 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 3897 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 3898 |
The stored value must be in the range 0 .. 16rFFFF. |
19415 | 3899 |
The value is stored in the machine's natural byteorder." |
3323 | 3900 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3901 |
^ self unsignedInt16At:index put:anInteger MSB:self isBigEndian |
3323 | 3902 |
|
3903 |
" |
|
3904 |
|b| |
|
3905 |
b := ByteArray new:4. |
|
19349 | 3906 |
b unsignedInt16At:1 put:16r0102. |
3907 |
b unsignedInt16At:3 put:16r0304. |
|
13575 | 3908 |
b inspect |
3323 | 3909 |
" |
3910 |
||
3911 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
3912 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3913 |
! |
|
3914 |
||
19366 | 3915 |
unsignedInt16At:byteIndex put:anInteger MSB:msb |
3323 | 3916 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 3917 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 3918 |
The stored value must be in the range 0 .. 16rFFFF. |
3323 | 3919 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
3920 |
lower index) if msb is false, MSB-first otherwise" |
|
3921 |
||
3922 |
|b1 b2 |
|
3923 |
iVal "{ Class: SmallInteger }"| |
|
3924 |
||
19366 | 3925 |
%{ /* NOCONTEXT */ |
3926 |
/* |
|
3927 |
* handle the most common case fast ... |
|
3928 |
*/ |
|
3929 |
if (__isSmallInteger(byteIndex)) { |
|
3930 |
unsigned char *cp; |
|
3931 |
INT sz; |
|
3932 |
||
3933 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
19404 | 3934 |
// printf("cp=%"_lx_"\n", (INT)cp); |
19366 | 3935 |
if (cp) { |
19415 | 3936 |
INT idx = __intVal(byteIndex) - 1; |
3937 |
||
3938 |
if ((idx >= 0) && ((idx+1) < sz)) { |
|
19366 | 3939 |
cp += idx; |
3940 |
||
3941 |
if (__isSmallInteger(anInteger)) { |
|
3942 |
INT __v = __intVal(anInteger); |
|
3943 |
||
3944 |
if (((unsigned INT)__v) > 0xFFFF) { |
|
3945 |
goto badArg; |
|
3946 |
} |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3947 |
if (msb == false) { |
19366 | 3948 |
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK)) |
3949 |
((unsigned short *)cp)[0] = (unsigned short)__v; |
|
3950 |
#else |
|
3951 |
cp[0] = __v & 0xFF; |
|
3952 |
cp[1] = (__v >> 8) & 0xFF; |
|
3953 |
#endif |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
3954 |
} else { |
19366 | 3955 |
cp[0] = (__v >> 8) & 0xFF; |
3956 |
cp[1] = __v & 0xFF; |
|
3957 |
} |
|
3958 |
RETURN (anInteger); |
|
3959 |
} |
|
3960 |
} |
|
3961 |
} |
|
3962 |
} |
|
3963 |
badArg: ; |
|
3964 |
%}. |
|
19349 | 3965 |
iVal := anInteger. |
3323 | 3966 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
19046 | 3967 |
^ self elementBoundsError:iVal |
3323 | 3968 |
]. |
3969 |
msb ifTrue:[ |
|
19046 | 3970 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
3971 |
b2 := (iVal bitAnd:16rFF). |
|
3323 | 3972 |
] ifFalse:[ |
19046 | 3973 |
b1 := (iVal bitAnd:16rFF). |
3974 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
|
3323 | 3975 |
]. |
19366 | 3976 |
self byteAt:byteIndex put:b1. |
3977 |
self byteAt:byteIndex+1 put:b2. |
|
19349 | 3978 |
^ anInteger |
3323 | 3979 |
|
3980 |
" |
|
3981 |
|b| |
|
3982 |
b := ByteArray new:8. |
|
19366 | 3983 |
b unsignedInt16At:1 put:16r0102 MSB:false. |
3984 |
b unsignedInt16At:3 put:16r0304 MSB:false. |
|
3985 |
b unsignedInt16At:5 put:16r0102 MSB:true. |
|
3986 |
b unsignedInt16At:7 put:16r0304 MSB:true. |
|
13575 | 3987 |
b inspect |
3323 | 3988 |
" |
3989 |
||
3990 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
3991 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
19629 | 3992 |
! |
3993 |
||
3994 |
unsignedInt16AtLSB:byteIndex |
|
3995 |
"return the 2-bytes starting at index as an unsigned Integer. |
|
3996 |
The index is a smalltalk index (i.e. 1-based). |
|
3997 |
The value is retrieved with least significant byte first" |
|
3998 |
||
3999 |
^ self unsignedInt16At:byteIndex MSB:false |
|
4000 |
||
4001 |
" |
|
4002 |
|b| |
|
4003 |
b := ByteArray new:2. |
|
4004 |
b wordAt:1 put:16rFFFE. |
|
4005 |
b unsignedInt16AtLSB:1. |
|
4006 |
b unsignedInt16AtMSB:1. |
|
4007 |
" |
|
4008 |
||
4009 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
4010 |
! |
|
4011 |
||
4012 |
unsignedInt16AtLSB:index put:anInteger |
|
4013 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
4014 |
The index is a smalltalk index (i.e. 1-based). |
|
4015 |
The stored value must be in the range 0 .. 16rFFFF. |
|
4016 |
The value is stored with least significant byte first" |
|
4017 |
||
4018 |
^ self unsignedInt16At:index put:anInteger MSB:false |
|
4019 |
||
4020 |
" |
|
4021 |
|b| |
|
4022 |
b := ByteArray new:4. |
|
4023 |
b unsignedInt16At:1 put:16r0102. |
|
4024 |
b unsignedInt16At:3 put:16r0304. |
|
4025 |
b inspect |
|
4026 |
" |
|
4027 |
||
4028 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
4029 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
4030 |
! |
|
4031 |
||
4032 |
unsignedInt16AtMSB:byteIndex |
|
4033 |
"return the 2-bytes starting at index as an unsigned Integer. |
|
4034 |
The index is a smalltalk index (i.e. 1-based). |
|
4035 |
The value is retrieved with most significant byte first" |
|
4036 |
||
4037 |
^ self unsignedInt16At:byteIndex MSB:true |
|
4038 |
||
4039 |
" |
|
4040 |
|b| |
|
4041 |
b := ByteArray new:2. |
|
4042 |
b wordAt:1 put:16rFFFF. |
|
4043 |
b signedWordAt:1 |
|
4044 |
" |
|
4045 |
||
4046 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
4047 |
! |
|
4048 |
||
4049 |
unsignedInt16AtMSB:index put:anInteger |
|
4050 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
4051 |
The index is a smalltalk index (i.e. 1-based). |
|
4052 |
The stored value must be in the range 0 .. 16rFFFF. |
|
4053 |
The value is stored with most significant byte first" |
|
4054 |
||
4055 |
^ self unsignedInt16At:index put:anInteger MSB:true |
|
4056 |
||
4057 |
" |
|
4058 |
|b| |
|
4059 |
b := ByteArray new:4. |
|
4060 |
b unsignedInt16At:1 put:16r0102. |
|
4061 |
b unsignedInt16At:3 put:16r0304. |
|
4062 |
b inspect |
|
4063 |
" |
|
4064 |
||
4065 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
4066 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3459 | 4067 |
! ! |
4068 |
||
4069 |
!UninterpretedBytes methodsFor:'accessing-strings'! |
|
4070 |
||
4071 |
stringAt:index |
|
4072 |
"return a string starting at index up to the 0-byte. |
|
4073 |
The index is a smalltalk index (i.e. 1-based)." |
|
4074 |
||
4075 |
|stream i "{ Class: SmallInteger }" c| |
|
4076 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4077 |
stream := WriteStream on:(String new:40). |
3459 | 4078 |
i := index. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4079 |
[(c := self byteAt:i) ~~ 0] whileTrue:[ |
19368 | 4080 |
stream nextPut:(Character value:c). |
4081 |
i := i + 1. |
|
3459 | 4082 |
]. |
4083 |
^ stream contents |
|
4084 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4085 |
" |
13575 | 4086 |
#[71 72 73 74 75 76 77 0] stringAt:1 |
4087 |
#[71 72 73 74 75 76 77 0] stringAt:2 |
|
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4088 |
'1234567890' stringAt:2 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4089 |
" |
3459 | 4090 |
! |
4091 |
||
4092 |
stringAt:index put:aString |
|
19196 | 4093 |
"copy aString to the receiver, starting at index up to |
7815 | 4094 |
(and including) the 0-byte (which is always written). |
3459 | 4095 |
The index is a smalltalk index (i.e. 1-based)." |
4096 |
||
4097 |
|i "{ Class: SmallInteger }"| |
|
4098 |
||
4099 |
i := index. |
|
4100 |
aString do:[:aChar | |
|
19196 | 4101 |
self byteAt:i put:aChar codePoint. |
4102 |
i := i + 1. |
|
3459 | 4103 |
]. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4104 |
self byteAt:i put:0. |
3459 | 4105 |
^ aString |
4106 |
||
4107 |
" |
|
4108 |
|bytes| |
|
4109 |
||
4110 |
bytes := ExternalBytes new:10. |
|
4111 |
bytes stringAt:1 put:'hello'. |
|
4112 |
1 to:bytes size do:[:i | |
|
19196 | 4113 |
Transcript showCR:(bytes at:i) |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4114 |
]. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4115 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4116 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4117 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4118 |
(String new:20) stringAt:1 put:'hello'; stringAt:6 put:' world'; yourself |
3459 | 4119 |
" |
4120 |
||
4121 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
|
4122 |
! |
|
4123 |
||
7812 | 4124 |
stringAt:index put:aString size:maxSize |
19196 | 4125 |
"copy aString to the receiver, starting at index up to either maxSize characters, |
7812 | 4126 |
or (and including) the 0-byte, whichever is encountered first. |
7815 | 4127 |
The final 0-byte is only written, if the string is shorter than maxSize. |
7812 | 4128 |
The index is a smalltalk index (i.e. 1-based)." |
4129 |
||
4130 |
|remaining "{ Class: SmallInteger }" |
|
4131 |
i "{ Class: SmallInteger }"| |
|
4132 |
||
4133 |
remaining := maxSize. |
|
7816 | 4134 |
remaining <= 0 ifTrue:[^ aString]. |
7812 | 4135 |
|
4136 |
i := index. |
|
4137 |
aString do:[:aChar | |
|
19196 | 4138 |
self byteAt:i put:aChar codePoint. |
4139 |
i := i + 1. |
|
4140 |
remaining := remaining - 1. |
|
4141 |
remaining <= 0 ifTrue:[^ aString]. |
|
7812 | 4142 |
]. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4143 |
self byteAt:i put:0. |
7812 | 4144 |
^ aString |
4145 |
||
4146 |
" |
|
4147 |
|bytes| |
|
4148 |
||
4149 |
bytes := ExternalBytes new:10. |
|
4150 |
bytes stringAt:1 put:'hello' size:3. |
|
4151 |
1 to:bytes size do:[:i | |
|
19196 | 4152 |
Transcript showCR:(bytes at:i) |
7812 | 4153 |
] |
4154 |
" |
|
4155 |
" |
|
4156 |
|bytes| |
|
4157 |
||
4158 |
bytes := ByteArray new:10 withAll:16rFF. |
|
4159 |
bytes stringAt:1 put:'he' size:3. |
|
4160 |
1 to:bytes size do:[:i | |
|
19196 | 4161 |
Transcript showCR:(bytes at:i) |
7812 | 4162 |
] |
4163 |
" |
|
4164 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4165 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4166 |
(String new:20) stringAt:1 put:'hello' size:3 ; stringAt:4 put:' world' size:4; yourself |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4167 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4168 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4169 |
|
7812 | 4170 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
4171 |
! |
|
4172 |
||
3459 | 4173 |
stringAt:index size:maxSize |
4174 |
"return a string starting at index up to maxSize, or a 0-byte. |
|
4175 |
The index is a smalltalk index (i.e. 1-based)." |
|
4176 |
||
13575 | 4177 |
|stream c |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4178 |
max "{ Class: SmallInteger }" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4179 |
start "{ Class: SmallInteger }"| |
3459 | 4180 |
|
4181 |
stream := WriteStream on:(String new:maxSize). |
|
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4182 |
start := index. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4183 |
max := start + maxSize - 1. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4184 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4185 |
start to:max do:[:eachIndex| |
19368 | 4186 |
c := self byteAt:eachIndex. |
4187 |
c == 0 ifTrue:[ |
|
4188 |
^ stream contents |
|
4189 |
]. |
|
4190 |
stream nextPut:(Character value:c). |
|
3459 | 4191 |
]. |
4192 |
^ stream contents |
|
4193 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4194 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4195 |
#[71 72 73 74 75 76 77] stringAt:1 size:7 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4196 |
#[71 72 73 74 75 76 77] stringAt:2 size:6 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4197 |
'1234567890' stringAt:2 size:6 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4198 |
" |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4199 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4200 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4201 |
zeroByteStringAt:index maximumSize:count |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4202 |
"extract a zeroByte-delimited string, given initial index and |
3433 | 4203 |
maximum number of characters (bytes). |
4204 |
The index is a smalltalk index (i.e. 1-based)." |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4205 |
|
19415 | 4206 |
|bytes endIndex idx| |
4207 |
||
4208 |
endIndex := self indexOf:0 startingAt:index. |
|
4209 |
endIndex == 0 ifTrue:[ |
|
4210 |
endIndex := self size + 1 |
|
4211 |
]. |
|
4212 |
endIndex := (endIndex min: (index + count)) - 1. |
|
4213 |
bytes := self copyFrom:index to:endIndex. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4214 |
^ bytes asString |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4215 |
|
19415 | 4216 |
" |
4217 |
#[ 1 2 3 4 5 6 7 8 ] zeroByteStringAt:2 maximumSize:10 |
|
4218 |
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:10 |
|
4219 |
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:3 |
|
4220 |
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:4 |
|
4221 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4222 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4223 |
|
12951 | 4224 |
!UninterpretedBytes methodsFor:'converting'! |
4225 |
||
4226 |
asExternalBytes |
|
4227 |
|sz bytes| |
|
4228 |
||
14142 | 4229 |
sz := self byteSize. |
12951 | 4230 |
bytes := ExternalBytes unprotectedNew:sz. |
4231 |
bytes replaceBytesFrom:1 to:sz with:self startingAt:1. |
|
4232 |
^ bytes |
|
4233 |
||
4234 |
" |
|
4235 |
#[1 2 3 4 5 6 7] asExternalBytes |
|
4236 |
'Hello World' asExternalBytes |
|
14142 | 4237 |
'Hello World' asUnicodeString asExternalBytes |
12951 | 4238 |
" |
14132 | 4239 |
! |
4240 |
||
14155 | 4241 |
asExternalBytesUnprotected |
4242 |
"Like asExternalBytes, but does not register the bytes so |
|
15836 | 4243 |
bytes are GARBAGE-COLLECTED." |
14155 | 4244 |
|
4245 |
|bytes sz| |
|
4246 |
||
4247 |
sz := self byteSize. |
|
15836 | 4248 |
bytes := ExternalBytes unprotectedNew:sz. |
14155 | 4249 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
4250 |
^ bytes |
|
4251 |
||
4252 |
" |
|
4253 |
|x| |
|
4254 |
x := 'fooBar' asExternalBytesUnprotected. |
|
4255 |
ObjectMemory garbageCollect |
|
4256 |
" |
|
4257 |
||
4258 |
"Created: / 05-06-2012 / 14:11:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15836 | 4259 |
"Modified: / 30-11-2013 / 11:42:21 / cg" |
14155 | 4260 |
! |
4261 |
||
18600 | 4262 |
asSingleByteString |
4263 |
"return the receiver converted to a 'normal' string. |
|
4264 |
Raises an error if unrepresentable characters are encountered. |
|
4265 |
See also: asSingleByteStringIfPossible and asSingleByteStringReplaceInvalidWith:" |
|
4266 |
||
4267 |
^ String fromString:self |
|
4268 |
||
4269 |
" |
|
4270 |
#[60 61 62 63] asSingleByteString |
|
18616 | 4271 |
#[60 61 62 63] asExternalBytes asSingleByteString |
18969 | 4272 |
#[67 68 69 70] asIntegerArray asSingleByteString |
18600 | 4273 |
(Unicode16String with:(Character value:16rFF)) asSingleByteString |
4274 |
(Unicode16String with:(Character value:16rFFFF)) asSingleByteString |
|
4275 |
" |
|
4276 |
! |
|
4277 |
||
18969 | 4278 |
asSingleByteStringIfPossible |
4279 |
"if possible, return the receiver converted to a 'normal' string. |
|
4280 |
It is only possible, if there are no characters with codePoints above 255 in the receiver. |
|
4281 |
If not possible, the (wideString) receiver is returned." |
|
4282 |
||
4283 |
self containsNon8BitElements ifTrue:[^ self asString]. |
|
4284 |
^ self asSingleByteString. |
|
4285 |
||
4286 |
" |
|
4287 |
#[67 68 69 70] asSingleByteStringIfPossible |
|
4288 |
#[67 68 69 70] asIntegerArray asSingleByteStringIfPossible |
|
4289 |
'hello' asUnicodeString asSingleByteStringIfPossible |
|
4290 |
" |
|
4291 |
! |
|
4292 |
||
14132 | 4293 |
asUUID |
4294 |
^ UUID fromBytes:self |
|
12951 | 4295 |
! ! |
4296 |
||
18616 | 4297 |
!UninterpretedBytes methodsFor:'encoding & decoding'! |
4298 |
||
4299 |
utf8Decoded |
|
4300 |
"Interpreting myself as an UTF-8 representation, decode and return the decoded string." |
|
4301 |
||
4302 |
^ CharacterArray decodeFromUTF8:self. |
|
4303 |
||
4304 |
" |
|
4305 |
#[16rC8 16rA0] utf8Decoded |
|
4306 |
#[16rC8 16rA0] asString utf8Decoded |
|
4307 |
#[16rC8 16rA0] asExternalBytes utf8Decoded |
|
4308 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
4309 |
||
4310 |
(Character value:16r800) utf8Encoded |
|
4311 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
4312 |
" |
|
4313 |
||
4314 |
"test: |
|
4315 |
||
4316 |
|utf8Encoding original readBack| |
|
4317 |
||
4318 |
1 to:16rFFFF do:[:ascii | |
|
19368 | 4319 |
original := (Character value:ascii) asString. |
4320 |
utf8Encoding := original utf8Encoded. |
|
4321 |
readBack := utf8Encoding utf8Decoded. |
|
4322 |
readBack = original ifFalse:[ |
|
4323 |
self halt |
|
4324 |
] |
|
18616 | 4325 |
] |
4326 |
" |
|
4327 |
! |
|
4328 |
||
4329 |
utf8DecodedWithTwoByteCharactersReplacedBy:replacementCharacter |
|
4330 |
"Interpreting myself as an UTF-8 representation, decode and return |
|
4331 |
the decoded string. Suppress all 2-byte (above 16rFF) characters, |
|
4332 |
and replace them with replacementCharacter" |
|
4333 |
||
4334 |
|in out c| |
|
4335 |
||
4336 |
self containsNon7BitAscii ifFalse:[ |
|
19368 | 4337 |
^ self asSingleByteString |
18616 | 4338 |
]. |
4339 |
||
4340 |
out := WriteStream on:(String uninitializedNew:self size * 3 // 2). |
|
4341 |
in := self readStream. |
|
4342 |
[in atEnd] whileFalse:[ |
|
19368 | 4343 |
c := Character utf8DecodeFrom:in. |
4344 |
c codePoint > 16rFF ifTrue:[ |
|
4345 |
c := replacementCharacter |
|
4346 |
]. |
|
4347 |
out nextPut:c. |
|
18616 | 4348 |
]. |
4349 |
^ out contents |
|
4350 |
||
4351 |
" |
|
4352 |
(Character value:16r220) utf8Encoded |
|
19368 | 4353 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
18616 | 4354 |
|
4355 |
(Character value:16r220) utf8Encoded asExternalBytes copyButLast |
|
19368 | 4356 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
18616 | 4357 |
" |
4358 |
! ! |
|
4359 |
||
4782 | 4360 |
!UninterpretedBytes methodsFor:'filling & replacing'! |
4361 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4362 |
replaceBytesFrom:start to:stop with:aCollection startingAt:repStart |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4363 |
"replace elements from another collection, which must be a ByteArray- |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4364 |
like collection. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4365 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4366 |
Notice: This operation modifies the receiver, NOT a copy; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4367 |
therefore the change may affect all others referencing the receiver." |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4368 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4369 |
%{ /* NOCONTEXT */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4370 |
|
23102
574962856f04
Issue #200: fixed `#basicAt:` / `#basicAt:put:` to work with objects bigger than 2GB
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21387
diff
changeset
|
4371 |
unsigned INT nIndex, repNIndex; |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4372 |
int startIndex, stopIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4373 |
REGISTER unsigned char *src; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4374 |
REGISTER int repStartIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4375 |
int repStopIndex, count; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4376 |
REGISTER unsigned char *dst; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4377 |
OBJ cls; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4378 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4379 |
#ifndef NO_PRIM_BYTEARR |
14082 | 4380 |
if ((__isBytes(aCollection) || __isExternalBytesLike(aCollection)) |
14142 | 4381 |
&& (__isBytes(self) || __isWords(self)) |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4382 |
&& __bothSmallInteger(start, stop) |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4383 |
&& __isSmallInteger(repStart)) { |
19368 | 4384 |
startIndex = __intVal(start) - 1; |
4385 |
if (startIndex >= 0) { |
|
4386 |
dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex; |
|
4387 |
nIndex = __byteArraySize(self); |
|
4388 |
||
4389 |
if ((cls = __qClass(self)) != @global(ByteArray)) { |
|
4390 |
int nInst; |
|
4391 |
||
4392 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
4393 |
dst += nInst; |
|
4394 |
nIndex -= nInst; |
|
4395 |
} |
|
4396 |
||
4397 |
stopIndex = __intVal(stop) - 1; |
|
4398 |
count = stopIndex - startIndex + 1; |
|
4399 |
if (count == 0) { |
|
4400 |
RETURN ( self ); |
|
4401 |
} |
|
4402 |
||
4403 |
if ((count > 0) && (stopIndex < nIndex)) { |
|
4404 |
repStartIndex = __intVal(repStart) - 1; |
|
4405 |
if (repStartIndex >= 0) { |
|
4406 |
if (__isExternalBytesLike(aCollection)) { |
|
4407 |
OBJ sz; |
|
4408 |
||
4409 |
src = __externalAddressVal(aCollection); |
|
4410 |
if (src == 0) goto fallBack; |
|
4411 |
||
4412 |
sz = __externalBytesSize(aCollection); |
|
4413 |
if (__isSmallInteger(sz)) { |
|
4414 |
repNIndex = __smallIntegerVal(sz); |
|
4415 |
} else { |
|
4416 |
repNIndex = repStopIndex+1; /* always enough */ |
|
4417 |
} |
|
4418 |
src = src + repStartIndex; |
|
4419 |
} else { |
|
4420 |
if (__isStringLike(aCollection)) { |
|
4421 |
repNIndex = __stringSize(aCollection); |
|
4422 |
} else { |
|
4423 |
repNIndex = __qSize(aCollection) - OHDR_SIZE; |
|
4424 |
} |
|
4425 |
src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex; |
|
4426 |
if ((cls = __qClass(aCollection)) != @global(ByteArray)) { |
|
4427 |
int nInst; |
|
4428 |
||
4429 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
4430 |
src += nInst; |
|
4431 |
repNIndex -= nInst; |
|
4432 |
} |
|
4433 |
} |
|
4434 |
repStopIndex = repStartIndex + (stopIndex - startIndex); |
|
4435 |
if (repStopIndex < repNIndex) { |
|
4436 |
if (aCollection == self) { |
|
4437 |
/* take care of overlapping copy */ |
|
4438 |
if (src < dst) { |
|
4439 |
/* must do a reverse copy */ |
|
4440 |
src += count; |
|
4441 |
dst += count; |
|
4442 |
while (count-- > 0) { |
|
4443 |
*--dst = *--src; |
|
4444 |
} |
|
4445 |
RETURN ( self ); |
|
4446 |
} |
|
4447 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4448 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4449 |
# ifdef bcopy4 |
19368 | 4450 |
if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) { |
4451 |
int nW; |
|
4452 |
||
4453 |
/* copy unaligned part */ |
|
4454 |
while (count && ((unsigned INT)src & 3)) { |
|
4455 |
*dst++ = *src++; |
|
4456 |
count--; |
|
4457 |
} |
|
4458 |
||
4459 |
if (count > 0) { |
|
4460 |
/* copy aligned part */ |
|
4461 |
nW = count >> 2; |
|
4462 |
bcopy4(src, dst, nW); |
|
4463 |
if ((count = count & 3) != 0) { |
|
4464 |
/* copy any remaining part */ |
|
4465 |
src += (nW<<2); |
|
4466 |
dst += (nW<<2); |
|
4467 |
while (count--) { |
|
4468 |
*dst++ = *src++; |
|
4469 |
} |
|
4470 |
} |
|
4471 |
} |
|
4472 |
RETURN ( self ); |
|
4473 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4474 |
# else |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4475 |
# if __POINTER_SIZE__ == 8 |
19368 | 4476 |
if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) { |
4477 |
/* copy unaligned part */ |
|
4478 |
while (count && ((unsigned INT)src & 7)) { |
|
4479 |
*dst++ = *src++; |
|
4480 |
count--; |
|
4481 |
} |
|
4482 |
||
4483 |
/* copy aligned part */ |
|
4484 |
while (count >= 8) { |
|
4485 |
((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0]; |
|
4486 |
dst += 8; |
|
4487 |
src += 8; |
|
4488 |
count -= 8; |
|
4489 |
} |
|
4490 |
while (count--) { |
|
4491 |
*dst++ = *src++; |
|
4492 |
} |
|
4493 |
RETURN ( self ); |
|
4494 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4495 |
# endif /* 64bit */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4496 |
# endif /* bcopy4 */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4497 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4498 |
# ifdef FAST_MEMCPY |
19368 | 4499 |
bcopy(src, dst, count); |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4500 |
# else |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4501 |
# ifdef __UNROLL_LOOPS__ |
19368 | 4502 |
while (count >= 8) { |
4503 |
dst[0] = src[0]; dst[1] = src[1]; |
|
4504 |
dst[2] = src[2]; dst[3] = src[3]; |
|
4505 |
dst[4] = src[4]; dst[5] = src[5]; |
|
4506 |
dst[6] = src[6]; dst[7] = src[7]; |
|
4507 |
dst += 8; src += 8; |
|
4508 |
count -= 8; |
|
4509 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4510 |
# endif /* __UNROLL_LOOPS__ */ |
19368 | 4511 |
while (count-- > 0) { |
4512 |
*dst++ = *src++; |
|
4513 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4514 |
# endif |
19368 | 4515 |
RETURN ( self ); |
4516 |
} |
|
4517 |
} |
|
4518 |
} |
|
4519 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4520 |
} |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4521 |
fallBack: ; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4522 |
#endif |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4523 |
%}. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4524 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4525 |
fall back in case of non-ByteArray argument, |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4526 |
or for the error report if any index is invalid |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4527 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4528 |
self slowReplaceBytesFrom:start to:stop with:aCollection startingAt:repStart |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4529 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4530 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4531 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4532 |
copy |
4533 |
replaceFrom:1 to:8 |
|
4534 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4535 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4536 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4537 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4538 |
copy |
4539 |
replaceFrom:3 to:10 |
|
4540 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4541 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4542 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4543 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4544 |
copy |
4545 |
replaceFrom:3 to:4 |
|
4546 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4547 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4548 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4549 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4550 |
copy |
4551 |
replaceFrom:0 to:9 |
|
4552 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4553 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4554 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4555 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4556 |
copy |
4557 |
replaceFrom:1 to:10 |
|
4558 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4559 |
startingAt:0 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4560 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4561 |
! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4562 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4563 |
replaceBytesFrom:startIndex with:replacementCollection startingAt:repStartIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4564 |
"replace elements from another collection, which must be |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4565 |
byte-array-like. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4566 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4567 |
Notice: This operation modifies the receiver, NOT a copy; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4568 |
therefore the change may affect all others referencing the receiver." |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4569 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4570 |
^ self |
19368 | 4571 |
replaceBytesFrom:startIndex |
4572 |
to:(startIndex + replacementCollection size - repStartIndex) |
|
4573 |
with:replacementCollection |
|
4574 |
startingAt:repStartIndex |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4575 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4576 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4577 |
args: startIndex : <integer> |
19368 | 4578 |
replacementCollection : <collection of <bytes> > |
4579 |
repStartIndex : <integer> |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4580 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4581 |
returns: self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4582 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4583 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4584 |
"Created: / 27.7.1998 / 16:56:46 / cg" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4585 |
"Modified: / 27.7.1998 / 16:58:38 / cg" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4586 |
! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4587 |
|
13902 | 4588 |
replaceBytesWith:replacementCollection |
4589 |
"replace elements from another collection, which must be byte-array-like. |
|
4590 |
Replace stops at whichever collection is smaller. |
|
4591 |
||
4592 |
Notice: This operation modifies the receiver, NOT a copy; |
|
4593 |
therefore the change may affect all others referencing the receiver." |
|
4594 |
||
4595 |
^ self |
|
19368 | 4596 |
replaceBytesFrom:1 |
4597 |
to:(replacementCollection size min:self size) |
|
4598 |
with:replacementCollection |
|
4599 |
startingAt:1 |
|
13902 | 4600 |
|
4601 |
" |
|
15004 | 4602 |
(ByteArray new:10) replaceBytesWith:'hello' |
4603 |
(ByteArray new:10) replaceBytesWith:'hello world bla bla bla' |
|
13902 | 4604 |
" |
4605 |
||
4606 |
"Created: / 09-01-2012 / 16:18:10 / cg" |
|
4607 |
! |
|
4608 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4609 |
replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4610 |
"replace elements in the receiver between index start and stop, |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4611 |
with elements taken from replacementCollection starting at repStart. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4612 |
Return the receiver. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4613 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4614 |
Notice: This operation modifies the receiver, NOT a copy; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4615 |
therefore the change may affect all others referencing the receiver." |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4616 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
4617 |
self class isBytes ifTrue:[ |
19368 | 4618 |
((aCollection class == self class) |
4619 |
or:[aCollection isByteCollection]) ifTrue:[ |
|
4620 |
^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex |
|
4621 |
]. |
|
7252
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
4622 |
]. |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4623 |
^ super replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4624 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4625 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4626 |
args: startIndex : <integer> |
19368 | 4627 |
stopIndex : <integer> |
4628 |
replacementCollection : <collection of <bytes> > |
|
4629 |
repStartIndex : <integer> |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4630 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4631 |
returns: self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4632 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4633 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
4634 |
"Modified: / 08-05-2012 / 13:23:27 / cg" |
4782 | 4635 |
! ! |
4636 |
||
12757 | 4637 |
!UninterpretedBytes methodsFor:'hashing'! |
4638 |
||
4639 |
computeXorHashFrom:startIndex to:endIndex |
|
20372 | 4640 |
"compute and answer the 32bit SmallInteger-Hash of the bytes |
12757 | 4641 |
from startIndex to endIndex. |
4642 |
If endindex = 0 or endIndex > size, hash up the size. |
|
4643 |
||
4644 |
NOTE: startIndex and endIndex are only hints about what should be hashed. |
|
19368 | 4645 |
In fact, more bytes could be involved in hashing. |
20372 | 4646 |
SO ARRAYS MUST BE EQUAL TO HASH TO THE SAME VALUE. |
4647 |
||
4648 |
Also NOTE: |
|
4649 |
used to return a 32bit hash on 32bit machines and a 64bit integer on 64bit cpus. |
|
4650 |
changed to return the same for all (in case hash values are used for other purposes)." |
|
12757 | 4651 |
|
4652 |
|w| |
|
4653 |
||
4654 |
%{ |
|
4655 |
if (__bothSmallInteger(startIndex, endIndex)) { |
|
19368 | 4656 |
unsigned char *cp; |
4657 |
INT sz; |
|
4658 |
||
4659 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
4660 |
if (cp) { |
|
4661 |
INT sidx = ((unsigned INT)__smallIntegerVal(startIndex)) - 1; |
|
4662 |
INT eidx = ((unsigned INT)__smallIntegerVal(endIndex)) - 1; |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
4663 |
// # define H_INT INT |
20372 | 4664 |
// # define _MAX_H_INT _MAX_INT; |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
4665 |
# define H_INT int |
20372 | 4666 |
# define _MAX_H_INT 0x3FFFFFFF |
4667 |
||
19368 | 4668 |
unsigned char *ep; |
20372 | 4669 |
unsigned H_INT hash = 0, hash2 = 0, carry; |
19368 | 4670 |
int i; |
4671 |
||
4672 |
if (eidx < 0 || eidx >= sz) eidx = sz - 1; |
|
4673 |
if (sidx > eidx) sidx = eidx; |
|
4674 |
if (sidx < 0) { |
|
4675 |
RETURN(__mkSmallInteger(0)); |
|
4676 |
} |
|
4677 |
||
4678 |
ep = cp + eidx; |
|
4679 |
cp += sidx; |
|
12757 | 4680 |
|
4681 |
#if 0 |
|
19368 | 4682 |
/* |
4683 |
* On LSB-First (little endian) cpus, |
|
4684 |
* this code does not produce the same result |
|
4685 |
* if the same bytes are at different positions |
|
4686 |
*/ |
|
4687 |
||
20372 | 4688 |
if ((H_INT)cp & (sizeof(H_INT)-1)) { |
19368 | 4689 |
/* not aligned */ |
4690 |
||
4691 |
for (i=0; cp <= ep; cp++) { |
|
4692 |
hash2 = (hash2 << 8) | *cp; |
|
20372 | 4693 |
if (++i == sizeof(H_INT)) { |
19368 | 4694 |
hash ^= hash2; |
4695 |
i = hash2 = 0; |
|
4696 |
} |
|
4697 |
} |
|
4698 |
} else { |
|
4699 |
/* aligned */ |
|
20372 | 4700 |
for (; cp+sizeof(H_INT) <= ep; cp += sizeof(H_INT)) { |
4701 |
hash ^= *(unsigned H_INT *)cp; |
|
19368 | 4702 |
} |
4703 |
for (; cp <= ep; cp++) { |
|
4704 |
hash2 = (hash2 << 8) | *cp; |
|
4705 |
} |
|
4706 |
} |
|
12757 | 4707 |
#else |
20372 | 4708 |
for (i=0; cp <= ep-sizeof(H_INT); cp += sizeof(H_INT)) { |
19368 | 4709 |
hash2 = cp[0]; |
4710 |
hash2 = (hash2 << 8) | cp[1]; |
|
4711 |
hash2 = (hash2 << 8) | cp[2]; |
|
4712 |
hash2 = (hash2 << 8) | cp[3]; |
|
20373 | 4713 |
# if 0 |
20372 | 4714 |
if (sizeof(H_INT) == 8) { |
4715 |
hash2 = (hash2 << 8) | cp[4]; |
|
4716 |
hash2 = (hash2 << 8) | cp[5]; |
|
4717 |
hash2 = (hash2 << 8) | cp[6]; |
|
4718 |
hash2 = (hash2 << 8) | cp[7]; |
|
4719 |
} |
|
20373 | 4720 |
# endif |
19368 | 4721 |
/* |
4722 |
* multiply by large prime to scramble bits and |
|
4723 |
* to avoid a 0 result from |
|
4724 |
* #[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8. |
|
4725 |
*/ |
|
4726 |
hash ^= (hash * 31415821) ^ hash2; |
|
4727 |
} |
|
4728 |
for (hash2 = 0; cp <= ep; cp++) { |
|
4729 |
hash2 = (hash2 << 8) | *cp; |
|
4730 |
} |
|
12757 | 4731 |
#endif |
19368 | 4732 |
hash ^= (hash * 31415821) ^ hash2; |
4733 |
||
4734 |
/* |
|
20372 | 4735 |
* fold the high bits not fitting into a H_INT |
19368 | 4736 |
*/ |
20372 | 4737 |
carry = hash & ~_MAX_H_INT; |
19368 | 4738 |
if (carry) { |
20372 | 4739 |
hash = (hash & _MAX_H_INT) ^ (carry >> 8); |
19368 | 4740 |
} |
4741 |
||
4742 |
RETURN(__mkSmallInteger(hash)); |
|
4743 |
} |
|
12757 | 4744 |
} |
4745 |
%}. |
|
4746 |
||
4747 |
^ self primitiveFailed |
|
4748 |
||
4749 |
" |
|
4750 |
#[1 2 3 4] computeXorHashFrom:1 to:4. |
|
4751 |
#[1 2 3 4] computeXorHashFrom:1 to:32. |
|
4752 |
#[1 2 3 4] computeXorHashFrom:1 to:0. |
|
4753 |
#[1 2 3 4 5] computeXorHashFrom:1 to:4. |
|
4754 |
#[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
4755 |
#[1 2 3 4 5 6 7 8] computeXorHashFrom:2 to:8. |
12757 | 4756 |
#[2 3 4 5 6 7 8] computeXorHashFrom:1 to:7. |
19554 | 4757 |
#[2 3 4 5 6 7 8] computeXorHashFrom:1 to:8. |
4758 |
" |
|
4759 |
! |
|
4760 |
||
4761 |
hash |
|
4762 |
|sz| |
|
4763 |
||
4764 |
sz := self size. |
|
4765 |
sz <= 32 ifTrue:[ |
|
4766 |
^ self computeXorHashFrom:1 to:sz. |
|
4767 |
]. |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
4768 |
^ (sz bitXor:(self computeXorHashFrom:1 to:16)) bitXor:(self computeXorHashFrom:sz-16 to:sz) |
19554 | 4769 |
|
4770 |
" |
|
4771 |
#[1 2 3 4] hash |
|
4772 |
#[1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 |
|
4773 |
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 ] hash |
|
4774 |
#[1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 |
|
4775 |
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1] hash |
|
12757 | 4776 |
" |
4777 |
! ! |
|
4778 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4779 |
!UninterpretedBytes methodsFor:'image manipulation support'! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4780 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4781 |
copyReverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4782 |
"create a copy of myself with elements reversed in order" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4783 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4784 |
^ self copy reverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4785 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4786 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4787 |
#[1 2 3 4 5] copyReverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4788 |
#[1 2 3 4] copyReverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4789 |
" |
19415 | 4790 |
! |
4791 |
||
4792 |
swapBytes |
|
4793 |
"swap bytes (of int16s) inplace - |
|
4794 |
Expects that the receiver has an even number of bytes; |
|
4795 |
if not, only the pairs excluding the last byte are swapped" |
|
4796 |
||
4797 |
|b1 lastIndex "{ Class: SmallInteger }"| |
|
4798 |
||
4799 |
lastIndex := self size-1. |
|
4800 |
1 to:lastIndex by:2 do:[:idx | |
|
4801 |
b1 := self byteAt:idx. |
|
4802 |
self byteAt:idx put:(self byteAt:idx+1). |
|
4803 |
self byteAt:idx+1 put:b1. |
|
4804 |
]. |
|
4805 |
||
4806 |
" |
|
4807 |
#[1 2 3 4 5] swapBytes |
|
4808 |
#[1 2 3 4] swapBytes |
|
4809 |
" |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4810 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4811 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
4812 |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4813 |
!UninterpretedBytes methodsFor:'misc'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4814 |
|
13575 | 4815 |
swapLongAt:byteIndex |
3433 | 4816 |
"swap the byteOrder of a long. |
4817 |
The index is a smalltalk index (i.e. 1-based)." |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4818 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4819 |
|t| |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4820 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4821 |
t := self byteAt:byteIndex. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4822 |
self byteAt:byteIndex put:(self byteAt:(byteIndex + 3)). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4823 |
self byteAt:(byteIndex + 3) put:t. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4824 |
t := self byteAt:(byteIndex + 1). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4825 |
self byteAt:(byteIndex + 1) put:(self byteAt:(byteIndex + 2)). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4826 |
self byteAt:(byteIndex + 2) put:t |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4827 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4828 |
"Created: / 3.4.1998 / 13:37:01 / cg" |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4829 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4830 |
|
18664 | 4831 |
!UninterpretedBytes methodsFor:'printing & storing'! |
4832 |
||
4833 |
hexPrintOn:aStream |
|
4834 |
"print as hex string, eg: 'FF0243'. |
|
4835 |
This string can be used in #fromHexString: to recreate the byteArray" |
|
4836 |
||
4837 |
self hexPrintOn:aStream withSeparator:nil |
|
4838 |
||
4839 |
" |
|
4840 |
#[1 2 3 4 10 17] hexPrintOn:Transcript |
|
4841 |
" |
|
4842 |
||
4843 |
" |
|
4844 |
|s| |
|
4845 |
s := String streamContents:[:s | #[1 2 3 4 10 17] hexPrintOn:s]. |
|
4846 |
ByteArray fromHexString:s |
|
4847 |
" |
|
4848 |
! |
|
4849 |
||
4850 |
hexPrintOn:aStream withSeparator:aSeparatorStringOrCharacterOrNil |
|
4851 |
"print as hex string with separators, eg: 'FF:02:43'" |
|
4852 |
||
4853 |
|first| |
|
4854 |
||
4855 |
first := true. |
|
4856 |
1 to:self size do:[:idx | |
|
19368 | 4857 |
aSeparatorStringOrCharacterOrNil notNil ifTrue:[ |
4858 |
first ifFalse:[ |
|
4859 |
aSeparatorStringOrCharacterOrNil printOn:aStream |
|
4860 |
] ifTrue:[ |
|
4861 |
first := false. |
|
4862 |
]. |
|
4863 |
]. |
|
4864 |
(self byteAt:idx) printOn:aStream base:16 size:2 fill:$0. |
|
18664 | 4865 |
]. |
4866 |
||
4867 |
" |
|
4868 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:$: |
|
4869 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:(Character space) |
|
4870 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:'-' |
|
4871 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:nil |
|
20177 | 4872 |
'hello' hexPrintOn:Transcript withSeparator:'.' |
18664 | 4873 |
" |
4874 |
! |
|
4875 |
||
4876 |
hexPrintString |
|
4877 |
"print as hex string, eg: 'FF0243'. |
|
4878 |
This string can be used in #fromHexString: to recreate the byteArray" |
|
4879 |
||
4880 |
^ self hexPrintStringWithSeparator:nil |
|
4881 |
||
4882 |
" |
|
4883 |
#[1 2 3 4 10 17] hexPrintString |
|
4884 |
ByteArray fromHexString:#[1 2 3 4 10 17] hexPrintString |
|
20176 | 4885 |
'hello' hexPrintString |
18664 | 4886 |
" |
4887 |
||
4888 |
"Modified: / 03-07-2010 / 01:59:19 / cg" |
|
4889 |
! |
|
4890 |
||
4891 |
hexPrintStringWithSeparator:aSeparatorStringOrCharacterOrNil |
|
4892 |
"print as hex string, eg: 'FF:02:43'." |
|
4893 |
||
4894 |
^ String |
|
19368 | 4895 |
streamContents:[:s | |
4896 |
self hexPrintOn:s withSeparator:aSeparatorStringOrCharacterOrNil. |
|
4897 |
] |
|
18664 | 4898 |
|
4899 |
" |
|
4900 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:$: |
|
4901 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:Character space |
|
4902 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:' - ' |
|
4903 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:nil |
|
20176 | 4904 |
'hello' hexPrintStringWithSeparator:'.' |
18664 | 4905 |
" |
4906 |
! ! |
|
4907 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4908 |
!UninterpretedBytes methodsFor:'private'! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4909 |
|
18969 | 4910 |
slowReplaceBytesFrom:startArg to:stopArg with:sourceBytes startingAt:sourceIndex |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4911 |
"fallback if primitive code fails" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4912 |
|
18969 | 4913 |
|srcIdx "{ Class:SmallInteger }" |
4914 |
start "{ Class:SmallInteger }" |
|
4915 |
stop "{ Class:SmallInteger }"| |
|
4916 |
||
4917 |
start := startArg. |
|
4918 |
stop := stopArg. |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4919 |
srcIdx := sourceIndex. |
18969 | 4920 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4921 |
start to:stop do:[:dstIdx | |
18969 | 4922 |
self at:dstIdx put:(sourceBytes at:srcIdx). |
4923 |
srcIdx := srcIdx + 1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4924 |
]. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4925 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4926 |
|
3323 | 4927 |
!UninterpretedBytes methodsFor:'queries'! |
4928 |
||
18616 | 4929 |
containsNon7BitAscii |
18969 | 4930 |
"return true, if the underlying collection contains elements longer than 7 bits |
18616 | 4931 |
(i.e. if it is non-ascii)" |
4932 |
||
4933 |
|sz "{ Class:SmallInteger }"| |
|
4934 |
||
4935 |
sz := self size. |
|
4936 |
1 to:sz do:[:idx| |
|
18969 | 4937 |
(self at:idx) > 16r7F ifTrue:[ |
4938 |
^ true. |
|
4939 |
]. |
|
4940 |
]. |
|
4941 |
^ false. |
|
4942 |
! |
|
4943 |
||
4944 |
containsNon8BitElements |
|
4945 |
"return true, if the underlying structure contains elements larger than a single byte" |
|
4946 |
||
4947 |
|sz "{ Class:SmallInteger }"| |
|
4948 |
||
4949 |
sz := self size. |
|
4950 |
1 to:sz do:[:idx| |
|
4951 |
(self at:idx) > 16rFF ifTrue:[ |
|
4952 |
^ true. |
|
4953 |
]. |
|
18616 | 4954 |
]. |
4955 |
^ false. |
|
4956 |
! |
|
4957 |
||
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4958 |
defaultElement |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4959 |
^ 0 |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4960 |
! |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4961 |
|
21320 | 4962 |
isValidUTF8 |
21323 | 4963 |
"returns true, if the receiver contains a valid UTF8 encoded string" |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
4964 |
|
21323 | 4965 |
|trailing "{ Class: SmallInteger }"| |
4966 |
||
21320 | 4967 |
trailing := 0. |
4968 |
||
4969 |
1 to:self size do:[:idx | |
|
4970 |
|byte "{ Class: SmallInteger }" | |
|
4971 |
||
4972 |
byte := self byteAt:idx. |
|
4973 |
trailing ~~ 0 ifTrue:[ |
|
21323 | 4974 |
(byte bitAnd:2r11000000) == 2r10000000 ifFalse:[^ false]. |
21320 | 4975 |
trailing := trailing - 1. |
4976 |
] ifFalse:[ |
|
4977 |
(byte bitAnd:16r80) == 0 ifTrue:[ |
|
4978 |
"/ continue |
|
4979 |
] ifFalse:[ |
|
21323 | 4980 |
(byte bitAnd:2r11100000) == 2r11000000 ifTrue:[ |
4981 |
"/ strict: should not be encoded this way (could have used a shorter sequence) |
|
4982 |
(byte bitAnd:2r00011110) == 0 ifTrue:[ |
|
21320 | 4983 |
^ false |
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
4984 |
]. |
21320 | 4985 |
trailing := 1. |
4986 |
] ifFalse:[ |
|
21323 | 4987 |
(byte bitAnd:2r11110000) == 2r11100000 ifTrue:[ |
4988 |
trailing := 2. |
|
21320 | 4989 |
] ifFalse:[ |
21323 | 4990 |
(byte bitAnd:2r11111000) == 2r11110000 ifTrue:[ |
4991 |
trailing := 3. |
|
21320 | 4992 |
] ifFalse:[ |
21323 | 4993 |
(byte bitAnd:2r11111100) == 2r11111000 ifTrue:[ |
4994 |
trailing := 4. |
|
21320 | 4995 |
] ifFalse:[ |
21323 | 4996 |
(byte bitAnd:2r11111110) == 2r11111100 ifTrue:[ |
4997 |
trailing := 5. |
|
21320 | 4998 |
] ifFalse:[ |
4999 |
^ false |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5000 |
]. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5001 |
]. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5002 |
]. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5003 |
]. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5004 |
]. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5005 |
]. |
21320 | 5006 |
]. |
5007 |
]. |
|
5008 |
^ trailing == 0 |
|
5009 |
||
5010 |
" |
|
5011 |
'abc' isValidUTF8 |
|
23547
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
23405
diff
changeset
|
5012 |
'abcöäü' isValidUTF8 |
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
23405
diff
changeset
|
5013 |
'abcöäü' utf8Encoded isValidUTF8 |
21323 | 5014 |
(Character value:16r800) utf8Encoded isValidUTF8 |
5015 |
(Character value:16r1000) utf8Encoded isValidUTF8 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5016 |
|
21320 | 5017 |
1 to:255 do:[:c1 | |
5018 |
1 to:255 do:[:c2 | |
|
5019 |
1 to:255 do:[:c3 | |
|
5020 |
self assert:(c1 asCharacter , c2 asCharacter , c3 asCharacter) utf8Encoded isValidUTF8 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5021 |
] |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5022 |
] |
21323 | 5023 |
] |
5024 |
||
5025 |
|s| |
|
5026 |
1 to:10000 do:[:c1 | |
|
5027 |
1 to:255 do:[:c2 | |
|
5028 |
s := (c1 asCharacter , c2 asCharacter). |
|
5029 |
self assert:s utf8Encoded isValidUTF8 |
|
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5030 |
] |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5031 |
] |
21320 | 5032 |
" |
5033 |
! |
|
5034 |
||
18616 | 5035 |
referencesAny:aCollection |
5036 |
"redefined to speed up searching when many of my instances are present" |
|
5037 |
||
5038 |
%{ /* NOCONTEXT */ |
|
5039 |
if (__mkSmallInteger(0) == __ClassInstPtr(__qClass(self))->c_ninstvars) { |
|
19368 | 5040 |
/* I am only bytes */ |
5041 |
RETURN(false) |
|
18616 | 5042 |
} |
5043 |
%}. |
|
5044 |
^ super referencesAny:aCollection |
|
5045 |
||
5046 |
" |
|
19368 | 5047 |
'abc' referencesAny:#() |
18616 | 5048 |
" |
5049 |
! |
|
5050 |
||
3323 | 5051 |
sizeInBytes |
5052 |
"return the number of 8-bit bytes in the receiver. |
|
25420
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5053 |
This is needed since subclasses may redefine #size (TwoByteString)" |
3323 | 5054 |
|
5055 |
^ super size |
|
5056 |
||
5057 |
"Created: / 5.3.1998 / 10:41:13 / stefan" |
|
25420
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5058 |
! |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5059 |
|
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5060 |
utf8DecodedSize |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5061 |
"return the number of characters needed when this string is |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5062 |
decoded from UTF-8" |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5063 |
|
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5064 |
|sz "{ Class:SmallInteger }" |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5065 |
cnt "{ Class:SmallInteger }"| |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5066 |
|
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5067 |
sz := self size. |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5068 |
cnt := 0. |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5069 |
|
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5070 |
1 to:sz do:[:idx| |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5071 |
"/ count the number of UTF-8 start bytes |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5072 |
((self byteAt:idx) bitAnd:16rC0) ~~ 16r80 ifTrue:[ |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5073 |
cnt := cnt+1. |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5074 |
]. |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5075 |
]. |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5076 |
^ cnt. |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5077 |
|
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5078 |
" |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5079 |
'hello world' asByteArray utf8DecodedSize |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5080 |
'ä' utf8Encoded asByteArray utf8DecodedSize |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5081 |
'äΣΔΨӕἤῴ' utf8Encoded asByteArray utf8DecodedSize |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5082 |
" |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5083 |
|
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5084 |
"Created: / 07-02-2017 / 15:03:07 / stefan" |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5085 |
"Modified: / 07-02-2017 / 19:14:06 / stefan" |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5086 |
"Modified (comment): / 02-01-2018 / 18:30:27 / stefan" |
a18d0d048b1f
Cherry-picked changes from eXept, part 4
Jan Vrany <jan.vrany@labware.com>
parents:
25414
diff
changeset
|
5087 |
"Modified (comment): / 15-01-2018 / 08:29:10 / mawalch" |
3323 | 5088 |
! ! |
5089 |
||
8986 | 5090 |
!UninterpretedBytes methodsFor:'testing'! |
5091 |
||
23405
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5092 |
isBigEndian |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5093 |
"Return `true`, if words are stored in big-endian mode, |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5094 |
`false` otherwise. |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5095 |
|
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5096 |
Subclasses that need configurable endianity may overrider |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5097 |
this to return approproate value." |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5098 |
|
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5099 |
^ IsBigEndian |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5100 |
|
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5101 |
! |
90479596f910
Allow subclasses of `UninterpretedBytes` to define endianity
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23107
diff
changeset
|
5102 |
|
8986 | 5103 |
isByteCollection |
5104 |
"return true, if the receiver has access methods for bytes; |
|
5105 |
true is returned here - the method is redefined from Object." |
|
5106 |
||
5107 |
^ true |
|
9005 | 5108 |
! |
5109 |
||
5110 |
isNonByteCollection |
|
5111 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
5112 |
false is returned here - the method is redefined from Collection." |
|
5113 |
||
5114 |
^ false |
|
8986 | 5115 |
! ! |
5116 |
||
11009
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
5117 |
!UninterpretedBytes methodsFor:'visiting'! |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
5118 |
|
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
5119 |
acceptVisitor:aVisitor with:aParameter |
16719 | 5120 |
"dispatch for visitor pattern; send #visitByteArray:with: to aVisitor." |
11009
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
5121 |
|
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
5122 |
^ aVisitor visitByteArray:self with:aParameter |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
5123 |
! ! |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
5124 |
|
695 | 5125 |
!UninterpretedBytes class methodsFor:'documentation'! |
5126 |
||
5127 |
version |
|
18600 | 5128 |
^ '$Header$' |
12253
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
5129 |
! |
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
5130 |
|
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
5131 |
version_CVS |
18600 | 5132 |
^ '$Header$' |
25414
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
5133 |
! |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
5134 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
5135 |
version_HG |
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
5136 |
|
dffa84757e23
Add more compatibility methods to `UninterpretedBytes`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
5137 |
^ '$Changeset: <not expanded> $' |
695 | 5138 |
! ! |
15087 | 5139 |
|
18284 | 5140 |
|
5141 |
UninterpretedBytes initialize! |