Beispiel #1
0
 /**
  * Returns an Unsigned 16-bit Integer
  *
  * @param  \PhpBinaryReader\BinaryReader $br
  * @param  null                          $length
  * @return int
  * @throws \OutOfBoundsException
  */
 public function read(BinaryReader &$br, $length = null)
 {
     if (!$br->canReadBytes(2)) {
         throw new \OutOfBoundsException('Cannot read 16-bit int, it exceeds the boundary of the file');
     }
     $endian = $br->getEndian() == Endian::ENDIAN_BIG ? $this->endianBig : $this->endianLittle;
     $segment = $br->readFromHandle(2);
     $data = unpack($endian, $segment);
     $data = $data[1];
     if ($br->getCurrentBit() != 0) {
         $data = $this->bitReader($br, $data);
     }
     return $data;
 }