mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-05-18 11:43:33 +02:00
Throw in Buffer when there is not enough data to unpack
This commit is contained in:
@@ -12,10 +12,14 @@
|
||||
|
||||
namespace xPaw\SourceQuery;
|
||||
|
||||
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||
|
||||
/**
|
||||
* Class Buffer
|
||||
*
|
||||
* @package xPaw\SourceQuery
|
||||
*
|
||||
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
||||
*/
|
||||
class Buffer
|
||||
{
|
||||
@@ -121,6 +125,11 @@
|
||||
*/
|
||||
public function GetShort( )
|
||||
{
|
||||
if( $this->Remaining( ) < 2 )
|
||||
{
|
||||
throw new InvalidPacketException( 'Not enough data to unpack a short.', InvalidPacketException::BUFFER_EMPTY );
|
||||
}
|
||||
|
||||
$Data = UnPack( 'v', $this->Get( 2 ) );
|
||||
|
||||
return $Data[ 1 ];
|
||||
@@ -133,6 +142,11 @@
|
||||
*/
|
||||
public function GetLong( )
|
||||
{
|
||||
if( $this->Remaining( ) < 4 )
|
||||
{
|
||||
throw new InvalidPacketException( 'Not enough data to unpack a long.', InvalidPacketException::BUFFER_EMPTY );
|
||||
}
|
||||
|
||||
$Data = UnPack( 'l', $this->Get( 4 ) );
|
||||
|
||||
return $Data[ 1 ];
|
||||
@@ -145,6 +159,11 @@
|
||||
*/
|
||||
public function GetFloat( )
|
||||
{
|
||||
if( $this->Remaining( ) < 4 )
|
||||
{
|
||||
throw new InvalidPacketException( 'Not enough data to unpack a float.', InvalidPacketException::BUFFER_EMPTY );
|
||||
}
|
||||
|
||||
$Data = UnPack( 'f', $this->Get( 4 ) );
|
||||
|
||||
return $Data[ 1 ];
|
||||
@@ -157,6 +176,11 @@
|
||||
*/
|
||||
public function GetUnsignedLong( )
|
||||
{
|
||||
if( $this->Remaining( ) < 4 )
|
||||
{
|
||||
throw new InvalidPacketException( 'Not enough data to unpack an usigned long.', InvalidPacketException::BUFFER_EMPTY );
|
||||
}
|
||||
|
||||
$Data = UnPack( 'V', $this->Get( 4 ) );
|
||||
|
||||
return $Data[ 1 ];
|
||||
|
||||
Reference in New Issue
Block a user