Exemple #1
0
 /**
  * @param $index
  * @return int
  */
 public function getInt($index)
 {
     $result = $this->readLittleEndian($index, 4);
     $sign = $index + (ByteBuffer::isLittleEndian() ? 3 : 0);
     $issigned = isset($this->_buffer[$sign]) && ord($this->_buffer[$sign]) & 0x80;
     // 4294967296 = 1 << 32 = Maximum unsigned 32-bit int
     return $issigned ? $result - 4294967296 : $result;
 }
 /**
  * @param $index
  * @return int
  */
 public function getInt($index)
 {
     $result = $this->readLittleEndian($index, 4);
     $sign = $index + (ByteBuffer::isLittleEndian() ? 3 : 0);
     $issigned = isset($this->_buffer[$sign]) && ord($this->_buffer[$sign]) & 0x80;
     if (PHP_INT_SIZE > 4) {
         // 4294967296 = 1 << 32 = Maximum unsigned 32-bit int
         return $issigned ? $result - self::UINT + 1 : $result;
     } else {
         // 32bit / Windows treated number as signed integer.
         return $result;
     }
 }
 /**
  * read little endian value from the buffer
  *
  * @param $offset
  * @param $count acutal size
  * @return int
  */
 public function readLittleEndian($offset, $count, $force_bigendian = false)
 {
     $this->assertOffsetAndLength($offset, $count);
     $r = 0;
     if (ByteBuffer::isLittleEndian() && $force_bigendian == false) {
         for ($i = 0; $i < $count; $i++) {
             $r |= ord($this->_buffer[$offset + $i]) << $i * 8;
         }
     } else {
         for ($i = 0; $i < $count; $i++) {
             $r |= ord($this->_buffer[$offset + $count - 1 - $i]) << $i * 8;
         }
     }
     return $r;
 }