mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-05-18 14:53: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;
|
namespace xPaw\SourceQuery;
|
||||||
|
|
||||||
|
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Buffer
|
* Class Buffer
|
||||||
*
|
*
|
||||||
* @package xPaw\SourceQuery
|
* @package xPaw\SourceQuery
|
||||||
|
*
|
||||||
|
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
||||||
*/
|
*/
|
||||||
class Buffer
|
class Buffer
|
||||||
{
|
{
|
||||||
@@ -121,6 +125,11 @@
|
|||||||
*/
|
*/
|
||||||
public function GetShort( )
|
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 ) );
|
$Data = UnPack( 'v', $this->Get( 2 ) );
|
||||||
|
|
||||||
return $Data[ 1 ];
|
return $Data[ 1 ];
|
||||||
@@ -133,6 +142,11 @@
|
|||||||
*/
|
*/
|
||||||
public function GetLong( )
|
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 ) );
|
$Data = UnPack( 'l', $this->Get( 4 ) );
|
||||||
|
|
||||||
return $Data[ 1 ];
|
return $Data[ 1 ];
|
||||||
@@ -145,6 +159,11 @@
|
|||||||
*/
|
*/
|
||||||
public function GetFloat( )
|
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 ) );
|
$Data = UnPack( 'f', $this->Get( 4 ) );
|
||||||
|
|
||||||
return $Data[ 1 ];
|
return $Data[ 1 ];
|
||||||
@@ -157,6 +176,11 @@
|
|||||||
*/
|
*/
|
||||||
public function GetUnsignedLong( )
|
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 ) );
|
$Data = UnPack( 'V', $this->Get( 4 ) );
|
||||||
|
|
||||||
return $Data[ 1 ];
|
return $Data[ 1 ];
|
||||||
|
|||||||
Reference in New Issue
Block a user