author | Martin Kobetic |
Sun, 17 Nov 2013 00:23:18 -0500 | |
changeset 147 | bd6be28aa924 |
parent 111 | 44ac233b2f83 |
permissions | -rw-r--r-- |
10 | 1 |
"{ Package: 'stx:goodies/xtreams/transforms' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
WriteStream subclass:#ObjectWriteStream |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
6 |
instanceVariableNames:'marshaler objects nothing int8 int_16 int_32 int_64 uint_16 |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
7 |
uint_32 uint_64 float_ double_' |
10 | 8 |
classVariableNames:'' |
9 |
poolDictionaries:'' |
|
27
2cc5a8a3ca14
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
10
diff
changeset
|
10 |
category:'Xtreams-Transforms' |
10 | 11 |
! |
12 |
||
13 |
ObjectWriteStream comment:'Marshals objects into a binary destination using the associated ObjectMarshaler. The marshaler version ID is emited at the beginning. |
|
14 |
||
15 |
Instance Variables |
|
16 |
marshaler <ObjectMarshaler> performs marshaling of object bodies |
|
17 |
objects <Array> retains unmarshaled objects for resolution of backward references (to preserve identity) |
|
18 |
longs <InterpretedReadStream> (internal) for reading of longs |
|
19 |
longlongs <InterpretedReadStream> (internal) for reading of longlongs |
|
20 |
floats <InterpretedReadStream> (internal) for reading of floats |
|
21 |
doubles <InterpretedReadStream> (internal) for reading of doubles |
|
22 |
nothing <Object> (internal) an object used to occupy empty slots in objects (since nil is potentially valid content) |
|
23 |
||
24 |
' |
|
25 |
! |
|
26 |
||
27 |
||
28 |
!ObjectWriteStream class methodsFor:'instance creation'! |
|
29 |
||
30 |
on: aDestination |
|
31 |
^self on: aDestination marshaler: ObjectMarshaler new |
|
32 |
! |
|
33 |
||
34 |
on: aDestination marshaler: aMarshaler |
|
35 |
^self new on: aDestination marshaler: aMarshaler |
|
36 |
! ! |
|
37 |
||
38 |
!ObjectWriteStream methodsFor:'accessing'! |
|
39 |
||
40 |
put: object |
|
41 |
marshaler marshal: self object: object. |
|
42 |
self complete. |
|
43 |
^object |
|
44 |
! |
|
45 |
||
46 |
write: anInteger from: aSequenceableCollection at: startIndex |
|
47 |
startIndex to: anInteger + startIndex - 1 do: [:index | |
|
48 |
marshaler marshal: self object: (aSequenceableCollection at: index). |
|
49 |
self complete]. |
|
50 |
^anInteger |
|
51 |
! ! |
|
52 |
||
53 |
!ObjectWriteStream methodsFor:'initialize-release'! |
|
54 |
||
55 |
contentsSpecies |
|
56 |
^Array |
|
57 |
! |
|
58 |
||
59 |
on: aDestination marshaler: aMarshaler |
|
60 |
super on: aDestination. |
|
61 |
marshaler := aMarshaler. |
|
62 |
objects := Array with: Transcript. |
|
63 |
nothing := Object new. |
|
64 |
||
65 |
int8 := aDestination interpreting: #signedChar. |
|
66 |
(marshaler configureMarshal: aDestination) |
|
67 |
ifTrue: [ |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
68 |
int_16 := aDestination interpreting: #signedShort_be. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
69 |
int_32 := aDestination interpreting: #signedLong_be. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
70 |
int_64 := aDestination interpreting: #signedLonglong_be. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
71 |
uint_16 := aDestination interpreting: #unsignedShort_be. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
72 |
uint_32 := aDestination interpreting: #unsignedLong_be. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
73 |
uint_64 := aDestination interpreting: #unsignedLonglong_be] |
10 | 74 |
ifFalse: [ |
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
75 |
int_16 := aDestination interpreting: #signedShort_le. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
76 |
int_32 := aDestination interpreting: #signedLong_le. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
77 |
int_64 := aDestination interpreting: #signedLonglong_le. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
78 |
uint_16 := aDestination interpreting: #unsignedShort_le. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
79 |
uint_32 := aDestination interpreting: #unsignedLong_le. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
80 |
uint_64 := aDestination interpreting: #unsignedLonglong_le]. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
81 |
float_ := aDestination interpreting: #float. |
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
82 |
double_ := aDestination interpreting: #double |
10 | 83 |
! ! |
84 |
||
85 |
!ObjectWriteStream methodsFor:'primitives'! |
|
86 |
||
87 |
double |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
88 |
^double_ |
10 | 89 |
! |
90 |
||
91 |
float |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
92 |
^float_ |
10 | 93 |
! |
94 |
||
95 |
int16 |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
96 |
^int_16 |
10 | 97 |
! |
98 |
||
99 |
int32 |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
100 |
^int_32 |
10 | 101 |
! |
102 |
||
103 |
int64 |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
104 |
^int_64 |
10 | 105 |
! |
106 |
||
107 |
int8 |
|
108 |
^int8 |
|
109 |
! |
|
110 |
||
111 |
uint16 |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
112 |
^uint_16 |
10 | 113 |
! |
114 |
||
115 |
uint32 |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
116 |
^uint_32 |
10 | 117 |
! |
118 |
||
119 |
uint64 |
|
105
ba761aff18ac
Yet another instvar rename, hopefully last.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
72
diff
changeset
|
120 |
^uint_64 |
10 | 121 |
! |
122 |
||
123 |
uint8 |
|
124 |
^destination |
|
125 |
! ! |
|
126 |
||
127 |
!ObjectWriteStream methodsFor:'private'! |
|
128 |
||
129 |
complete |
|
130 |
objects atAllPut: nothing. |
|
131 |
objects at: 1 put: Transcript |
|
132 |
! |
|
133 |
||
134 |
grow |
|
135 |
objects := objects copyWith: nothing |
|
136 |
! |
|
137 |
||
138 |
nothing |
|
139 |
^nothing |
|
140 |
! |
|
141 |
||
142 |
objects |
|
143 |
^objects |
|
144 |
! ! |
|
145 |
||
146 |
!ObjectWriteStream class methodsFor:'documentation'! |
|
147 |
||
111
44ac233b2f83
* removed namespace from pool references and stray extension methods
joe
parents:
105
diff
changeset
|
148 |
version_HG |
44ac233b2f83
* removed namespace from pool references and stray extension methods
joe
parents:
105
diff
changeset
|
149 |
|
44ac233b2f83
* removed namespace from pool references and stray extension methods
joe
parents:
105
diff
changeset
|
150 |
^ '$Changeset: <not expanded> $' |
44ac233b2f83
* removed namespace from pool references and stray extension methods
joe
parents:
105
diff
changeset
|
151 |
! |
44ac233b2f83
* removed namespace from pool references and stray extension methods
joe
parents:
105
diff
changeset
|
152 |
|
10 | 153 |
version_SVN |
154 |
^ '$Id$' |
|
155 |
! ! |
|
111
44ac233b2f83
* removed namespace from pool references and stray extension methods
joe
parents:
105
diff
changeset
|
156 |