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