protected function readAmf3Int()
{
$int = $this->readByte();
if ($int < 128) {
return $int;
} else {
$int = ($int & 0x7f) << 7;
$tmp = $this->readByte();
if ($tmp < 128) {
return $int | $tmp;
} else {
$int = ($int | $tmp & 0x7f) << 7;
$tmp = $this->readByte();
if ($tmp < 128) {
return $int | $tmp;
} else {
$int = ($int | $tmp & 0x7f) << 8;
$tmp = $this->readByte();
$int |= $tmp;
// Integers in Amf3 are 29 bit. The MSB (of those 29 bit) is the sign bit.
// In order to properly convert that integer to a PHP integer - the system
// might be 32 bit, 64 bit, 128 bit or whatever - all higher bits need to
// be set.
if (($int & 0x10000000) !== 0) {
$int |= ~0x1fffffff;
// extend the sign bit regardless of integer (bit) size
}
return $int;
}
}
}
}