本文整理汇总了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();
}