示例#1
0
 /**
  * Appends AMQP table/array field value to buffer.
  *
  * @param mixed $value
  * @param Buffer $buffer
  */
 public function appendFieldValue($value, Buffer $buffer)
 {
     if (is_string($value)) {
         $buffer->appendUint8(Constants::FIELD_LONG_STRING);
         $buffer->appendUint32(strlen($value));
         $buffer->append($value);
     } elseif (is_int($value)) {
         $buffer->appendUint8(Constants::FIELD_LONG_INT);
         $buffer->appendInt32($value);
     } elseif (is_bool($value)) {
         $buffer->appendUint8(Constants::FIELD_BOOLEAN);
         $buffer->appendUint8(intval($value));
     } elseif (is_float($value)) {
         $buffer->appendUint8(Constants::FIELD_DOUBLE);
         $buffer->appendDouble($value);
     } elseif (is_array($value)) {
         if (array_keys($value) === range(0, count($value) - 1)) {
             // sequential array
             $buffer->appendUint8(Constants::FIELD_ARRAY);
             $this->appendArray($value, $buffer);
         } else {
             $buffer->appendUint8(Constants::FIELD_TABLE);
             $this->appendTable($value, $buffer);
         }
     } elseif (is_null($value)) {
         $buffer->appendUint8(Constants::FIELD_NULL);
     } elseif ($value instanceof \DateTime) {
         $buffer->appendUint8(Constants::FIELD_TIMESTAMP);
         $this->appendTimestamp($value, $buffer);
     } else {
         throw new ProtocolException("Unhandled value type '" . gettype($value) . "' " . (is_object($value) ? "(class " . get_class($value) . ")" : "") . ".");
     }
 }