|
Class: BinaryStream
Object
|
+--Stream
|
+--BinaryStream
- Package:
- stx:libcompat
- Category:
- Compatibility-Squeak
- Version:
- rev:
1.4
date: 2021/01/20 11:27:42
- user: cg
- file: BinaryStream.st directory: libcompat
- module: stx stc-classLibrary: libcompat
DO NOT DIRECTLY REFER TO THIS CLASS OR USE IT OTHERWISE IN YOUR CODE:
This is a mimicry class to allow some squeak code to be filed in without changing.
Its protocol is neither complete, nor fully compatible with the corresponding
squeak original class.
This stream is used (in squeak) for storage of binary data in either MSB or LSB
byte order. In contrast to ST/X streams (where the MSB/LSB parameter is passed around
as argument), this one keeps it as a state, and provides the usual nextShort/nextInt
protocol without that parameter.
It is needed to port the Matlab reader (goodies/math).
By default, this stream is in MSB mode (network byte order)
copyrightCOPYRIGHT (c) 2018 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
new
-
return an initialized instance
-
on: aStream
-
return an initialized instance
accessing
-
beBigEndian
-
-
beLittleEndian
-
-
rawStream: anotherStream
-
initialization
-
initialize
-
Invoked when a new instance is created.
misc
-
position
-
-
position: newPosition
-
-
reset
-
reading
-
next: nBytes
-
Read nBytes and return them as a byteArray
-
nextInt16
-
Read two bytes and return the value as a 16-bit signed Integer.
The byteOrder is as specified by my msb instvar:
if true, the value is read with the most-significant byte first,
otherwise the least-significant byte comes first.
-
nextInt32
-
Read four bytes and return the value as a 32-bit signed Integer.
The byteOrder is as specified by my msb instvar:
if true, the value is read with the most-significant byte first,
otherwise the least-significant byte comes first.
-
nextInt64
-
Read four bytes and return the value as a 64-bit signed Integer.
The byteOrder is as specified by my msb instvar:
if true, the value is read with the most-significant byte first,
otherwise the least-significant byte comes first.
-
nextShort
-
Read two bytes and return the value as a 16-bit signed Integer.
The byteOrder is as specified by my msb instvar:
if true, the value is read with the most-significant byte first,
otherwise the least-significant byte comes first.
-
nextUnsignedInt16
-
Read two bytes and return the value as a 16-bit unsigned Integer.
The byteOrder is as specified by my msb instvar:
if true, the value is read with the most-significant byte first,
otherwise the least-significant byte comes first.
-
nextUnsignedInt32
-
Read four bytes and return the value as a 32-bit unsigned Integer.
The byteOrder is as specified by my msb instvar:
if true, the value is read with the most-significant byte first,
otherwise the least-significant byte comes first.
-
nextUnsignedInt64
-
Read four bytes and return the value as a 64-bit unsigned Integer.
The byteOrder is as specified by my msb instvar:
if true, the value is read with the most-significant byte first,
otherwise the least-significant byte comes first.
-
nextUnsignedShort
-
Read two bytes and return the value as a 16-bit unsigned Integer.
The byteOrder is as specified by my msb instvar:
if true, the value is read with the most-significant byte first,
otherwise the least-significant byte comes first.
-
peek
-
more examples to be added:
|bytes rawStream binaryStream val|
bytes := #[1 2 3 4 5 6 7 8 9].
rawStream := bytes readStream.
binaryStream := BinaryStream on:rawStream.
binaryStream beBigEndian.
self assert:((val := binaryStream nextShort) = 16r0102).
self assert:((val := binaryStream nextUnsignedShort) = 16r0304).
binaryStream reset.
binaryStream beLittleEndian.
self assert:((val := binaryStream nextShort) = 16r0201).
self assert:((val := binaryStream nextUnsignedShort) = 16r0403).
|
|