@@ -209,30 +209,75 @@ public function read_table()
209209 while ($ table_data ->tell () < $ tlen ) {
210210 $ name = $ table_data ->read_shortstr ();
211211 $ ftype = $ table_data ->rawread (1 );
212- if ($ ftype == 'S ' ) {
213- $ val = $ table_data ->read_longstr ();
214- } else if ($ ftype == 'I ' ) {
215- $ val = $ table_data ->read_signed_long ();
216- } else if ($ ftype == 'D ' )
217- {
218- $ e = $ table_data ->read_octet ();
219- $ n = $ table_data ->read_signed_long ();
220- $ val = new AMQPDecimal ($ n , $ e );
221- } else if ($ ftype == 'T ' )
222- {
223- $ val = $ table_data ->read_timestamp ();
224- } else if ($ ftype == 'F ' )
225- {
226- $ val = $ table_data ->read_table (); // recursion
227- } else {
228- error_log ("Usupported table field type $ ftype " );
229- $ val = null ;
230- }
212+ $ val = $ table_data ->read_value ($ ftype );
231213 $ result [$ name ] = array ($ ftype ,$ val );
232214 }
233215 return $ result ;
234216 }
235217
218+ /**
219+ * Reads the array in the next value.
220+ *
221+ * @return array
222+ */
223+ public function read_array ()
224+ {
225+ $ this ->bitcount = $ this ->bits = 0 ;
226+
227+ // Determine array length and its end position
228+ $ arrayLength = $ this ->read_php_int ();
229+ $ endOffset = $ this ->offset + $ arrayLength ;
230+
231+ $ result = array ();
232+ // Read values until we reach the end of the array
233+ while ($ this ->offset < $ endOffset ) {
234+ $ fieldType = $ this ->rawread (1 );
235+ $ result [] = $ this ->read_value ($ fieldType );
236+ }
237+
238+ return $ result ;
239+ }
240+
241+ /**
242+ * Reads the next value as the provided field type.
243+ *
244+ * @param string $fieldType the char field type
245+ * @return mixed
246+ */
247+ public function read_value ($ fieldType )
248+ {
249+ $ this ->bitcount = $ this ->bits = 0 ;
250+
251+ $ val = NULL ;
252+ switch ($ fieldType ) {
253+ case 'S ' : // Long string
254+ $ val = $ this ->read_longstr ();
255+ break ;
256+ case 'I ' : // Signed 32-bit
257+ $ val = $ this ->read_signed_long ();
258+ break ;
259+ case 'D ' : // Decimal
260+ $ e = $ this ->read_octet ();
261+ $ n = $ this ->read_signed_long ();
262+ $ val = new AMQPDecimal ($ n , $ e );
263+ break ;
264+ case 'T ' : // Timestamp
265+ $ val = $ this ->read_timestamp ();
266+ break ;
267+ case 'F ' : // Table
268+ $ val = $ this ->read_table ();
269+ break ;
270+ case 'A ' : // Array
271+ $ val = $ this ->read_array ();
272+ break ;
273+ default :
274+ // UNKNOWN TYPE
275+ error_log ("Usupported table field type $ fieldType " );
276+ break ;
277+ }
278+
279+ return $ val ;
280+ }
236281
237282 protected function tell ()
238283 {
0 commit comments