ObjectCoder.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 18 Jul 2011 16:22:09 +0100
branchjv
changeset 17846 24edc476ac18
parent 17845 7e0cfaac936d
child 17864 e6010e48defb
permissions -rw-r--r--
Merged with /trunk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     1
"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2000 by eXept Software AG
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     4
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    10
 hereby transferred.
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    11
"
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
    12
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
    13
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
    14
5543
02ae5b02191a re-checkin to force packageID change
Claus Gittinger <cg@exept.de>
parents: 5477
diff changeset
    15
"{ Package: 'stx:libbasic' }"
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    16
8402
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
    17
AspectVisitor subclass:#ObjectCoder
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    18
	instanceVariableNames:'stream'
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    19
	classVariableNames:''
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    20
	poolDictionaries:''
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    21
	category:'System-Storage'
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    22
!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    23
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    24
!ObjectCoder class methodsFor:'documentation'!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    25
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    26
copyright
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    27
"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    28
 COPYRIGHT (c) 2000 by eXept Software AG
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    29
              All Rights Reserved
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    30
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    31
 This software is furnished under a license and may be used
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    32
 only in accordance with the terms of that license and with the
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    34
 be provided or otherwise made available to, or used by, any
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    35
 other person.  No title to or ownership of the software is
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    36
 hereby transferred.
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    37
"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    38
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    39
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    40
!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    41
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    42
documentation
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    43
"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    44
    This is an abstract class. Subclasses implement encoding and decoding
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    45
    of Objects onto resp. from a stream. Possible coders are ASN.1/BER,
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    46
    CORBA/CDR, BOSS, RMI ...
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    47
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    48
    Classes which implement basic types (Boolean, Integer, Float, ...)
8402
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
    49
    implement the visitor methods #acceptVisitor:with:, which dispatches onto an ObjectCoder.
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    50
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    51
    [author:]
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    52
         Stefan Vogel
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    53
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    54
    [see also:]
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    55
        OSI::ASN1_Coder
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    56
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    57
    [instance variables:]
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    58
        stream  <Stream>        the stream we read/write the encodings from/to
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    59
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    60
    [class variables:]
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    61
"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    62
! !
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    63
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    64
!ObjectCoder class methodsFor:'instance creation'!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    65
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    66
on:aStream
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    67
    "return an encoder/decoder for a stream"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    68
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    69
    ^ self new stream:aStream
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    70
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    71
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    72
! !
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    73
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    74
!ObjectCoder class methodsFor:'encoding'!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    75
8621
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    76
decode:anObject
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    77
    "decode anObject"
6896
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
    78
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
    79
    ^ (self on:anObject readStream) upToEnd
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
    80
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
    81
    "
8621
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    82
     Base64Coder encode:#[1 2 16rFe 16rFF]
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    83
     Base64Coder decode:'AQL+/w=='    
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    84
    "
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    85
!
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    86
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    87
decodingOf:anObject
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    88
    "use encode"
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    89
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    90
    <resource: #obsolete>
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    91
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    92
    ^ self decode:anObject
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    93
!
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    94
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    95
encode:anObject
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    96
    "encode of anObject"
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    97
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    98
    ^ self new encodingOf:anObject with:nil
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
    99
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   100
    "
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   101
     Base64Coder encode:#[1 2 16rFe 16rFF]
6896
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
   102
    "
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
   103
!
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
   104
6705
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   105
encode:anObject on:aStream
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   106
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   107
    |coder|
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   108
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   109
    coder := self new stream:aStream.
8402
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   110
    anObject acceptVisitor:coder with:nil.
6705
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   111
!
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   112
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   113
encode:anObject on:aStream with:info
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   114
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   115
    |coder|
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   116
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   117
    coder := self new stream:aStream.
8402
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   118
    anObject acceptVisitor:coder with:info.
6705
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   119
!
490a44b0890d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6595
diff changeset
   120
8621
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   121
encode:anObject with:aParameter
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   122
    "return the encoding of anObject"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   123
8621
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   124
    ^ self new encodingOf:anObject with:aParameter
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   125
!
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   126
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   127
encodingOf:anObject
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   128
    "use #encode:"
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   129
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   130
    <resource: #obsolete>
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   131
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   132
    ^ self encode:anObject
6896
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
   133
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
   134
    "
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
   135
     Base64Coder encodingOf:#[1 2 16rFe 16rFF]
ebfdcf4e35e5 utilities
Claus Gittinger <cg@exept.de>
parents: 6705
diff changeset
   136
    "
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   137
!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   138
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   139
encodingOf:anObject with:aParameter
8621
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   140
    "use #encode:with:"
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   141
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   142
    <resource: #obsolete>
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   143
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   144
    ^ self new encodingOf:anObject with:aParameter
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   145
! !
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   146
6479
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   147
!ObjectCoder methodsFor:'accessing'!
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   148
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   149
contents
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   150
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   151
    self flush.
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   152
    ^ stream contents
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   153
! !
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   154
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   155
!ObjectCoder methodsFor:'decoding'!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   156
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   157
next
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   158
    "read, decode and return the next object"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   159
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   160
    ^ self subclassResponsibility
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   161
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   162
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   163
! !
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   164
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   165
!ObjectCoder methodsFor:'encoding'!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   166
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   167
encodingOf:anObject
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   168
    "answer the encoded argument anObject"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   169
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   170
    ^ self encodingOf:anObject with:nil
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   171
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   172
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   173
!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   174
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   175
encodingOf:anObject with:aParameter
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   176
    "answer the encoded argument anObject"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   177
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   178
    stream isNil ifTrue:[
6595
94466b4392d4 #emptyWriteStream and #encodeSeqenceableCollection
Stefan Vogel <sv@exept.de>
parents: 6594
diff changeset
   179
        stream := self emptyWriteStream.
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   180
    ] ifFalse:[
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   181
        stream reset.
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   182
    ].
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   183
8621
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   184
    anObject acceptVisitor:self with:aParameter.
b57b1e5b2eca Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents: 8402
diff changeset
   185
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   186
    ^ stream contents.
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   187
!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   188
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   189
nextPut:anObject
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   190
    "encode anObject onto my stream"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   191
8402
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   192
    self nextPut:anObject with:nil.
8369
4ed7a6453f44 only one method sends encodeOn (to allow for easier redefinition)
Claus Gittinger <cg@exept.de>
parents: 7257
diff changeset
   193
!
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   194
8369
4ed7a6453f44 only one method sends encodeOn (to allow for easier redefinition)
Claus Gittinger <cg@exept.de>
parents: 7257
diff changeset
   195
nextPut:anObject with:aParameter
4ed7a6453f44 only one method sends encodeOn (to allow for easier redefinition)
Claus Gittinger <cg@exept.de>
parents: 7257
diff changeset
   196
    "encode anObject onto my stream"
4ed7a6453f44 only one method sends encodeOn (to allow for easier redefinition)
Claus Gittinger <cg@exept.de>
parents: 7257
diff changeset
   197
8402
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   198
    anObject acceptVisitor:self with:aParameter.
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   199
!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   200
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   201
nextPutAll:aCollectionOfObjects
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   202
    "encode all objects from the argument"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   203
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   204
    aCollectionOfObjects do:[:o |
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   205
        self nextPut:o
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   206
    ]
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   207
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   208
! !
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   209
8402
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   210
!ObjectCoder methodsFor:'encoding-smalltalk types'!
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   211
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   212
visitBlock:aBlock with:aParameter
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   213
    "encoding of blocks is rather difficult and an error by default.
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   214
     If your encoder supports this, redefine it there"
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   215
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   216
    self error:'encoding of blocks is not supported'
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   217
! !
a18732b1f6c4 Use Visitor.
Stefan Vogel <sv@exept.de>
parents: 8369
diff changeset
   218
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   219
!ObjectCoder methodsFor:'initialization'!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   220
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   221
close
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   222
    "close the underlying stream"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   223
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   224
    stream notNil ifTrue:[
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   225
        stream close.
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   226
    ].
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   227
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   228
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   229
!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   230
6595
94466b4392d4 #emptyWriteStream and #encodeSeqenceableCollection
Stefan Vogel <sv@exept.de>
parents: 6594
diff changeset
   231
emptyWriteStream
94466b4392d4 #emptyWriteStream and #encodeSeqenceableCollection
Stefan Vogel <sv@exept.de>
parents: 6594
diff changeset
   232
    "answer an empty stream for writing the encoded object"
6594
d354bbc111d0 Encoding
Stefan Vogel <sv@exept.de>
parents: 6479
diff changeset
   233
6595
94466b4392d4 #emptyWriteStream and #encodeSeqenceableCollection
Stefan Vogel <sv@exept.de>
parents: 6594
diff changeset
   234
    ^ self subclassResponsibility
6594
d354bbc111d0 Encoding
Stefan Vogel <sv@exept.de>
parents: 6479
diff changeset
   235
!
d354bbc111d0 Encoding
Stefan Vogel <sv@exept.de>
parents: 6479
diff changeset
   236
6479
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   237
flush
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   238
    "flush possibly internally buffered data.
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   239
     Nothing is done by default. Subclasses may redefine this"
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   240
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   241
    ^ self
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   242
!
2a0abedfbbd3 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6380
diff changeset
   243
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   244
reset
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   245
    "reset the coder"
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   246
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   247
    stream notNil ifTrue:[
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   248
        stream reset.
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   249
    ].
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   250
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   251
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   252
! !
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   253
7257
b9f0fb923c72 method category rename
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
   254
!ObjectCoder methodsFor:'private-accessing'!
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   255
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   256
stream:aStream
5617
465796ebb40c Set stream as signalAtEnd
Stefan Vogel <sv@exept.de>
parents: 5603
diff changeset
   257
    stream := aStream.
5477
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   258
! !
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   259
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   260
!ObjectCoder class methodsFor:'documentation'!
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   261
299f6883d9b0 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   262
version
17846
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
   263
    ^ '$Id: ObjectCoder.st 10660 2011-07-18 15:22:09Z vranyj1 $'
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
   264
! !