@@ -48,19 +48,17 @@ private static function bytesplit($x, $bytes)
4848
4949 private function flushbits ()
5050 {
51- if (!empty ($ this ->bits )) {
52- $ this ->out .= implode ("" , array_map ('chr ' , $ this ->bits ));
53- $ this ->bits = array ();
54- $ this ->bitcount = 0 ;
55- }
51+ $ this ->out .= implode ("" , array_map ('chr ' , $ this ->bits ));
52+ $ this ->bits = array ();
53+ $ this ->bitcount = 0 ;
5654 }
5755
5856 /**
5957 * Get what's been encoded so far.
6058 */
6159 public function getvalue ()
6260 {
63- $ this ->flushbits ();
61+ if ( $ this -> bitcount ) $ this ->flushbits ();
6462 return $ this ->out ;
6563 }
6664
@@ -69,7 +67,7 @@ public function getvalue()
6967 */
7068 public function write ($ s )
7169 {
72- $ this ->flushbits ();
70+ if ( $ this -> bitcount ) $ this ->flushbits ();
7371 $ this ->out .= $ s ;
7472 return $ this ;
7573 }
@@ -109,7 +107,7 @@ public function write_octet($n)
109107 throw new \InvalidArgumentException ('Octet out of range 0..255 ' );
110108 }
111109
112- $ this ->flushbits ();
110+ if ( $ this -> bitcount ) $ this ->flushbits ();
113111 $ this ->out .= chr ($ n );
114112 return $ this ;
115113 }
@@ -123,7 +121,7 @@ public function write_short($n)
123121 throw new \InvalidArgumentException ('Octet out of range 0..65535 ' );
124122 }
125123
126- $ this ->flushbits ();
124+ if ( $ this -> bitcount ) $ this ->flushbits ();
127125 $ this ->out .= pack ('n ' , $ n );
128126 return $ this ;
129127 }
@@ -133,14 +131,14 @@ public function write_short($n)
133131 */
134132 public function write_long ($ n )
135133 {
136- $ this ->flushbits ();
134+ if ( $ this -> bitcount ) $ this ->flushbits ();
137135 $ this ->out .= implode ("" , AMQPWriter::chrbytesplit ($ n ,4 ));
138136 return $ this ;
139137 }
140138
141139 private function write_signed_long ($ n )
142140 {
143- $ this ->flushbits ();
141+ if ( $ this -> bitcount ) $ this ->flushbits ();
144142 // although format spec for 'N' mentions unsigned
145143 // it will deal with sinned integers as well. tested.
146144 $ this ->out .= pack ('N ' , $ n );
@@ -152,7 +150,7 @@ private function write_signed_long($n)
152150 */
153151 public function write_longlong ($ n )
154152 {
155- $ this ->flushbits ();
153+ if ( $ this -> bitcount ) $ this ->flushbits ();
156154 $ this ->out .= implode ("" , AMQPWriter::chrbytesplit ($ n ,8 ));
157155 return $ this ;
158156 }
@@ -163,7 +161,7 @@ public function write_longlong($n)
163161 */
164162 public function write_shortstr ($ s )
165163 {
166- $ this ->flushbits ();
164+ if ( $ this -> bitcount ) $ this ->flushbits ();
167165 if (strlen ($ s ) > 255 ) {
168166 throw new \InvalidArgumentException ('String too long ' );
169167 }
@@ -179,7 +177,7 @@ public function write_shortstr($s)
179177 */
180178 public function write_longstr ($ s )
181179 {
182- $ this ->flushbits ();
180+ if ( $ this -> bitcount ) $ this ->flushbits ();
183181 $ this ->write_long (strlen ($ s ));
184182 $ this ->out .= $ s ;
185183 return $ this ;
@@ -201,7 +199,7 @@ public function write_timestamp($v)
201199 */
202200 public function write_table ($ d )
203201 {
204- $ this ->flushbits ();
202+ if ( $ this -> bitcount ) $ this ->flushbits ();
205203 $ table_data = new AMQPWriter ();
206204 foreach ($ d as $ k =>$ va ) {
207205 list ($ ftype ,$ v ) = $ va ;
0 commit comments