author | Claus Gittinger <cg@exept.de> |
Wed, 22 Nov 2000 11:56:15 +0100 | |
changeset 5724 | 96c2a5cf4217 |
parent 5617 | 465796ebb40c |
child 6380 | 457773bd81f9 |
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 |
|
17 |
Object subclass:#ObjectCoder |
|
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, ...) |
|
49 |
implement #encodeOn:with:, which dispatches onto an ObjectCoder. |
|
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 |
||
76 |
encodingOf:anObject |
|
77 |
"return the encoding of anObject" |
|
78 |
||
79 |
^ self new encodingOf:anObject with:nil |
|
80 |
! |
|
81 |
||
82 |
encodingOf:anObject with:aParameter |
|
83 |
"return the encoding of anObject" |
|
84 |
||
85 |
^ self new encodingOf:anObject with:aParameter |
|
86 |
! ! |
|
87 |
||
88 |
!ObjectCoder methodsFor:'decoding'! |
|
89 |
||
90 |
next |
|
91 |
"read, decode and return the next object" |
|
92 |
||
93 |
^ self subclassResponsibility |
|
94 |
||
95 |
||
96 |
! ! |
|
97 |
||
98 |
!ObjectCoder methodsFor:'encoding'! |
|
99 |
||
100 |
encodingOf:anObject |
|
101 |
"answer the encoded argument anObject" |
|
102 |
||
103 |
^ self encodingOf:anObject with:nil |
|
104 |
||
105 |
||
106 |
! |
|
107 |
||
108 |
encodingOf:anObject with:aParameter |
|
109 |
"answer the encoded argument anObject" |
|
110 |
||
111 |
stream isNil ifTrue:[ |
|
112 |
stream := WriteStream on:(ByteArray new:20). |
|
113 |
] ifFalse:[ |
|
114 |
stream reset. |
|
115 |
]. |
|
116 |
||
117 |
anObject encodeOn:self with:aParameter. |
|
118 |
^ stream contents. |
|
119 |
||
120 |
||
121 |
! |
|
122 |
||
123 |
nextPut:anObject |
|
124 |
"encode anObject onto my stream" |
|
125 |
||
126 |
anObject encodeOn:self with:nil. |
|
127 |
||
128 |
! |
|
129 |
||
130 |
nextPutAll:aCollectionOfObjects |
|
131 |
"encode all objects from the argument" |
|
132 |
||
133 |
aCollectionOfObjects do:[:o | |
|
134 |
self nextPut:o |
|
135 |
] |
|
136 |
||
137 |
! ! |
|
138 |
||
139 |
!ObjectCoder methodsFor:'encoding-smalltalk-types'! |
|
140 |
||
141 |
encodeAbsoluteTime:anAbsoluteTime with:aParameter |
|
142 |
"encode an absolute time value" |
|
143 |
||
144 |
self encodeObject:anAbsoluteTime with:aParameter |
|
145 |
||
146 |
||
147 |
! |
|
148 |
||
149 |
encodeBitArray:aBitArray with:aParameter |
|
150 |
"encode a BitArray" |
|
151 |
||
152 |
self encodeObject:aBitArray with:aParameter |
|
153 |
||
154 |
||
155 |
! |
|
156 |
||
157 |
encodeBoolean:aBoolean with:aParameter |
|
158 |
"encode a Boolean" |
|
159 |
||
160 |
self encodeObject:aBoolean with:aParameter |
|
161 |
||
162 |
||
163 |
! |
|
164 |
||
165 |
encodeByteArray:aByteArray with:aParameter |
|
166 |
"encode an absolute time value" |
|
167 |
||
168 |
self encodeObject:aByteArray with:aParameter |
|
169 |
||
170 |
||
171 |
! |
|
172 |
||
173 |
encodeCharacter:aCharacter with:aParameter |
|
174 |
"encode a Character" |
|
175 |
||
176 |
self encodeObject:aCharacter with:aParameter |
|
177 |
||
178 |
||
179 |
! |
|
180 |
||
181 |
encodeDictionary:aDictionary with:aParameter |
|
182 |
"encode a Dictionary" |
|
183 |
||
184 |
self encodeObject:aDictionary with:aParameter |
|
185 |
||
186 |
||
187 |
! |
|
188 |
||
189 |
encodeFloat:aFloat with:aParameter |
|
190 |
"encode a Float" |
|
191 |
||
192 |
self encodeObject:aFloat with:aParameter |
|
193 |
||
194 |
||
195 |
! |
|
196 |
||
197 |
encodeInteger:anInteger with:aParameter |
|
198 |
"encode an Integer" |
|
199 |
||
200 |
self encodeObject:anInteger with:aParameter |
|
201 |
||
202 |
||
203 |
! |
|
204 |
||
205 |
encodeNilWith:aParameter |
|
206 |
"encode a nil" |
|
207 |
||
208 |
self encodeObject:nil with:aParameter |
|
209 |
||
210 |
||
211 |
! |
|
212 |
||
213 |
encodeObject:anObject with:aParameter |
|
214 |
"encode an object. Subclasses must implement this method" |
|
215 |
||
216 |
self subclassResponsibility |
|
217 |
||
218 |
||
219 |
! |
|
220 |
||
221 |
encodeSequencableCollection:aCollection with:aParameter |
|
222 |
"encode a SequencableCollection" |
|
223 |
||
224 |
self encodeObject:aCollection with:aParameter |
|
225 |
||
226 |
||
227 |
! |
|
228 |
||
229 |
encodeSet:aCollection with:aParameter |
|
230 |
"encode a Set" |
|
231 |
||
232 |
self encodeObject:aCollection with:aParameter |
|
233 |
||
234 |
||
235 |
! |
|
236 |
||
237 |
encodeString:aString with:aParameter |
|
238 |
"encode a String" |
|
239 |
||
240 |
self encodeObject:aString with:aParameter |
|
241 |
||
242 |
||
243 |
! |
|
244 |
||
245 |
encodeSymbol:aSymbol with:aParameter |
|
246 |
"encode a Symbol" |
|
247 |
||
248 |
self encodeObject:aSymbol with:aParameter |
|
249 |
||
250 |
||
251 |
! ! |
|
252 |
||
253 |
!ObjectCoder methodsFor:'initialization'! |
|
254 |
||
255 |
close |
|
256 |
"close the underlying stream" |
|
257 |
||
258 |
stream notNil ifTrue:[ |
|
259 |
stream close. |
|
260 |
]. |
|
261 |
||
262 |
||
263 |
! |
|
264 |
||
265 |
reset |
|
266 |
"reset the coder" |
|
267 |
||
268 |
stream notNil ifTrue:[ |
|
269 |
stream reset. |
|
270 |
]. |
|
271 |
||
272 |
||
273 |
! ! |
|
274 |
||
5603
00d09b3135e1
Stream has been made #protected by accident.
Stefan Vogel <sv@exept.de>
parents:
5543
diff
changeset
|
275 |
!ObjectCoder methodsFor:'private - accessing'! |
5477 | 276 |
|
277 |
stream:aStream |
|
5617 | 278 |
stream := aStream. |
279 |
stream signalAtEnd:true. |
|
5477 | 280 |
|
281 |
||
282 |
||
283 |
! ! |
|
284 |
||
285 |
!ObjectCoder class methodsFor:'documentation'! |
|
286 |
||
287 |
version |
|
5617 | 288 |
^ '$Header: /cvs/stx/stx/libbasic/ObjectCoder.st,v 1.4 2000-09-20 08:32:51 stefan Exp $' |
5477 | 289 |
! ! |