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