Exemplo n.º 1
0
 /**
  * Main parsing function that reads the head code from the stream and returns the appropriate PHP value
  * Thanks to Radu-Adrian Popescu for his patch to 'long' and 'date' deserializing.
  *  
  * @param string code Hessian object code 
  * @return mixed parsed value
  **/
 function &parseObject($code = '')
 {
     if ($code == '') {
         $code = $this->read(1);
     }
     $this->lastCode = $code;
     switch ($code) {
         case 'N':
             return null;
         case 'F':
             return false;
         case 'T':
             return true;
         case 'I':
             $data = unpack('N', $this->read(4));
             return $data[1];
         case 'L':
             return $this->readLong(true);
         case 'd':
             $ts = $this->readLong();
             return $this->dateProvider->readDate($ts);
         case 'D':
             /*
             				2005-09-14:
             				Changed due to the "Fatal error: Only variables can be passed by reference" bug in PHP 5.1 
             old code:
             
             				$bytes = ByteUtils::orderedByteString($this->read(8));
             				$value = each(unpack("d",$bytes));
             				return $value[1];
             */
             $bytes = Hessian_ByteUtils::orderedByteString($this->read(8));
             $val = unpack("d", $bytes);
             $value = array_pop($val);
             return $value;
         case 'B':
         case 'b':
             return $this->readBinary();
         case 'S':
         case 's':
         case 'X':
         case 'x':
             return $this->readString();
         case 'M':
             return $this->parseMap();
         case 'V':
             return $this->parseList();
         case 'R':
             $refStruct = unpack('N', $this->read(4));
             $numRef = $refStruct[1];
             if (isset($this->refs[$numRef])) {
                 return $this->refs[$numRef];
             } else {
                 return new Hessian_HessianError("Unresolved referenced object number {$numRef}", HESSIAN_PARSER_ERROR, 0, $this->stream);
             }
             break;
         case 'z':
             $this->end = true;
             return;
         case 'f':
             return $this->parseFault();
         default:
             return new Hessian_HessianError("Unrecognized response type code '{$code}' or not implemented", HESSIAN_PARSER_ERROR, 0, $this->stream);
     }
 }
Exemplo n.º 2
0
 function writeList(&$value)
 {
     if ($this->writeReference($value)) {
         return;
     }
     $this->stream .= 'V';
     // type, maybe we don't need type info since this is PHP
     $this->stream .= 't';
     $this->writeStringData('');
     // end type info
     if (!empty($value)) {
         $this->stream .= 'l';
         $this->stream .= Hessian_ByteUtils::getIntBytes(count($value), 32);
         foreach ($value as $val) {
             $this->writeObject($val);
         }
     }
     $this->stream .= 'z';
 }
Exemplo n.º 3
0
 /**
  * Returns a sequence of bytes in big endian order, it orders the string depending
  * on machine architecture (big endian or little endian).<BR>
  * 
  * Based in code from Open Sound Control (OSC) Client Library for PHP<BR>
  * Author: Andy W Schmeder &lt;andy@a2hd.com&gt;<BR>
  * Copyright 2003
  *
  * @param string string sequence of bytes to order
  * @return string big endian ordered sequence of bytes
  * @access public 
  **/
 function orderedByteString($string)
 {
     if (Hessian_ByteUtils::isLittleEndian()) {
         $orderStr = '';
         for ($i = 0; $i < strlen($string); $i++) {
             $index = strlen($string) - 1 - $i;
             $orderStr .= $string[$index];
         }
         return $orderStr;
     }
     // No conversion necessary for big-endian architecture
     return $string;
 }