|
Class: UninterpretedBytes
Object
|
+--Collection
|
+--SequenceableCollection
|
+--ArrayedCollection
|
+--UninterpretedBytes
|
+--AbstractNumberVector
|
+--ByteArray
|
+--CharacterArray
|
+--ExternalBytes
|
+--SocketAddress
- Package:
- stx:libbasic
- Category:
- Collections-Abstract
- Version:
- rev:
1.171
date: 2019/08/11 21:49:41
- user: cg
- file: UninterpretedBytes.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
UninterpretedBytes provides the common protocol for byte-storage
containers; concrete subclasses are
ByteArray (which store the bytes within the Smalltalk object memory)
String (knows that the bytes represent characters)
and
ExternalBytes (which store the bytes in the malloc-heap).
UninterpretedBytes itself is abstract, so no instances of it can be created.
[Notice:]
Notice the confusion due to multiple methods with the same
functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:').
The reason is that at the time this class was written,
ST80 did not offer protocol to specify the byteOrder, and
ST/X provided methods ending in 'MSB:' for this.
In the meanwhile, VW added protocol ending in 'bigEndian:',
which has been added here for compatibility.
(certainly a point, where an ansi-standard will help)
ByteArray
String
ExternalBytes
Compatibility-Squeak
-
readHexFrom: aString
-
same as fromHexString: for squeak/Pharo compatibility
usage example(s):
(ByteArray readHexFrom: 'C3A1C3A5C3A6C3B1C386C2A5C3BC')
|
initialization
-
initialize
-
instance creation
-
from: aByteArray
-
return new instance which is a copy of aByteArray
usage example(s):
String from:#[40 41 42]
String with:#[40 41 42 43 44 45 46 47 48 49 50] from:2 to:5
|
-
fromHexString: aString
-
decode a byteArray from a hex string (as generated by hexPrintOn:).
aString should not contain whitespace (only hex chars);
see fromHexStringWithSeparators: for an alternative
usage example(s):
ByteArray fromHexString:'1234FEFF'
ExternalBytes fromHexString:'1234FEFF'
|
usage example(s):
Time millisecondsToRun:[
1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ]
].
|
-
fromHexStringWithSeparators: aString
-
read a bytearray from a printed string representation, where
individual bytes are encoded as two hex digits, optionally separated by whiteSpace.
See also fromHexString:, which does something similar, but does not allow for spaces
usage example(s):
ByteArray fromHexString:'1234FEFF'
ByteArray fromHexStringWithSeparators:' 12 34 FE FF'
|
-
fromPackedString: aString
-
ST-80 compatibility: decode a byteArray from a packed string in which
6bits are encoded per character. The argument, aString must be a multiple
of 4 in size (since 24 is the lcm of 6 and 8).
Every 6 bit packet is encoded as a character in 32..95.
Characters below 32 are ignored (so line breaks can be inserted at any place).
An addition final byte defines how many bytes of the last triple are valid.
This is somewhat like the radix-encoding used in good old PDP11 times ;-)
ST-80 uses this encoding for Images ...
This is a base64 encoding, very similar (but not equal) to the algorithm used in RFC1421.
PS: It took a while to figure that one out ...
PPS: I don't like it ;-)
usage example(s):
ByteArray fromPackedString:(#[1 1 1 1] asPackedString)
ByteArray fromPackedString:(#[1 1 1 1 1] asPackedString)
ByteArray fromPackedString:(#[1 1 1 1 1 1] asPackedString)
ByteArray fromPackedString:(#[1 1 1 1 1 1 1] asPackedString)
ByteArray fromPackedString:(#[1 1 1 1 1 1 1 1] asPackedString)
ByteArray fromPackedString:((ByteArray new:256) asPackedString)
ByteArray fromPackedString:((ByteArray new:128) asPackedString)
ByteArray fromPackedString:((ByteArray new:129) asPackedString)
ByteArray fromPackedString:((ByteArray new:130) asPackedString)
ByteArray fromPackedString:((ByteArray new:131) asPackedString)
ByteArray fromPackedString:((ByteArray new:132) asPackedString)
ByteArray fromPackedString:((ByteArray new:64) asPackedString)
0 to:256 do:[:l |
|orig copy|
0 to:255 do:[:fill |
orig := ByteArray new:l withAll:fill.
copy := ByteArray fromPackedString:(orig asPackedString).
self assert:(orig = copy).
]
]
|
-
uninitializedNew: anInteger
-
return a new instance of the receiver with uninitialized
(i.e. undefined) contents. The indexed elements have any random
value. However, any named instance variables are still nilled.
For use, when contents will be set anyway shortly after - this
is a bit faster than the regular basicNew:, which clears the bytes.
Of course, it only makes a difference for very big ByteArrays, such
as used for images/bitmaps.
Notice: if you want to port code using uninitializedNew: to another
smalltalk, you have to add an 'uninitializedNew: -> basicNew:'-calling
method to the ByteArray class of the other smalltalk.
-
with: aByteArray from: start to: stop
-
return new instance with a copy of aByteArray
beginning at index start up to and including index stop
usage example(s):
String with:#[40 41 42 43 44 45 46 47 48 49 50] from:2 to:5
|
queries
-
isAbstract
-
Return if this class is an abstract class.
True is returned for UninterpretedBytes here; false for subclasses.
Abstract subclasses must redefine this again.
-
isBigEndian
-
return true, if words/shorts store the most-significant
byte first (MSB), false if least-sign.-first (LSB).
Returns
false for vax, intel,
true for m68k, m88k, power, sparc.
Notice: UninterpretedBytes isBigEndian
this is inlined both by stc and the jit compiler
usage example(s):
UninterpretedBytes isBigEndian
|
-
isBuiltInClass
-
return true if this class is known by the run-time-system.
Here, true is returned, since UninterpretedBytes is the superclass of
some builtIn classes (ByteArray & ExternalBytes)
Compatibility
-
doubleWordAt: index
-
return the 4-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
-
doubleWordAt: index MSB: msb
-
return the 4-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first, if the msb-arg is true;
LSB-first otherwise.
-
doubleWordAt: byteIndex put: anInteger
-
set the 4-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value should be in the range 0 to 16rFFFFFFFF
(for negative values, the stored value is not defined).
The value is stored in the machine's natural byte order.
-
doubleWordAt: byteIndex put: anInteger MSB: msb
-
set the 4-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFF.
The value is stored MSB-first if msb is true; LSB-first otherwise.
-
doubleWordAtDoubleWordIndex: int32Index
-
return the unsigned long (int32) at index, anInteger.
Fetching in the machine's natural byte order.
Indices are 1-based and scaled as appropriate to allow
accessing the memory as an array of doubleWord entries.
(i.e. indices are 1, 2, ...)
-
doubleWordAtDoubleWordIndex: int32Index MSB: msb
-
return the unsigned long (int32) at index, anInteger.
Fetching is MSB if msb is true, LSB otherwise.
Indices are 1-based and scaled as appropriate to allow
accessing the memory as an array of doubleWord entries.
(i.e. indices are 1, 2, ...)
-
doubleWordAtDoubleWordIndex: int32Index put: anInteger
-
set the long at index, anInteger.
Storing in the machines natural byte order.
Indices are 1-based and scaled as appropriate to allow
accessing the memory as an array of doubleWord entries.
(i.e. indices are 1, 2, ...)
-
doubleWordAtDoubleWordIndex: int32Index put: anInteger MSB: msb
-
set the long at index, anInteger.
Storing is MSB if msb is true, LSB otherwise.
Indices are 1-based and scaled as appropriate to allow
accessing the memory as an array of doubleWord entries.
(i.e. indices are 1, 2, ...)
-
int16At: byteIndex
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
This may be worth a primitive.
-
int16At: byteIndex MSB: msb
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machines natural byte order.
This may be worth a primitive.
-
int16At: index put: anInteger
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
The value is stored in the machine's natural byteorder
-
int16At: index put: anInteger MSB: bigEndian
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
The value is stored in the byteorder given by bigEndian.
This may be worth a primitive.
-
longAt: index
-
return the 4-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order,
therefore, this should only be used for byte-data which is
only used inside this machine.
To setup data packets which are to be sent to other machines,
or stored into a file, always use longAt:MSB: and specify
a definite byteOrder.
-
longAt: index bigEndian: msb
-
return the 4-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
Depending on msb, the value is retrieved MSB-first or LSB-first.
This may be worth a primitive.
-
longAt: index put: value
-
set the 4-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The value is stored in the machine's natural byte order.
-
longAt: byteIndex put: anInteger bigEndian: msb
-
store a signed long (32bit) integer.
The index is a smalltalk index (i.e. 1-based).
-
longLongAt: index
-
return the 8-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
This may be worth a primitive.
-
longLongAt: index bigEndian: msb
-
return the 8-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the given byte order.
This may be worth a primitive.
-
longLongAt: byteIndex put: anInteger
-
store a signed longLong (64bit) integer.
The index is a smalltalk index (i.e. 1-based).
The value is stored in the machine's natural byte order.
Same as #signedQuadWordAt:put: - for ST80 compatibility.
-
longLongAt: byteIndex put: anInteger bigEndian: msb
-
store a signed longLong (64bit) integer.
The index is a smalltalk index (i.e. 1-based).
Same as #signedQuadWordAt:put: - for ST80 compatibility.
-
quadWordAt: index MSB: msb
-
return the 8-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
Depending on msb, the value is retrieved MSB or LSB-first.
-
quadWordAt: index put: anInteger MSB: msb
-
set the 8-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
Depending on msb, the value is stored MSB-first or LSB-first.
-
shortAt: index
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
This may be worth a primitive.
This is the ST80 equivalent of #signedWordAt:
-
shortAt: index bigEndian: msb
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first, if the msb-arg is true;
LSB-first otherwise.
This is the ST80 equivalent of #signedWordAt:
-
shortAt: index put: value
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
The value is stored in the machine's natural byteorder.
This may be worth a primitive.
This is the ST80 equivalent of #signedWordAt:put:
-
shortAt: index put: value bigEndian: bigEndian
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
The value is stored in the byteorder given by bigEndian.
This may be worth a primitive.
-
signedDoubleWordAt: index
-
return the 4-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
This may be worth a primitive.
-
signedDoubleWordAt: index MSB: msb
-
return the 4-bytes starting at index as a (signed) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first, if the msb-arg is true;
LSB-first otherwise.
-
signedDoubleWordAt: index put: value
-
set the 4-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The value is stored in the machine's natural byte order.
This may be worth a primitive.
-
signedDoubleWordAt: index put: value MSB: msb
-
set the 4-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
Depending on msb, the value is stored MSB-first or LSB-first.
This may be worth a primitive.
-
signedLongAt: index
-
return the 4-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
-
signedLongAt: index put: newValue
-
store a 4-bytes signed value starting at index.
The index is a smalltalk index (i.e. 1-based).
The value is in the machine's natural byte order.
-
signedWordAt: index
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
This may be worth a primitive.
-
signedWordAt: index MSB: msb
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first if the msb-arg is true,
LSB-first otherwise.
This may be worth a primitive.
-
signedWordAt: byteIndex put: anInteger
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
The value is stored in the machine's natural byteorder.
-
signedWordAt: byteIndex put: anInteger MSB: msb
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
The value is stored MSB-first, if the msb-arg is true;
LSB-first otherwise.
-
unsignedLongAt: index
-
return the 4-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
Subclasses may redefine this for better performance.
Same as doubleWordAt: for protocol completeness
-
unsignedLongAt: index bigEndian: msb
-
return the 4-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first, if the msb-arg is true;
LSB-first otherwise.
Subclasses may redefine this for better performance.
Same as doubleWordAt:MSB: for protocol completeness
-
unsignedLongAt: index put: value
-
set the 4-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value should be in the range 0 to 16rFFFFFFFF
(for negative values, the stored value is not defined).
The value is stored in the machine's natural byte order.
Subclasses may redefine this for better performance.
Same as doubleWordAt:put: for protocol completeness
-
unsignedLongAt: index put: aNumber bigEndian: msb
-
set the 4-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFF.
The value is stored MSB-first if msb is true; LSB-first otherwise.
Subclasses may redefine this for better performance.
Same as doubleWordAt:put:MSB: for protocol completeness
-
unsignedLongLongAt: index
-
get the 8-bytes starting at index as (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value will be in the range 0 to 16rFFFFFFFFFFFFFFFF.
The value is fetched in the machine's natural byte order.
-
unsignedLongLongAt: index bigEndian: msb
-
return the 8-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
Depending on msb, the value is retrieved MSB or LSB-first.
-
unsignedLongLongAt: index put: anInteger
-
set the 8-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
The value is stored in the machine's natural byte order.
-
unsignedLongLongAt: index put: anInteger bigEndian: msb
-
set the 8-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
Depending on msb, the value is stored MSB-first or LSB-first.
-
unsignedShortAt: index
-
return the 2-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order
Subclasses may redefine this for better performance.
This is the ST80 equivalent of #wordAt:
-
unsignedShortAt: index bigEndian: msb
-
return the 2-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first (high 8 bits at lower index) if msb is true;
LSB-first (i.e. low 8-bits at lower byte index) if it's false)
-
unsignedShortAt: index put: value
-
set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored in the machine's natural byteorder.
-
unsignedShortAt: index put: value bigEndian: msb
-
set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored LSB-first (i.e. the low 8bits are stored at the
lower index) if msb is false, MSB-first otherwise
-
wordAt: index
-
return the 2-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order
Subclasses may redefine this for better performance.
-
wordAt: index MSB: msb
-
return the 2-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB (high 8 bits at lower index) if msb is true;
LSB-first (i.e. low 8-bits at lower byte index) if it's false.
Notice:
the index is a byte index; thus, this allows for unaligned access to
words on any boundary.
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)
-
wordAt: index put: value
-
set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored in the machine's natural byteorder.
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)
-
wordAt: index put: value MSB: msb
-
set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored LSB-first (i.e. the low 8bits are stored at the
lower index) if msb is false, MSB-first otherwise.
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)
usage example(s):
b := ByteArray new:8.
b wordAt:1 put:16r0102 MSB:false.
b wordAt:3 put:16r0304 MSB:false.
b wordAt:5 put:16r0102 MSB:true.
b wordAt:7 put:16r0304 MSB:true.
b inspect
|
-
wordAtWordIndex: int16Index
-
return the unsigned short (uint16) at index, anInteger.
Fetching in the machine's natural byte order.
Indices are 1-based and scaled as appropriate to allow
accessing the memory as an array of word entries.
(i.e. indices are 1, 2, ...)
-
wordAtWordIndex: int16Index MSB: msb
-
return the unsigned short (uint16) at index, anInteger.
Fetching is MSB if msb is true, LSB otherwise.
Indices are 1-based and scaled as appropriate to allow
accessing the memory as an array of word entries.
(i.e. indices are 1, 2, ...)
-
wordAtWordIndex: int16Index put: anInteger
-
set the unsigned short (uint16) at index, anInteger.
Storing in the machine's natural byte order.
Indices are 1-based and scaled as appropriate to allow
accessing the memory as an array of word entries.
(i.e. indices are 1, 2, ...)
-
wordAtWordIndex: int16Index put: anInteger MSB: msb
-
set the short at index, anInteger.
Storing is MSB if msb is true, LSB otherwise.
Indices are 1-based and scaled as appropriate to allow
accessing the memory as an array of word entries.
(i.e. indices are 1, 2, ...)
Compatibility-Squeak
-
copyFromByteArray: aByteArray
-
copy as much as possible from aByteArray
Compatibility-V'Age
-
uint32At: zeroBasedIndex
-
return the 4-bytes starting at index as (unsigned) Integer.
WARNING: The index is a C index (i.e. 0-based).
The value is retrieved in the machine's natural byte order.
Similar to unsignedInt32At:, except for the index base
-
uint32At: zeroBasedIndex put: anInteger
-
set the 4-bytes starting at index to the value given by (unsigned) Integer.
WARNING: The index is a C index (i.e. 0-based).
The value is stored in the machine's natural byte order.
Similar to unsignedInt32At:put:, except for the index base
accessing-128bit ints
-
signedInt128At: index MSB: msb
-
return the 16-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the given byte order.
This may be worth a primitive.
-
signedInt128At: byteIndex put: anInteger MSB: msb
-
store a signed 128bit integer.
The index is a smalltalk index (i.e. 1-based).
-
unsignedInt128At: byteIndex MSB: msb
-
return the 16-bytes starting at index as an unsigned integer.
The index is a smalltalk index (i.e. 1-based).
Depending on msb, the value is retrieved MSB or LSB-first.
-
unsignedInt128At: byteIndex put: anInteger MSB: msb
-
set the 18-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.
Depending on msb, the value is stored MSB-first or LSB-first.
accessing-arbitrary-long ints
-
nativeIntAt: index
-
return the 4- or 8-bytes (depending on the native integer/pointer size)
starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order,
therefore, this should only be used for byte-data which is
only used inside this machine.
-
nativeIntAt: index put: value
-
set the 4- or 8-bytes (depending on INT-/pointer size) starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The value is stored in the machine's natural byte order.
-
signedIntegerAt: index length: len bigEndian: bigEndian
-
return the n-byte signed integer starting at index.
With n=1, this returns the single signed byte's value,
n=2, a signed short, n=4 a signed int etc.
Useful to extract arbitrary long integers
-
unsignedIntegerAt: index length: len bigEndian: bigEndian
-
return the n-byte unsigned integer starting at index.
With n=1, this returns the single byte's value,
n=2, an unsigned short, n=4 an unsigned int32 etc.
Useful to extract arbitrary long integers
-
unsignedIntegerAt: index put: newValue length: len bigEndian: bigEndian
-
store the n-byte unsigned integer starting at index.
With n=1, this stores a single byte's value,
n=2, an unsigned short, n=4 an unsigned int32 etc.
Useful to replace arbitrary long integers
accessing-bytes
-
bcdByteAt: index
-
return the bcd-value for a byte at index in the range 0..99.
BCD treats nibbles (4-bit) as an encoded decimal number's digits
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)
usage example(s):
#[ 16r55 ] bcdByteAt:1
#[ 16r99 ] bcdByteAt:1
#[ 16rAA ] bcdByteAt:1
|
-
bcdByteAt: index put: aNumber
-
set the byte at index as bcd-value in the range 0..99.
BCD treats nibbles (4-bit) as an encoded decimal number's digits
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)
usage example(s):
(((ByteArray new:1) bcdByteAt:1 put:55; yourself) at:1) hexPrintString
(((ByteArray new:1) bcdByteAt:1 put:99; yourself) at:1) hexPrintString
(((ByteArray new:1) bcdByteAt:1 put:100; yourself) at:1) hexPrintString
(((ByteArray new:1) bcdByteAt:1 put:-1; yourself) at:1) hexPrintString
|
-
byteAt: byteIndex
-
return the byte at byteIndex as an unsigned 8 bit value in the range 0..255.
The index is a smalltalk index (i.e. 1-based).
-
byteAt: byteIndex put: anInteger
-
set the byte at byteIndex as an unsigned 8 bit value in the range 0..255.
The index is a smalltalk index (i.e. 1-based).
-
signedByteAt: byteIndex
-
return the byte at byteIndex as a signed 8 bit value in the range -128..+127.
The index is a smalltalk index (i.e. 1-based).
This may be worth a primitive.
-
signedByteAt: byteIndex put: aSignedByteValue
-
set the byte at byteIndex to aSignedByteValue in the range -128 .. 255
The index is a smalltalk index (i.e. 1-based).
Return the signedByteValue argument.
accessing-floats & doubles
-
doubleAt: index
-
return the 8-bytes starting at index as a Float.
The index is a smalltalk index (i.e. 1-based).
Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
Notice also, that the bytes are expected to be in this machine's
float representation and byte order - if the bytearray originated from another
machine, some conversion is usually needed.
-
doubleAt: index MSB: msb
-
return the 8-bytes starting at index as a Float.
The index is a smalltalk index (i.e. 1-based).
Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
Notice also, that the bytes are expected to be in this machines
float representation - if the bytearray originated from another
machine, some conversion is usually needed.
-
doubleAt: index put: aFloat
-
store the value of the argument, aFloat into the receiver
starting at index.
The index is a smalltalk index (i.e. 1-based).
Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
Notice also, that the bytes are expected to be in this machine's
float representation and byte order - if the bytearray originated from another
machine, some conversion is usually needed.
-
doubleAt: index put: aFloat MSB: msb
-
store the value of the argument, aFloat into the receiver
starting at index.
The index is a smalltalk index (i.e. 1-based).
Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
Notice also, that the bytes are expected to be in this machine's
float representation - if the bytearray originated from another
machine, some conversion is usually needed.
-
floatAt: index
-
return the 4-bytes starting at index as a ShortFloat.
The index is a smalltalk index (i.e. 1-based).
Notice, that (currently) ST/X Floats are what Doubles are in ST-80;
therefore this method reads a 4-byte float from the byteArray and returns
a float object which keeps an 8-byte double internally.
Notice also, that the bytes are expected to be in this machine's
float representation and byte order - if the bytearray originated from another
machine, some conversion is usually needed.
-
floatAt: index MSB: msb
-
return the 4-bytes starting at index as a ShortFloat.
The index is a smalltalk index (i.e. 1-based).
Notice, that (currently) ST/X Floats are what Doubles are in ST-80;
therefore this method reads a 4-byte float from the byteArray and returns
a float object which keeps an 8-byte double internally.
Notice also, that the bytes are expected to be in this machine's
float representation and order - if the bytearray originated from another
machine, some conversion is usually needed.
-
floatAt: index put: aFloat
-
store the 4 bytes of value of the argument, aFloat into the receiver
starting at index.
The index is a smalltalk index (i.e. 1-based).
Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
Notice also, that the bytes are expected to be in this machines
float representation and byte order - if the bytearray originated from another
machine, some conversion is usually needed.
-
floatAt: index put: aFloat MSB: msb
-
store the 4 bytes of value of the argument, aFloat into the receiver
starting at index.
The index is a smalltalk index (i.e. 1-based).
Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
Notice also, that the bytes are expected to be in this machines
float representation - if the bytearray originated from another
machine, some conversion is usually needed.
-
ieeeDoubleAt: index
-
retrieve the 8 bytes starting at index as a float.
The index is a smalltalk index (i.e. 1-based).
The 8 bytes are assumed to be in IEEE floating point single precision
number format in the native byte order.
-
ieeeDoubleAt: index put: aFloat
-
store the value of the argument, aFloat into the receiver
The index is a smalltalk index (i.e. 1-based).
starting at index. Storage is in IEEE floating point double precision format.
(i.e. 8 bytes are stored in the native byte order).
-
ieeeFloatAt: index
-
retrieve the 4 bytes starting at index as a float.
The index is a smalltalk index (i.e. 1-based).
The 4 bytes are assumed to be in IEEE floating point single precision
number format in the native byte order.
-
ieeeFloatAt: index put: aFloat
-
store the value of the argument, aFloat into the receiver
starting at index, which is a smalltalk index (i.e. 1-based).
Storage is in IEEE floating point single precision format.
(i.e. 4 bytes are stored in the native byte order).
Since ST/X floats are really doubles,
the low- order 4 bytes of the precision are lost.
-
longDoubleAt: index
-
return the 16-bytes starting at index as a LongDouble.
The index is a smalltalk index (i.e. 1-based).
Notice, that the C-type long double might have different sizes on different
machines and may only use part of the 16 bytes;
i.e. 10bytes (80bit) as on intel CPUS, 12 bytes (96bits) or 16 bytes (128bits).
Notice also, that the bytes are expected to be in this machine's
long double representation and byte order
- if the bytearray originated from another
machine, some conversion is usually needed.
-
longDoubleAt: index MSB: msb
-
return the 16-bytes starting at index as a LongDouble.
The index is a smalltalk index (i.e. 1-based).
Notice, that the C-type long double has different sizes on different
machines and may only use part of the 16 bytes;
i.e. 10bytes (80bit) as on intel CPUS, 12 bytes (96bits) or 16 bytes (128bits).
Notice also, that the bytes are expected to be in this machine's
long double representation - if the bytearray originated from another
machine, some conversion is usually needed.
-
longDoubleAt: index put: aLongFloat
-
store the value of the argument, aLongFloat as 16 bytes into the receiver
starting at index.
The index is a smalltalk index (i.e. 1-based).
LongFloats are the machine's long double numbers.
Notice that the bytes are expected to be in this machine's
float representation and byte order - if the bytearray originated from another
machine, some conversion is usually needed.
-
longDoubleAt: index put: aLongFloat MSB: msb
-
store the value of the argument, aLongFloat as 16 bytes into the receiver
starting at index.
The index is a smalltalk index (i.e. 1-based).
Notice that the bytes are expected to be in this machine's
float representation - if the bytearray originated from another
machine, some conversion is usually needed.
accessing-longlongs (64bit)
-
signedInt64At: index
-
return the 8-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
This may be worth a primitive.
-
signedInt64At: index MSB: msb
-
return the 8-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the given byte order.
This may be worth a primitive.
-
signedInt64At: byteIndex put: anInteger
-
store a signed longLong (64bit) integer.
The index is a smalltalk index (i.e. 1-based).
The value is stored in the machine's natural byte order.
Same as #signedQuadWordAt:put: - for ST80 compatibility.
-
signedInt64At: byteIndex put: anInteger MSB: msb
-
store a signed longLong (64bit) integer.
The index is a smalltalk index (i.e. 1-based).
Same as #signedQuadWordAt:put: - for ST80 compatibility.
-
signedInt64AtLSB: byteIndex
-
return the 8-bytes starting at index as a signed 64bit Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with least significant byte first
-
signedInt64AtLSB: byteIndex put: anInteger
-
set the 8-bytes starting at index from the signed Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored with least significant byte first.
-
signedInt64AtMSB: byteIndex
-
return the 8-bytes starting at index as a signed 64bit Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with most significant byte first
-
signedInt64AtMSB: byteIndex put: anInteger
-
set the 8-bytes starting at index from the signed Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored with least significant byte first.
-
unsignedInt64At: byteIndex
-
return the 8-bytes starting at index in the machine's native
byteorder as an unsigned integer.
The value is retrieved in the machine's natural byte order.
The index is a smalltalk index (i.e. 1-based)
-
unsignedInt64At: byteIndex MSB: msb
-
return the 8-bytes starting at index as an unsigned integer.
The index is a smalltalk index (i.e. 1-based).
Depending on msb, the value is retrieved MSB or LSB-first.
-
unsignedInt64At: byteIndex put: anInteger
-
set the 8-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
The value is stored in the machine's natural byteorder.
-
unsignedInt64At: byteIndex put: anInteger MSB: msb
-
set the 8-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
Depending on msb, the value is stored MSB-first or LSB-first.
-
unsignedInt64AtLSB: byteIndex
-
return the 8-bytes starting at index as an unsigned 64bit Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with most significant byte first
-
unsignedInt64AtLSB: byteIndex put: anInteger
-
set the 8-bytes starting at index from the unsigned Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored with least significant byte first.
-
unsignedInt64AtMSB: byteIndex
-
return the 8-bytes starting at index as an unsigned 64bit Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with most significant byte first
-
unsignedInt64AtMSB: byteIndex put: anInteger
-
set the 8-bytes starting at index from the unsigned Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored with least significant byte first.
accessing-longs (32bit)
-
signedInt32At: byteIndex
-
return the 4-bytes starting at byteIndex as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order,
therefore, this should only be used for byte-data which is
only used inside this machine.
To setup binary data packets which are to be sent to other machines,
or stored into a file, always use the corresponding xxx:MSB: method
and specify a definite byteOrder.
-
signedInt32At: byteIndex MSB: msb
-
return the 4-bytes starting at byteIndex as a (signed) Integer.
The byteIndex is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first, if the msb-arg is true;
LSB-first otherwise.
-
signedInt32At: byteIndex put: anInteger
-
set the 4-bytes starting at index from the signed Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored in the machine's natural byte order.
-
signedInt32At: byteIndex put: anInteger MSB: msb
-
set the 4-bytes starting at byteIndex from the signed Integer value.
The byteIndex is a smalltalk index (i.e. 1-based).
This is the ST80 version of #signedDoubleWordAt:put:
-
signedInt32AtLSB: byteIndex
-
return the 4-bytes starting at index as a signed 32bit Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with least significant byte first
-
signedInt32AtLSB: byteIndex put: anInteger
-
set the 4-bytes starting at index from the signed Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored with least significant byte first.
-
signedInt32AtMSB: byteIndex
-
return the 4-bytes starting at index as a signed 32bit Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with most significant byte first
-
signedInt32AtMSB: byteIndex put: anInteger
-
set the 4-bytes starting at index from the signed Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored with most significant byte first.
-
unsignedInt32At: byteIndex
-
return the 4-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
-
unsignedInt32At: byteIndex MSB: msb
-
return the 4-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first, if the msb-arg is true;
LSB-first otherwise.
-
unsignedInt32At: byteIndex put: anInteger
-
set the 4-bytes starting at index from the (unsigned) integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFF.
The value is stored in the machine's native byte order
-
unsignedInt32At: byteIndex put: anInteger MSB: msb
-
set the 4-bytes starting at byteIndex from the unsigned Integer value.
The byteIndex is a smalltalk index (i.e. 1-based).
This is the ST80 version of #doubleWordAt:put:
-
unsignedInt32AtLSB: byteIndex
-
return the 4-bytes starting at index as an unsigned 32bit Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with least significant byte first
-
unsignedInt32AtLSB: byteIndex put: anInteger
-
set the 4-bytes starting at index from the unsigned Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored with least significant byte first.
-
unsignedInt32AtMSB: byteIndex
-
return the 4-bytes starting at index as an unsigned 32bit Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with most significant byte first
-
unsignedInt32AtMSB: byteIndex put: anInteger
-
set the 4-bytes starting at index from the unsigned Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
The integer is stored with most significant byte first.
accessing-pointers
-
pointerAt: byteIndex
-
get a pointer starting at byteIndex as ExternalAddress.
The byteIndex is a smalltalk index (i.e. 1-based).
Only aligned accesses are allowed.
The pointer is of native cpu's size (4 or 8 bytes).
This returns an external adress.
-
pointerAt: byteIndex put: value
-
set the pointer starting at byteIndex from the integer or externalAddress value.
The byteIndex is a smalltalk index (i.e. 1-based).
Only aligned accesses are allowed.
The pointer is of native cpu's size (4 or 8 bytes).
The value may be either an ExternalAddress, ExternalBytes or an Integer
-
pointerValueAt: byteIndex
-
get a pointer value starting at byteIndex as unsigned integer.
The byteIndex is a smalltalk index (i.e. 1-based).
Only aligned accesses are allowed.
The pointer is of native cpu's size (4 or 8 bytes).
This returns an int with sizeof the machines's native pointer (4 or 8 bytes)
accessing-shorts (16bit)
-
signedInt16At: byteIndex
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order.
-
signedInt16At: byteIndex MSB: msb
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB (high 8 bits at lower index) if msb is true;
LSB-first (i.e. low 8-bits at lower byte index) if it's false.
Notice:
the index is a byte index; thus, this allows for unaligned access to
words on any boundary.
-
signedInt16At: index put: anInteger
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
The value is stored in the machine's natural byte order.
-
signedInt16At: byteIndex put: anInteger MSB: msb
-
set the 2-bytes starting at byteIndex from the signed integer value.
The byteIndex is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
The value is stored MSB-first, if the msb-arg is true;
LSB-first otherwise.
-
signedInt16AtLSB: byteIndex
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with least significant byte first
-
signedInt16AtLSB: index put: anInteger
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored with least significant byte first
-
signedInt16AtMSB: byteIndex
-
return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with most significant byte first
-
signedInt16AtMSB: index put: anInteger
-
set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored with most significant byte first
-
unsignedInt16At: index
-
return the 2-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machine's natural byte order
-
unsignedInt16At: byteIndex MSB: msb
-
return the 2-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved MSB (high 8 bits at lower index) if msb is true;
LSB-first (i.e. low 8-bits at lower byte index) if it's false.
Notice:
the index is a byte index; thus, this allows for unaligned access to
words on any boundary.
usage example(s):
#[ 16rFF 16r00 ] unsignedInt16At:1 MSB:true
#[ 16rFF 16r00 ] unsignedInt16At:1 MSB:false
#[ 16rFF 16r00 ] unsignedInt16At:2 MSB:true
#[ 16rFF 16r00 ] unsignedInt16At:2 MSB:false
|
-
unsignedInt16At: index put: anInteger
-
set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored in the machine's natural byteorder.
-
unsignedInt16At: byteIndex put: anInteger MSB: msb
-
set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored LSB-first (i.e. the low 8bits are stored at the
lower index) if msb is false, MSB-first otherwise
-
unsignedInt16AtLSB: byteIndex
-
return the 2-bytes starting at index as an unsigned Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with least significant byte first
-
unsignedInt16AtLSB: index put: anInteger
-
set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored with least significant byte first
-
unsignedInt16AtMSB: byteIndex
-
return the 2-bytes starting at index as an unsigned Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved with most significant byte first
-
unsignedInt16AtMSB: index put: anInteger
-
set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored with most significant byte first
accessing-strings
-
stringAt: index
-
return a string starting at index up to the 0-byte.
The index is a smalltalk index (i.e. 1-based).
usage example(s):
#[71 72 73 74 75 76 77 0] stringAt:1
#[71 72 73 74 75 76 77 0] stringAt:2
'1234567890' stringAt:2
|
-
stringAt: index put: aString
-
copy aString to the receiver, starting at index up to
(and including) the 0-byte (which is always written).
The index is a smalltalk index (i.e. 1-based).
usage example(s):
(String new:20) stringAt:1 put:'hello'; stringAt:6 put:' world'; yourself
|
-
stringAt: index put: aString size: maxSize
-
copy aString to the receiver, starting at index up to either maxSize characters,
or (and including) the 0-byte, whichever is encountered first.
The final 0-byte is only written, if the string is shorter than maxSize.
The index is a smalltalk index (i.e. 1-based).
usage example(s):
(String new:20) stringAt:1 put:'hello' size:3 ; stringAt:4 put:' world' size:4; yourself
|
-
stringAt: index size: maxSize
-
return a string starting at index up to maxSize, or a 0-byte.
The index is a smalltalk index (i.e. 1-based).
usage example(s):
#[71 72 73 74 75 76 77] stringAt:1 size:7
#[71 72 73 74 75 76 77] stringAt:2 size:6
'1234567890' stringAt:2 size:6
|
-
zeroByteStringAt: index maximumSize: count
-
extract a zeroByte-delimited string, given initial index and
maximum number of characters (bytes).
The index is a smalltalk index (i.e. 1-based).
usage example(s):
#[ 1 2 3 4 5 6 7 8 ] zeroByteStringAt:2 maximumSize:10
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:10
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:3
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:4
|
converting
-
asExternalBytes
-
in earlier times, this use to return protected memory
(i.e. it would not be garbage collected, and the user had to free it manually).
This was changed to now return garbage collected memory.
usage example(s):
#[1 2 3 4 5 6 7] asExternalBytes
'Hello World' asExternalBytes
'Hello World' asUnicodeString asExternalBytes
|
-
asExternalBytesUnprotected
-
Like asExternalBytes, but does not protect the bytes from the collector,
so the bytes are GARBAGE-COLLECTED
(i.e. free is called when the smalltalk object is no longer referenced).
-
asSingleByteString
-
return the receiver converted to a 'normal' string.
Raises an error if unrepresentable characters are encountered.
See also: #asSingleByteStringIfPossible and #asSingleByteStringReplaceInvalidWith:
usage example(s):
#[60 61 62 63] asSingleByteString
#[60 61 62 63] asExternalBytes asSingleByteString
#[67 68 69 70] asIntegerArray asSingleByteString
'abc' asText asSingleByteString
(Unicode16String with:(Character value:16rFF)) asSingleByteString
(Unicode16String with:(Character value:16rFFFF)) asSingleByteString
|
-
asSingleByteStringIfPossible
-
if possible, return the receiver converted to a 'normal' string.
It is only possible, if there are no characters with codePoints above 255 in the receiver.
If not possible, the (wideString) receiver is returned.
usage example(s):
#[67 68 69 70] asSingleByteStringIfPossible
#[67 68 69 70] asIntegerArray asSingleByteStringIfPossible
'hello' asUnicodeString asSingleByteStringIfPossible
|
-
asUUID
-
encoding & decoding
-
base64Decoded
-
'abc' base64Encoded base64Decoded
#[1 2 3] base64Encoded base64Decoded
-
base64Encoded
-
'abc' base64Encoded
#[1 2 3] base64Encoded
-
utf8Decoded
-
Interpreting myself as an UTF-8 representation, decode and return the decoded string.
usage example(s):
#[16rC8 16rA0] utf8Decoded
#[16rC8 16rA0] asString utf8Decoded
#[16rC8 16rA0] asExternalBytes utf8Decoded
(Character value:16r220) utf8Encoded utf8Decoded
(Character value:16r800) utf8Encoded
(Character value:16r220) utf8Encoded utf8Decoded
|
-
utf8DecodedWithTwoByteCharactersReplacedBy: replacementCharacter
-
Interpreting myself as an UTF-8 representation, decode and return
the decoded string. Suppress all 2-byte (above 16rFF) characters,
and replace them with replacementCharacter
usage example(s):
(Character value:16r220) utf8Encoded
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space)
(Character value:16r220) utf8Encoded asExternalBytes copyButLast
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space)
|
filling & replacing
-
replaceBytesFrom: start to: stop with: aCollection startingAt: repStart
-
replace elements from another collection, which must be a ByteArray-
like collection.
Notice: This operation modifies the receiver, NOT a copy;
therefore the change may affect all others referencing the receiver.
-
replaceBytesFrom: startIndex with: replacementCollection startingAt: repStartIndex
-
replace elements from another collection, which must be
byte-array-like.
Notice: This operation modifies the receiver, NOT a copy;
therefore the change may affect all others referencing the receiver.
-
replaceBytesWith: replacementCollection
-
replace elements from another collection, which must be byte-array-like.
Replace stops at whichever collection is smaller.
Notice: This operation modifies the receiver, NOT a copy;
therefore the change may affect all others referencing the receiver.
usage example(s):
(ByteArray new:10) replaceBytesWith:'hello'
(ByteArray new:10) replaceBytesWith:'hello world bla bla bla'
|
-
replaceFrom: startIndex to: stopIndex with: aCollection startingAt: repStartIndex
-
replace elements in the receiver between index start and stop,
with elements taken from replacementCollection starting at repStart.
Return the receiver.
Notice: This operation modifies the receiver, NOT a copy;
therefore the change may affect all others referencing the receiver.
hashing
-
computeXorHashFrom: startIndex to: endIndex
-
compute and answer the 32bit SmallInteger-Hash of the bytes
from startIndex to endIndex.
If endindex = 0 or endIndex > size, hash up the size.
NOTE: startIndex and endIndex are only hints about what should be hashed.
In fact, more bytes could be involved in hashing.
SO ARRAYS MUST BE EQUAL TO HASH TO THE SAME VALUE.
Also NOTE:
used to return a 32bit hash on 32bit machines and a 64bit integer on 64bit cpus.
changed to return the same for all (in case hash values are used for other purposes).
usage example(s):
#[1 2 3 4] computeXorHashFrom:1 to:4.
#[1 2 3 4] computeXorHashFrom:1 to:32.
#[1 2 3 4] computeXorHashFrom:1 to:0.
#[1 2 3 4 5] computeXorHashFrom:1 to:4.
#[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8.
#[1 2 3 4 5 6 7 8] computeXorHashFrom:2 to:8.
#[2 3 4 5 6 7 8] computeXorHashFrom:1 to:7.
#[2 3 4 5 6 7 8] computeXorHashFrom:1 to:8.
|
-
hash
-
the code below is actually not doing what was intended (to take the hashes of the first 16
usage example(s):
However, we will not change it, but keep it that way, in case the hashvalue already found
|
usage example(s):
#[1 2 3 4] hash
#[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
#[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 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
#[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 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
|
image manipulation support
-
copyReverse
-
create a copy of myself with elements reversed in order
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
swapBytes
-
swap bytes (of int16s) inplace -
Expects that the receiver has an even number of bytes;
if not, only the pairs excluding the last byte are swapped
usage example(s):
#[1 2 3 4 5] swapBytes
#[1 2 3 4] swapBytes
|
inspecting
-
inspector2Tabs ( an extension from the stx:libtool package )
-
(comment from inherited method)
add a graph-tab; but only if all my values are numerical
misc
-
copyToEndInto: aStream
-
copy all of myself into aStream. Compatibility with Stream
-
swapLongAt: byteIndex
-
swap the byteOrder of a long.
The index is a smalltalk index (i.e. 1-based).
printing & storing
-
hexPrintOn: aStream
-
print as hex string, eg: 'FF0243'.
This string can be used in #fromHexString: to recreate the byteArray
usage example(s):
#[1 2 3 4 10 17] hexPrintOn:Transcript
|
-
hexPrintOn: aStream withSeparator: aSeparatorStringOrCharacterOrNil
-
print as hex string with separators, eg: 'FF:02:43'
usage example(s):
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:$:
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:(Character space)
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:'-'
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:nil
'hello' hexPrintOn:Transcript withSeparator:'.'
|
-
hexPrintString
-
print as hex string, eg: 'FF0243'.
This string can be used in #fromHexString: to recreate the byteArray
usage example(s):
#[1 2 3 4 10 17] hexPrintString
ByteArray fromHexString:#[1 2 3 4 10 17] hexPrintString
'hello' hexPrintString
|
-
hexPrintStringWithSeparator: aSeparatorStringOrCharacterOrNil
-
print as hex string, eg: 'FF:02:43'.
usage example(s):
#[1 2 3 4 10 17] hexPrintStringWithSeparator:$:
#[1 2 3 4 10 17] hexPrintStringWithSeparator:Character space
#[1 2 3 4 10 17] hexPrintStringWithSeparator:' - '
#[1 2 3 4 10 17] hexPrintStringWithSeparator:nil
'hello' hexPrintStringWithSeparator:'.'
|
private
-
reportError: failReason with: parameter
-
common helper
-
slowReplaceBytesFrom: startArg to: stopArg with: sourceBytes startingAt: sourceIndex
-
fallback if primitive code fails
queries
-
containsNon7BitAscii
-
return true, if the underlying collection contains elements longer than 7 bits
(i.e. if it is non-ascii)
-
containsNon8BitElements
-
return true, if the underlying structure contains elements larger than a single byte
-
defaultElement
-
-
isAllocated
-
for compatibility with ExternalBytes
-
isNull
-
for compatibility with ExternalBytes
-
isValidUTF8
-
returns true, if the receiver contains a valid UTF8 encoded string
usage example(s):
'abc' isValidUTF8
'abcöäü' isValidUTF8
'abcöäü' utf8Encoded isValidUTF8
(Character value:16r800) utf8Encoded isValidUTF8
(Character value:16r1000) utf8Encoded isValidUTF8
1 to:255 do:[:c1 |
1 to:255 do:[:c2 |
1 to:255 do:[:c3 |
self assert:(c1 asCharacter , c2 asCharacter , c3 asCharacter) utf8Encoded isValidUTF8
]
]
]
|s|
1 to:10000 do:[:c1 |
1 to:255 do:[:c2 |
s := (c1 asCharacter , c2 asCharacter).
self assert:s utf8Encoded isValidUTF8
]
]
|
-
referencesAny: aCollection
-
redefined to speed up searching when many of my instances are present
usage example(s):
-
sizeInBytes
-
return the number of 8-bit bytes in the receiver.
This is needed since subclasses may redefine #size (TwoByteString)
-
utf8DecodedSize
-
return the number of characters needed when this string is
decoded from UTF-8
usage example(s):
'hello world' asByteArray utf8DecodedSize
'ä' utf8Encoded asByteArray utf8DecodedSize
'äΣΔΨӕἤῴ' utf8Encoded asByteArray utf8DecodedSize
|
testing
-
isByteCollection
-
return true, if the receiver has access methods for bytes;
This is different from 'self class isBytes',
true is returned here - the method is redefined from Object.
-
isNonByteCollection
-
return true, if the receiver is some kind of collection, but not a String, ByteArray etc.;
false is returned here - the method is redefined from Collection.
-
isSingleByteCollection
-
return true, if the receiver has access methods for bytes;
i.e. #at: and #at:put: accesses a byte and are equivalent to #byteAt: and byteAt:put:
and #replaceFrom:to: is equivalent to #replaceBytesFrom:to:.
This is different from 'self class isBytes',
true is returned here - the method is redefined from Object.
visiting
-
acceptVisitor: aVisitor with: aParameter
-
dispatch for visitor pattern; send #visitByteArray:with: to aVisitor.
|