Structures are very similar to the decompress function inside PHP.
These pieces of code are basically equivalent.
PHP:
define('ISP_TINY', 4);
class IS_TINY
{
const PACK = 'CCCC';
const UNPACK = 'CSize/CType/CReqI/CSubT';
public $Size = 4;
public $Type = ISP_TINY;
public $ReqI;
public $SubT;
public function __construct($rawPacket)
{
$pkClass = unpack($this::UNPACK, $rawPacket);
foreach ($this as $property => $value)
{
$this->$property = $pkClass[$property];
}
}
}
C ++:
#define ISP_TINY = 4;
struct IS_TINY
{
byte Size;
byte Type;
byte ReqI;
byte SubT;
};
source
share