eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'BaseNCoder':

Home

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

Class: BaseNCoder


Inheritance:

   Object
   |
   +--Visitor
      |
      +--AspectVisitor
         |
         +--ObjectCoder
            |
            +--BaseNCoder
               |
               +--Base32Coder
               |
               +--Base64Coder

Package:
stx:libbasic2
Category:
System-Storage
Version:
rev: 1.17 date: 2019/03/28 17:08:06
user: stefan
file: BaseNCoder.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Stefan Vogel (stefan@zwerg)

Description:


Abstract superclass of Base64Coder and Base32Coder
Their main entry point API is 
    <BaseNCoder> encode:aStringOrBytes
and
    <BaseNCoder> decode:aString

If the decoder should return a string, use
    <BaseNCoder> decodeAsString:aString.

[examples:]
    Base64Coder encode:'helloWorld'
    
    Base64Coder decode:'aGVsbG9Xb3JsZA=='
    
    Base64Coder decodeAsString:'aGVsbG9Xb3JsZA=='
    

[instance variables:]
    buffer          SmallInteger   buffered data
    bits            SmallInteger   Number of valid bits in buffer
    charCount       SmallInteger   Number of characters since last cr
    atEnd           Boolean        true if end of Base64 string reached

[class variables:]


Related information:



Class protocol:

constants
o  lineLimit
RFC 2045 says: max 76 characters in one line

decoding
o  decodeAsString: encodedString
decode a base-n encoded string.
We already expect a string instead of a ByteArray

initialization
o  initializeMappings
self withAllSubclassesDo:#initialize


** This method raises an error - it must be redefined in concrete classes **

o  mapping

** This method raises an error - it must be redefined in concrete classes **

o  reverseMapping

** This method raises an error - it must be redefined in concrete classes **

o  reverseMappingFor: mapping
initialize class variables

instance creation
o  new

queries
o  isAbstract
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.


Instance protocol:

accessing
o  lineLimit: something
set the line length of the encoded output.
Default is a line length of 76 characters.

If nil, no line breaks will be done.

decoding
o  next
answer the next decoded byte

o  next: count
return the next count bytes of the stream as ByteArray

o  peek
answer the next decoded byte. Do not consume this byte

encoding
o  encodingOf: anObject with: aParameter
(comment from inherited method)
answer the encoded argument anObject

o  visitByteArray: aByteArray with: aParameter
Base64Coder encodingOf:#[1 2 3 4 5 6 255]

o  visitObject: anObject with: aParameter
not defined. Use nextPut or nextPutAll:.
Could encode the printString here

o  visitStream: aStream with: aParameter
Base64Coder encodingOf:#[1 2 3 4 5 6 255]
Base64Coder encodingOf:#[1 2 3 4 5 6 255] readStream

o  visitString: aString with: aParameter
|encoded decoded decoder|

encoded := Base64Coder encode:'hello world'.
decoded := #[] writeStream.
decoder := Base64Coder on:encoded readStream.
[decoder atEnd] whileFalse:[
decoded nextPut:(decoder next).
].
decoded := decoded contents.
decoded asString.

initialization
o  emptyWriteStream
answer an empty stream. We encode as string

o  initialize
must be called if redefined

misc
o  reset
reset to initial state

private
o  basicNext
answer the next decoded byte.
No peekByte handling is done here.

queries
o  atEnd
answer true, if no more bytes can be read

o  binary
switch to binary mode - nothing is done here.
Defined for compatibility with ExternalStream.

o  binary: beBinaryBool
ExternalStream protocol compatibility

o  isStream
we simulate a stream

stream compatibility
o  bufferSizeForBulkCopy

o  nextByte
ExternalStream compatibility

o  nextBytes: count into: anObject
read the next count bytes into an object and return the number of
bytes read. On EOF, 0 is returned.
If the receiver is some socket/pipe-like stream, an exception
is raised if the connection is broken.

The object must have non-pointer indexed instvars (i.e. it must be
a ByteArray, String, Float- or DoubleArray).
If anObject is a string or byteArray and reused, this provides the
fastest possible physical I/O (since no new objects are allocated).

Use with care - non object oriented i/o.
Warning: in general, you cannot use this method to pass data from other
architectures since it does not care for byte order or float representation.

o  nextBytes: numBytes into: anObject startingAt: initialIndex
copy bytes into anObject starting at offset

o  nextBytesInto: anObject startingAt: initialIndex
copy bytes into anObject starting at offset

o  nextInt32MSB: msbFlag
return a signed long (4 bytes) from the stream.
The receiver must support reading of binary bytes.

The msbFlag argument controls if the integer is to be read with
most-significant-byte-first (true) or least-first (false).
This interface is provided to allow talking to external programs,
where it's known that the byte order is some definite one.
If you don't care (i.e. talk to other smalltalks) or you can control the
order, please use the corresponding xxxNet methods, which use a standard
network byte order.

1-to-1 copy from Stream

o  nextPut: aByte
encode aByte on the output stream

o  nextPutAll: aCollection startingAt: first to: last
append the elements with index from first to last
of the argument, aCollection onto the receiver.

o  nextPutBytes: aCollectionOfBytes
encode all objects from the argument

o  skip: numberToSkip
skip numberToSkip objects, return the receiver.
1-to-1 copy from Stream.

o  stringUpToEnd
return a collection of the elements up-to the end

o  upToEnd
return a collection of the elements up-to the end

subclass responsibility
o  fillBuffer
fill buffer with next n characters each representing m bits

** This method raises an error - it must be redefined in concrete classes **

o  flush
flush the remaining bits of buffer.
The number of bits in buffer is not a multiple of m, so we pad
the buffer and signal that padding has been done via $= characters.

** This method raises an error - it must be redefined in concrete classes **

o  nextPutByte: aByte
encode aByte on the output stream

** This method raises an error - it must be redefined in concrete classes **



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 25 Apr 2024 13:55:03 GMT