/** * Writes numeric values for int, uint and double (floating point) vectors to the AMF byte stream. * * @param mixed But should be either an integer (signed or unsigned) or a floating point. * @param string 'i' for signed integers, 'I' for unsigned integers, and 'd' for double precision floating point */ function writeAmf3VectorValue($value, $format) { $bytes = pack($format, $value); if (Amfphp_Core_Amf_Util::isSystemBigEndian()) { $bytes = strrev($bytes); } $this->outBuffer .= $bytes; }
/** * readDouble reads the floating point value from the bytes stream and properly orders * the bytes depending on the system architecture. * * @return float The floating point value of the next 8 bytes */ protected function readDouble() { $bytes = substr($this->rawData, $this->currentByte, 8); $this->currentByte += 8; if (Amfphp_Core_Amf_Util::isSystemBigEndian()) { $bytes = strrev($bytes); } $zz = unpack('dflt', $bytes); // unpack the bytes return $zz['flt']; // return the number from the associative array }
/** * writeDouble takes a float as the input and writes it to the output stream. * Then if the system is big-endian, it reverses the bytes order because all * doubles passed via remoting are passed little-endian. * * @param double $d The double to add to the output buffer */ protected function writeDouble($d) { $b = pack("d", $d); // pack the bytes if (Amfphp_Core_Amf_Util::isSystemBigEndian()) { // if we are a big-endian processor $r = strrev($b); } else { // add the bytes to the output $r = $b; } $this->outBuffer .= $r; }
/** * build date */ public function buildDate() { $this->dDate = new Amfphp_Core_Amf_Types_Date(1306926779576); //1st June 2011 //type: 0x0B $this->sDate = pack('C', 0xb); //date is a double, see writeDouble for little/big endian $dateData = pack('d', 1306926779576); if (Amfphp_Core_Amf_Util::isSystemBigEndian()) { $dateData = strrev($dateData); } $this->sDate .= $dateData; //time zone, not supported. int set to 0 $this->sDate .= pack('n', 0); }
/** * revers packed data if big endian * @see Amfphp_Core_Amf_Util * @param string $packedData * @return string */ private function revIfBigEndian($packedData) { if (Amfphp_Core_Amf_Util::isSystemBigEndian()) { return strrev($packedData); } else { return $packedData; } }
/** * Read numeric values from the AMF byte stream. Please be aware that unsigned integers are not really supported in PHP, and for this reason * unsigned integers are cast to float. {@link http://php.net/manual/en/language.types.integer.php}. * * @param integer You can specify 4 for integers or 8 for double precision floating point. * @param string 'ival' for signed integers, 'Ival' for unsigned integers, and "dval" for double precision floating point * * @return <type> */ protected function readAmf3VectorValue($length, $format) { $bytes = $this->readBuffer($length); if (Amfphp_Core_Amf_Util::isSystemBigEndian()) { $bytes = strrev($bytes); } $array = unpack($format, $bytes); // Unsigned Integers don't work in PHP amazingly enough. If you go into the "upper" region // on the Actionscript side, this will come through as a negative without this cast to a float // see http://php.net/manual/en/language.types.integer.php if ($format === "Ival") { $array["val"] = floatval(sprintf('%u', $array["val"])); } return $array["val"]; }
/** * test system is big endian */ public function testIsSystemBigEndian() { $isBigEndian = Amfphp_Core_Amf_Util::isSystemBigEndian(); $this->assertTrue($isBigEndian == false || $isBigEndian == true); }
/** * build date */ public function buildDate() { $this->dDate = new Amfphp_Core_Amf_Types_Date(1306926779576); //1st June 2011 //type: 0x08 $this->sDate = pack('C', 0x8); //U29D-value = 1. Marker to distinguish from references, I think $this->sDate .= pack('C', 0x1); //date is a double, see writeDouble for little/big endian $dateData = pack('d', 1306926779576); if (Amfphp_Core_Amf_Util::isSystemBigEndian()) { $dateData = strrev($dateData); } $this->sDate .= $dateData; }