author | HG Automerge |
Tue, 10 Jan 2017 13:26:39 +0000 | |
branch | jv |
changeset 21251 | 32f12bea6608 |
parent 19610 | a9a6940944a9 |
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 |
" |
|
5543
02ae5b02191a
re-checkin to force packageID change
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
5477 | 13 |
|
18552 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
8402 | 16 |
AspectVisitor subclass:#ObjectCoder |
5477 | 17 |
instanceVariableNames:'stream' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'System-Storage' |
|
21 |
! |
|
22 |
||
23 |
!ObjectCoder class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2000 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
||
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
43 |
This is an abstract class. Subclasses implement encoding and decoding |
|
44 |
of Objects onto resp. from a stream. Possible coders are ASN.1/BER, |
|
45 |
CORBA/CDR, BOSS, RMI ... |
|
46 |
||
47 |
Classes which implement basic types (Boolean, Integer, Float, ...) |
|
8402 | 48 |
implement the visitor methods #acceptVisitor:with:, which dispatches onto an ObjectCoder. |
5477 | 49 |
|
50 |
[author:] |
|
51 |
Stefan Vogel |
|
52 |
||
53 |
[see also:] |
|
54 |
OSI::ASN1_Coder |
|
55 |
||
56 |
[instance variables:] |
|
57 |
stream <Stream> the stream we read/write the encodings from/to |
|
58 |
||
59 |
[class variables:] |
|
60 |
" |
|
61 |
! ! |
|
62 |
||
63 |
!ObjectCoder class methodsFor:'instance creation'! |
|
64 |
||
65 |
on:aStream |
|
66 |
"return an encoder/decoder for a stream" |
|
67 |
||
68 |
^ self new stream:aStream |
|
69 |
||
70 |
||
71 |
! ! |
|
72 |
||
73 |
!ObjectCoder class methodsFor:'encoding'! |
|
74 |
||
8621
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
75 |
decode:anObject |
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
76 |
"decode anObject" |
6896 | 77 |
|
78 |
^ (self on:anObject readStream) upToEnd |
|
79 |
||
80 |
" |
|
8621
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
81 |
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
|
82 |
Base64Coder decode:'AQL+/w==' |
19588 | 83 |
(Base64Coder decode:(Base64Coder encode:#[1 2 16rFe 16rFF])) = #[1 2 16rFe 16rFF] |
8621
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] |
13720 | 102 |
Base64Coder encode:'hello' |
13931 | 103 |
OSI::BERCoder encode:'hello' |
6896 | 104 |
" |
13720 | 105 |
|
13931 | 106 |
"Modified (comment): / 12-01-2012 / 13:51:23 / cg" |
6896 | 107 |
! |
108 |
||
6705 | 109 |
encode:anObject on:aStream |
18552 | 110 |
self encode:anObject on:aStream with:nil |
6705 | 111 |
! |
112 |
||
113 |
encode:anObject on:aStream with:info |
|
18552 | 114 |
self new encode:anObject on:aStream with:info |
6705 | 115 |
! |
116 |
||
8621
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
117 |
encode:anObject with:aParameter |
5477 | 118 |
"return the encoding of anObject" |
119 |
||
8621
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
120 |
^ 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
|
121 |
! |
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
122 |
|
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
123 |
encodingOf:anObject |
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
124 |
"use #encode:" |
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 |
<resource: #obsolete> |
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
127 |
|
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
128 |
^ self encode:anObject |
6896 | 129 |
|
130 |
" |
|
131 |
Base64Coder encodingOf:#[1 2 16rFe 16rFF] |
|
132 |
" |
|
5477 | 133 |
! |
134 |
||
135 |
encodingOf:anObject with:aParameter |
|
8621
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
136 |
"use #encode:with:" |
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
137 |
|
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
138 |
<resource: #obsolete> |
5477 | 139 |
|
18552 | 140 |
^ self encode:anObject with:aParameter |
5477 | 141 |
! ! |
142 |
||
6479 | 143 |
!ObjectCoder methodsFor:'accessing'! |
144 |
||
145 |
contents |
|
146 |
||
147 |
self flush. |
|
148 |
^ stream contents |
|
149 |
! ! |
|
150 |
||
5477 | 151 |
!ObjectCoder methodsFor:'decoding'! |
152 |
||
153 |
next |
|
154 |
"read, decode and return the next object" |
|
155 |
||
156 |
^ self subclassResponsibility |
|
157 |
||
158 |
||
159 |
! ! |
|
160 |
||
161 |
!ObjectCoder methodsFor:'encoding'! |
|
162 |
||
18553 | 163 |
encode:anObject on:aStream |
164 |
self encode:anObject on:aStream with:nil |
|
165 |
! |
|
166 |
||
18552 | 167 |
encode:anObject on:aStream with:info |
168 |
self stream:aStream. |
|
169 |
self startEncoding. |
|
170 |
anObject acceptVisitor:self with:info. |
|
171 |
self endEncoding. |
|
172 |
! |
|
173 |
||
5477 | 174 |
encodingOf:anObject |
175 |
"answer the encoded argument anObject" |
|
176 |
||
177 |
^ self encodingOf:anObject with:nil |
|
178 |
||
179 |
||
180 |
! |
|
181 |
||
182 |
encodingOf:anObject with:aParameter |
|
183 |
"answer the encoded argument anObject" |
|
184 |
||
185 |
stream isNil ifTrue:[ |
|
6595
94466b4392d4
#emptyWriteStream and #encodeSeqenceableCollection
Stefan Vogel <sv@exept.de>
parents:
6594
diff
changeset
|
186 |
stream := self emptyWriteStream. |
5477 | 187 |
] ifFalse:[ |
188 |
stream reset. |
|
189 |
]. |
|
18552 | 190 |
self startEncoding. |
8621
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
191 |
anObject acceptVisitor:self with:aParameter. |
18552 | 192 |
self endEncoding. |
8621
b57b1e5b2eca
Define #encode: and #decode: instead of #encodingOf: an #decodingOf:
Stefan Vogel <sv@exept.de>
parents:
8402
diff
changeset
|
193 |
|
5477 | 194 |
^ stream contents. |
195 |
! |
|
196 |
||
18552 | 197 |
endEncoding |
198 |
"redefinable - allows subclass to create a file trailer or similar stuff" |
|
199 |
||
200 |
"/ intentionally left blank here |
|
201 |
! |
|
202 |
||
5477 | 203 |
nextPut:anObject |
204 |
"encode anObject onto my stream" |
|
205 |
||
19588 | 206 |
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
|
207 |
! |
5477 | 208 |
|
8369
4ed7a6453f44
only one method sends encodeOn (to allow for easier redefinition)
Claus Gittinger <cg@exept.de>
parents:
7257
diff
changeset
|
209 |
nextPut:anObject with:aParameter |
4ed7a6453f44
only one method sends encodeOn (to allow for easier redefinition)
Claus Gittinger <cg@exept.de>
parents:
7257
diff
changeset
|
210 |
"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
|
211 |
|
8402 | 212 |
anObject acceptVisitor:self with:aParameter. |
5477 | 213 |
! |
214 |
||
215 |
nextPutAll:aCollectionOfObjects |
|
216 |
"encode all objects from the argument" |
|
217 |
||
218 |
aCollectionOfObjects do:[:o | |
|
219 |
self nextPut:o |
|
220 |
] |
|
221 |
||
18552 | 222 |
! |
223 |
||
224 |
startEncoding |
|
225 |
"redefinable - allows subclass to create a file header or similar stuff" |
|
226 |
||
227 |
"/ intentionally left blank here |
|
5477 | 228 |
! ! |
229 |
||
8402 | 230 |
!ObjectCoder methodsFor:'encoding-smalltalk types'! |
231 |
||
232 |
visitBlock:aBlock with:aParameter |
|
233 |
"encoding of blocks is rather difficult and an error by default. |
|
234 |
If your encoder supports this, redefine it there" |
|
235 |
||
236 |
self error:'encoding of blocks is not supported' |
|
237 |
! ! |
|
238 |
||
5477 | 239 |
!ObjectCoder methodsFor:'initialization'! |
240 |
||
241 |
close |
|
242 |
"close the underlying stream" |
|
243 |
||
244 |
stream notNil ifTrue:[ |
|
245 |
stream close. |
|
246 |
]. |
|
247 |
||
248 |
||
249 |
! |
|
250 |
||
6595
94466b4392d4
#emptyWriteStream and #encodeSeqenceableCollection
Stefan Vogel <sv@exept.de>
parents:
6594
diff
changeset
|
251 |
emptyWriteStream |
94466b4392d4
#emptyWriteStream and #encodeSeqenceableCollection
Stefan Vogel <sv@exept.de>
parents:
6594
diff
changeset
|
252 |
"answer an empty stream for writing the encoded object" |
6594 | 253 |
|
6595
94466b4392d4
#emptyWriteStream and #encodeSeqenceableCollection
Stefan Vogel <sv@exept.de>
parents:
6594
diff
changeset
|
254 |
^ self subclassResponsibility |
6594 | 255 |
! |
256 |
||
6479 | 257 |
flush |
258 |
"flush possibly internally buffered data. |
|
259 |
Nothing is done by default. Subclasses may redefine this" |
|
260 |
||
261 |
^ self |
|
262 |
! |
|
263 |
||
5477 | 264 |
reset |
265 |
"reset the coder" |
|
266 |
||
267 |
stream notNil ifTrue:[ |
|
268 |
stream reset. |
|
269 |
]. |
|
270 |
||
271 |
||
272 |
! ! |
|
273 |
||
7257 | 274 |
!ObjectCoder methodsFor:'private-accessing'! |
5477 | 275 |
|
19598 | 276 |
stream |
277 |
"return my input or output stream" |
|
278 |
||
279 |
^ stream |
|
280 |
! |
|
281 |
||
5477 | 282 |
stream:aStream |
19598 | 283 |
"set my input or output stream" |
284 |
||
5617 | 285 |
stream := aStream. |
5477 | 286 |
! ! |
287 |
||
288 |
!ObjectCoder class methodsFor:'documentation'! |
|
289 |
||
290 |
version |
|
18552 | 291 |
^ '$Header$' |
18553 | 292 |
! |
293 |
||
294 |
version_CVS |
|
295 |
^ '$Header$' |
|
5477 | 296 |
! ! |
18552 | 297 |