src/Protocol/EasyDataGram.php
private function pack(int $packetId, $data): string
    {
        if (!$this->canSend($type = gettype($data))) {
            throw new SendException('Cannot send data of type "' . $type . '".');
        }
        if ($type === 'object') {
            $data = serialize($data);
        }
        $data = json_encode([
            'id' => $packetId,
            'type' => $type,
            'data' => $data,
        ]);

        $maxPacketSize = $this->provider->getMaxPacketSizeForWriting();
        if ($maxPacketSize > 0 && strlen($data) > $maxPacketSize) {
            throw new SendException('Large size of data to send! Please break it into your code.');
        }
        return $data;
    }
private function pack(int $packetId, $data): string
    {
        if (!$this->canSend($type = gettype($data))) {
            throw new SendException('Cannot send data of type "' . $type . '".');
        }
        if ($type === 'object') {
            $data = serialize($data);
        }
        $data = json_encode([
            'id' => $packetId,
            'type' => $type,
            'data' => $data,
        ]);

        $maxPacketSize = $this->provider->getMaxPacketSizeForWriting();
        if ($maxPacketSize > 0 && strlen($data) > $maxPacketSize) {
            throw new SendException('Large size of data to send! Please break it into your code.');
        }
        return $data;
    }
Пакует данные в пакеты, и возвращает массив пакетов,
которые можно отправлять в любом порядке.

@param int $packetId
@param mixed $data

@return string
@throws SendException