Kafka\Protocol\Encoder::encodeString PHP Метод

encodeString() публичный статический Метод

encode pack string type
public static encodeString ( string $string, integer $bytes, integer $compression = self::COMPRESSION_NONE ) : string
$string string
$bytes integer self::PACK_INT32: int32 big endian order. self::PACK_INT16: int16 big endian order.
$compression integer
Результат string
    public static function encodeString($string, $bytes, $compression = self::COMPRESSION_NONE)
    {
        $packLen = $bytes == self::PACK_INT32 ? self::BIT_B32 : self::BIT_B16;
        switch ($compression) {
            case self::COMPRESSION_NONE:
                break;
            case self::COMPRESSION_GZIP:
                $string = \gzencode($string);
                break;
            case self::COMPRESSION_SNAPPY:
                throw new \Kafka\Exception\NotSupported('SNAPPY compression not yet implemented');
            default:
                throw new \Kafka\Exception\NotSupported('Unknown compression flag: ' . $compression);
        }
        return self::pack($packLen, strlen($string)) . $string;
    }