本文整理匯總了PHP中pocketmine\utils\Binary::writeUnsignedVarInt方法的典型用法代碼示例。如果您正苦於以下問題:PHP Binary::writeUnsignedVarInt方法的具體用法?PHP Binary::writeUnsignedVarInt怎麽用?PHP Binary::writeUnsignedVarInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\utils\Binary
的用法示例。
在下文中一共展示了Binary::writeUnsignedVarInt方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getChunkCacheFromData
/**
* @param int $chunkX
* @param int $chunkZ
* @param string $payload
* @param int $ordering
*
* @return DataPacket
*/
public static function getChunkCacheFromData($chunkX, $chunkZ, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
{
$pk = new FullChunkDataPacket();
$pk->chunkX = $chunkX;
$pk->chunkZ = $chunkZ;
$pk->order = $ordering;
$pk->data = $payload;
$pk->encode();
$batch = new BatchPacket();
$batch->payload = zlib_encode(Binary::writeUnsignedVarInt(strlen($pk->getBuffer())) . $pk->getBuffer(), ZLIB_ENCODING_DEFLATE, Server::getInstance()->networkCompressionLevel);
$batch->encode();
$batch->isEncoded = true;
return $batch;
}
示例2: putUnsignedVarInt
/**
* Writes an unsigned varint32 to the stream.
*/
public function putUnsignedVarInt($v)
{
$this->put(Binary::writeUnsignedVarInt($v));
}
示例3: batchPackets
/**
* Broadcasts a list of packets in a batch to a list of players
*
* @param Player[] $players
* @param DataPacket[]|string $packets
* @param bool $forceSync
*/
public function batchPackets(array $players, array $packets, $forceSync = false)
{
Timings::$playerNetworkTimer->startTiming();
$str = "";
foreach ($packets as $p) {
if ($p instanceof DataPacket) {
if (!$p->isEncoded) {
$p->encode();
}
$str .= Binary::writeUnsignedVarInt(strlen($p->buffer)) . $p->buffer;
} else {
$str .= Binary::writeUnsignedVarInt(strlen($p)) . $p;
}
}
$targets = [];
foreach ($players as $p) {
if ($p->isConnected()) {
$targets[] = $this->identifiers[spl_object_hash($p)];
}
}
if (!$forceSync and $this->networkCompressionAsync) {
$task = new CompressBatchedTask($str, $targets, $this->networkCompressionLevel);
$this->getScheduler()->scheduleAsyncTask($task);
} else {
$this->broadcastPacketsCallback(zlib_encode($str, ZLIB_ENCODING_DEFLATE, $this->networkCompressionLevel), $targets);
}
Timings::$playerNetworkTimer->stopTiming();
}