1717//
1818package org .msgpack .packer ;
1919
20+ import java .math .BigInteger ;
21+ import java .nio .ByteBuffer ;
2022import java .io .IOException ;
2123import org .msgpack .type .Value ;
2224import org .msgpack .MessagePack ;
@@ -31,178 +33,228 @@ protected AbstractPacker(MessagePack msgpack) {
3133 }
3234
3335 @ Override
34- public void writeByteArray (byte [] b ) throws IOException {
35- writeByteArray (b , 0 , b .length );
36+ public Packer write (boolean o ) throws IOException {
37+ writeBoolean (o );
38+ return this ;
3639 }
3740
41+ @ Override
42+ public Packer write (byte o ) throws IOException {
43+ writeByte (o );
44+ return this ;
45+ }
3846
3947 @ Override
40- public void writeArrayEnd () throws IOException {
41- writeArrayEnd (true );
48+ public Packer write (short o ) throws IOException {
49+ writeShort (o );
50+ return this ;
4251 }
4352
4453 @ Override
45- public void writeMapEnd () throws IOException {
46- writeMapEnd (true );
54+ public Packer write (int o ) throws IOException {
55+ writeInt (o );
56+ return this ;
57+ }
58+
59+ @ Override
60+ public Packer write (long o ) throws IOException {
61+ writeLong (o );
62+ return this ;
63+ }
64+
65+ @ Override
66+ public Packer write (float o ) throws IOException {
67+ writeFloat (o );
68+ return this ;
69+ }
70+
71+ @ Override
72+ public Packer write (double o ) throws IOException {
73+ writeDouble (o );
74+ return this ;
75+ }
76+
77+ @ Override
78+ public Packer write (Boolean o ) throws IOException {
79+ if (o == null ) {
80+ writeNil ();
81+ } else {
82+ writeBoolean (o );
83+ }
84+ return this ;
85+ }
86+
87+ @ Override
88+ public Packer write (Byte o ) throws IOException {
89+ if (o == null ) {
90+ writeNil ();
91+ } else {
92+ writeByte (o );
93+ }
94+ return this ;
95+ }
96+
97+ @ Override
98+ public Packer write (Short o ) throws IOException {
99+ if (o == null ) {
100+ writeNil ();
101+ } else {
102+ writeShort (o );
103+ }
104+ return this ;
105+ }
106+
107+ @ Override
108+ public Packer write (Integer o ) throws IOException {
109+ if (o == null ) {
110+ writeNil ();
111+ } else {
112+ writeInt (o );
113+ }
114+ return this ;
115+ }
116+
117+ @ Override
118+ public Packer write (Long o ) throws IOException {
119+ if (o == null ) {
120+ writeNil ();
121+ } else {
122+ writeLong (o );
123+ }
124+ return this ;
125+ }
126+
127+ @ Override
128+ public Packer write (BigInteger o ) throws IOException {
129+ if (o == null ) {
130+ writeNil ();
131+ } else {
132+ writeBigInteger (o );
133+ }
134+ return this ;
135+ }
136+
137+ @ Override
138+ public Packer write (Float o ) throws IOException {
139+ if (o == null ) {
140+ writeNil ();
141+ } else {
142+ writeFloat (o );
143+ }
144+ return this ;
145+ }
146+
147+ @ Override
148+ public Packer write (Double o ) throws IOException {
149+ if (o == null ) {
150+ writeNil ();
151+ } else {
152+ writeDouble (o );
153+ }
154+ return this ;
155+ }
156+
157+ @ Override
158+ public Packer write (byte [] o ) throws IOException {
159+ if (o == null ) {
160+ writeNil ();
161+ } else {
162+ writeByteArray (o );
163+ }
164+ return this ;
165+ }
166+
167+ @ Override
168+ public Packer write (byte [] o , int off , int len ) throws IOException {
169+ if (o == null ) {
170+ writeNil ();
171+ } else {
172+ writeByteArray (o , off , len );
173+ }
174+ return this ;
175+ }
176+
177+ @ Override
178+ public Packer write (ByteBuffer o ) throws IOException {
179+ if (o == null ) {
180+ writeNil ();
181+ } else {
182+ writeByteBuffer (o );
183+ }
184+ return this ;
185+ }
186+
187+ @ Override
188+ public Packer write (String o ) throws IOException {
189+ if (o == null ) {
190+ writeNil ();
191+ } else {
192+ writeString (o );
193+ }
194+ return this ;
47195 }
48196
49197 @ Override
50198 public Packer write (Object o ) throws IOException {
51199 if (o == null ) {
52200 writeNil ();
53- return this ;
201+ } else {
202+ Template tmpl = msgpack .lookup (o .getClass ());
203+ tmpl .write (this , o );
54204 }
55- Template tmpl = msgpack .lookup (o .getClass ());
56- tmpl .write (this , o );
57205 return this ;
58206 }
59207
60208 @ Override
61209 public Packer write (Value v ) throws IOException {
62210 if (v == null ) {
63211 writeNil ();
64- return this ;
212+ } else {
213+ v .writeTo (this );
65214 }
66- v .writeTo (this );
67215 return this ;
68216 }
69217
70218
219+
220+ @ Override
221+ public void writeArrayEnd () throws IOException {
222+ writeArrayEnd (true );
223+ }
224+
225+ @ Override
226+ public void writeMapEnd () throws IOException {
227+ writeMapEnd (true );
228+ }
229+
71230 @ Override
72231 public void close () throws IOException {
73232 }
74233
75- // public Packer write(Object o) throws IOException {
76- // msgpack.lookup(o.getClass()).write(this, o);
77- // return this;
78- // }
79- //
80- // public Packer write(Value v) throws IOException {
81- // v.writeTo(this);
82- // return this;
83- // }
84- //
85- // public Packer write(MessagePackable v) throws IOException {
86- // v.writeTo(this);
87- // return this;
88- // }
89- //
90- // public Packer write(boolean v) throws IOException {
91- // writeBoolean(v);
92- // return this;
93- // }
94- //
95- // public Packer write(byte v) throws IOException {
96- // writeByte(v);
97- // return this;
98- // }
99- //
100- // public Packer write(short v) throws IOException {
101- // writeShort(v);
102- // return this;
103- // }
104- //
105- // public Packer write(int v) throws IOException {
106- // writeInt(v);
107- // return this;
108- // }
109- //
110- // public Packer write(long v) throws IOException {
111- // writeLong(v);
112- // return this;
113- // }
114- //
115- // public Packer write(float v) throws IOException {
116- // writeFloat(v);
117- // return this;
118- // }
119- //
120- // public Packer write(double v) throws IOException {
121- // writeDouble(v);
122- // return this;
123- // }
124- //
125- // public Packer write(Boolean v) throws IOException {
126- // if(v == null) {
127- // writeNil();
128- // } else {
129- // writeBoolean(v);
130- // }
131- // return this;
132- // }
133- //
134- // public Packer write(Byte v) throws IOException {
135- // if(v == null) {
136- // writeNil();
137- // } else {
138- // writeByte(v);
139- // }
140- // return this;
141- // }
142- //
143- // public Packer write(Short v) throws IOException {
144- // if(v == null) {
145- // writeNil();
146- // } else {
147- // writeShort(v);
148- // }
149- // return this;
150- // }
151- //
152- // public Packer write(Integer v) throws IOException {
153- // if(v == null) {
154- // writeNil();
155- // } else {
156- // writeInt(v);
157- // }
158- // return this;
159- // }
160- //
161- // public Packer write(Long v) throws IOException {
162- // if(v == null) {
163- // writeNil();
164- // } else {
165- // writeLong(v);
166- // }
167- // return this;
168- // }
169- //
170- // public Packer write(Float v) throws IOException {
171- // if(v == null) {
172- // writeNil();
173- // } else {
174- // writeFloat(v);
175- // }
176- // return this;
177- // }
178- //
179- // public Packer write(Double v) throws IOException {
180- // if(v == null) {
181- // writeNil();
182- // } else {
183- // writeDouble(v);
184- // }
185- // return this;
186- // }
187- //
188- // public Packer write(String s) throws IOException {
189- // writeString(s);
190- // return this;
191- // }
192- //
193- // public Packer write(byte[] b) throws IOException {
194- // writeByteArray(b);
195- // return this;
196- // }
197- //
198- // public Packer write(byte[] b, int off, int len) throws IOException {
199- // writeByteArray(b, off, len);
200- // return this;
201- // }
202- //
203- // //public Packer write(ByteBuffer b) throws IOException {
204- // // writeByteBuffer(b);
205- // // return this;
206- // //}
234+ abstract protected void writeBoolean (boolean v ) throws IOException ;
235+
236+ abstract protected void writeByte (byte v ) throws IOException ;
237+
238+ abstract protected void writeShort (short v ) throws IOException ;
239+
240+ abstract protected void writeInt (int v ) throws IOException ;
241+
242+ abstract protected void writeLong (long v ) throws IOException ;
243+
244+ abstract protected void writeBigInteger (BigInteger v ) throws IOException ;
245+
246+ abstract protected void writeFloat (float v ) throws IOException ;
247+
248+ abstract protected void writeDouble (double v ) throws IOException ;
249+
250+ protected void writeByteArray (byte [] b ) throws IOException {
251+ writeByteArray (b , 0 , b .length );
252+ }
253+
254+ abstract protected void writeByteArray (byte [] b , int off , int len ) throws IOException ;
255+
256+ abstract protected void writeByteBuffer (ByteBuffer bb ) throws IOException ;
257+
258+ abstract protected void writeString (String s ) throws IOException ;
207259}
208260
0 commit comments