ObjectCoder.st
author Stefan Vogel <sv@exept.de>
Tue, 25 Jun 2002 16:01:05 +0200
changeset 6594 d354bbc111d0
parent 6479 2a0abedfbbd3
child 6595 94466b4392d4
permissions -rw-r--r--
Encoding

"
 COPYRIGHT (c) 2000 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.
"



"{ Package: 'stx:libbasic' }"

AbstractObjectCoder subclass:#ObjectCoder
	instanceVariableNames:'stream'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Storage'
!

!ObjectCoder class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2000 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.
"


!

documentation
"
    This is an abstract class. Subclasses implement encoding and decoding
    of Objects onto resp. from a stream. Possible coders are ASN.1/BER,
    CORBA/CDR, BOSS, RMI ...

    Classes which implement basic types (Boolean, Integer, Float, ...)
    implement #encodeOn:with:, which dispatches onto an ObjectCoder.

    [author:]
         Stefan Vogel

    [see also:]
        OSI::ASN1_Coder

    [instance variables:]
        stream  <Stream>        the stream we read/write the encodings from/to

    [class variables:]
"
! !

!ObjectCoder class methodsFor:'instance creation'!

on:aStream
    "return an encoder/decoder for a stream"

    ^ self new stream:aStream


! !

!ObjectCoder class methodsFor:'encoding'!

encodingOf:anObject
    "return the encoding of anObject"

    ^ self new encodingOf:anObject with:nil
!

encodingOf:anObject with:aParameter
    "return the encoding of anObject"

    ^ self new encodingOf:anObject with:aParameter
! !

!ObjectCoder methodsFor:'accessing'!

contents

    self flush.
    ^ stream contents
! !

!ObjectCoder methodsFor:'decoding'!

next
    "read, decode and return the next object"

    ^ self subclassResponsibility


! !

!ObjectCoder methodsFor:'encoding'!

encodingOf:anObject
    "answer the encoded argument anObject"

    ^ self encodingOf:anObject with:nil


!

encodingOf:anObject with:aParameter
    "answer the encoded argument anObject"

    stream isNil ifTrue:[
        stream := self emptyStream.
    ] ifFalse:[
        stream reset.
    ].

    anObject encodeOn:self with:aParameter.
    ^ stream contents.
!

nextPut:anObject
    "encode anObject onto my stream"

    anObject encodeOn:self with:nil.

!

nextPutAll:aCollectionOfObjects
    "encode all objects from the argument"

    aCollectionOfObjects do:[:o |
        self nextPut:o
    ]

! !

!ObjectCoder methodsFor:'initialization'!

close
    "close the underlying stream"

    stream notNil ifTrue:[
        stream close.
    ].


!

emptyStream
    "answer an empty stream"

    ^ (ByteArray new:20) writeStream.
    "
        ^ self subclassResponsibility
    "
!

flush
    "flush possibly internally buffered data.
     Nothing is done by default. Subclasses may redefine this"

    ^ self
!

reset
    "reset the coder"

    stream notNil ifTrue:[
        stream reset.
    ].


! !

!ObjectCoder methodsFor:'private - accessing'!

stream:aStream
    stream := aStream.
    stream signalAtEnd:true.



! !

!ObjectCoder class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/ObjectCoder.st,v 1.7 2002-06-25 14:01:05 stefan Exp $'
! !