$bodies */ public static function mpub(string $topic, array $bodies): string { static $buffer; $buffer ??= new ByteBuffer(); $buffer->appendUint32(\count($bodies)); foreach ($bodies as $body) { $buffer->appendUint32(\strlen($body)); $buffer->append($body); } return self::pack('MPUB', $topic, $buffer->flush()); } public static function dpub(string $topic, string $body, int $delay): string { return self::pack('DPUB', [$topic, $delay], $body); } public static function sub(string $topic, string $channel): string { return self::pack('SUB', [$topic, $channel]); } /** * @param array|string $params */ private static function pack(string $command, array | string $params = [], string $data = null): string { static $buffer; $buffer ??= new Buffer(); $command = implode(' ', [$command, ...((array) $params)]); $buffer->append($command.PHP_EOL); if (null !== $data) { $buffer->appendUint32(\strlen($data)); $buffer->append($data); } return $buffer->flush(); } }