public static function packEncode($data, $type = "tcp")
{
if ($type == "tcp") {
$sendStr = serialize($data);
//if compress the packet
if (DoraConst::SW_DATACOMPRESS_FLAG == true) {
$sendStr = gzencode($sendStr, 4);
}
if (DoraConst::SW_DATASIGEN_FLAG == true) {
$signedcode = pack('N', crc32($sendStr . DoraConst::SW_DATASIGEN_SALT));
$sendStr = pack('N', strlen($sendStr) + 4) . $signedcode . $sendStr;
} else {
$sendStr = pack('N', strlen($sendStr)) . $sendStr;
}
return $sendStr;
} else {
if ($type == "http") {
$sendStr = json_encode($data);
return $sendStr;
} else {
return self::packFormat("packet type wrong", 100006);
}
}
}