2010-03-28 196 views

回答

0

結構非常像PHP中的解壓函數。

這些代碼塊基本上是等價的。

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 // General purpose 4 byte packet 
{ 
    byte Size; // Always 4 
    byte Type; // Always ISP_TINY 
    byte ReqI; 
    byte SubT; 
};