@@ -198,6 +198,7 @@ public void writeBytes(byte[] b, int off, int len) throws IOException {
198198 out .writeByteAndInt ((byte )0xdb , len );
199199 }
200200 out .write (b , off , len );
201+ stack .reduceCount ();
201202 }
202203
203204 @ Override
@@ -216,12 +217,6 @@ public void writeString(String s) throws IOException {
216217 @ Override
217218 public void writeArrayBegin (int size ) throws IOException {
218219 // TODO check size < 0?
219- if (size == 0 ) {
220- stack .reduceCount ();
221- out .writeByte ((byte )0x90 );
222- stack .reduceCount ();
223- return ;
224- }
225220 if (size < 16 ) {
226221 // FixArray
227222 out .writeByte ((byte )(0x90 | size ));
@@ -242,7 +237,7 @@ public void writeArrayEnd(boolean check) throws IOException {
242237 int remain = stack .getTopCount ();
243238 if (remain > 0 ) {
244239 if (check ) {
245- throw new MessageTypeException ("writeArrayEnd(check=true) is called but the array is not end" );
240+ throw new MessageTypeException ("writeArrayEnd(check=true) is called but the array is not end: " + remain );
246241 }
247242 for (int i =0 ; i < remain ; i ++) {
248243 writeNil ();
@@ -255,12 +250,6 @@ public void writeArrayEnd(boolean check) throws IOException {
255250 @ Override
256251 public void writeMapBegin (int size ) throws IOException {
257252 // TODO check size < 0?
258- if (size == 0 ) {
259- stack .reduceCount ();
260- out .writeByte ((byte )0x80 );
261- stack .reduceCount ();
262- return ;
263- }
264253 if (size < 16 ) {
265254 // FixMap
266255 out .writeByte ((byte )(0x80 | size ));
@@ -275,13 +264,13 @@ public void writeMapBegin(int size) throws IOException {
275264 @ Override
276265 public void writeMapEnd (boolean check ) throws IOException {
277266 if (!stack .topIsMap ()) {
278- throw new MessageTypeException ("writeArrayEnd () is called but writeArrayBegin () is not called" );
267+ throw new MessageTypeException ("writeMapEnd () is called but writeMapBegin () is not called" );
279268 }
280269
281270 int remain = stack .getTopCount ();
282271 if (remain > 0 ) {
283272 if (check ) {
284- throw new MessageTypeException ("writeArrayEnd (check=true) is called but the array is not end" );
273+ throw new MessageTypeException ("writeMapEnd (check=true) is called but the map is not end: " + remain );
285274 }
286275 for (int i =0 ; i < remain ; i ++) {
287276 writeNil ();
0 commit comments