eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'BinaryStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: BinaryStream


Inheritance:

   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

Description:


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) 

copyright

COPYRIGHT (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.

Class protocol:

instance creation
o  new
return an initialized instance

o  on: aStream
return an initialized instance


Instance protocol:

accessing
o  beBigEndian

o  beLittleEndian

o  rawStream: anotherStream

initialization
o  initialize
Invoked when a new instance is created.

misc
o  position

o  position: newPosition

o  reset

reading
o  next: nBytes
Read nBytes and return them as a byteArray

o  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.

o  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.

o  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.

o  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.

o  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.

o  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.

o  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.

o  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.

o  peek


Examples:


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).


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Tue, 10 Dec 2024 08:36:13 GMT