Parse an array of bytes and returns an IPv4 instance if the array is valid, or null otherwise.

@param int[]|array $bytes

@return static|null
352376
public static function fromBytes(array $bytes)
    {
        $result = null;
        if (count($bytes) === 4) {
            $chunks = array_map(
                function ($byte) {
                    return (is_int($byte) && $byte >= 0 && $byte <= 255) ? (string) $byte : false;
                },
                $bytes
            );
            if (in_array(false, $chunks, true) === false) {
                $result = new static(implode('.', $chunks));
            }
        }

        return $result;
    }
352473
public function read($bytes)
    {
        $read = 0;
        $parts = array();

        while ($read < $bytes) {
            $data = fread($this->socket, $bytes - $read);

            if ($data === false) {
                // server must have dropped the connection
                if (feof($this->socket)) {
                    $this->close();
                }

                return false;
            }

            $read += strlen($data);
            $parts[] = $data;
        }

        return implode($parts);
    }
516719
protected static function randomTwister($bytes)
    {
        $rand = "";
        for ($a = 0; $a < $bytes; $a++) {
            $rand .= chr(mt_rand(0, 255));
        }

        return $rand;
    }
412996
public function consumeReadBuffer(int $bytes) : string
    {
        if ($this->getBufferLength()<$bytes) {
            throw new \RuntimeException("BufferedSocket::getAndConsumeReadBuffer requested more bytes than are currently available. Requested=".$bytes.", available=".$this->getBufferLength().".");
        }
        $data = \substr($this->getReadBuffer(), 0, $bytes);
        $this->reduceReadBuffer($bytes);
        return $data;
    }
100955
protected function formatBytes(int $bytes)
    {
        if (!$this->useFormatting) {
            return $bytes;
        }

        if ($bytes > 1024 * 1024) {
            return round($bytes / 1024 / 1024, 2).' MB';
        } elseif ($bytes > 1024) {
            return round($bytes / 1024, 2).' KB';
        }

        return $bytes . ' B';
    }
884341
protected function getReadableBytes($bytes, $precision)
    {
        $suffix = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
        $total = count($suffix);

        for ($i = 0; $bytes > 1024 && $i < $total; $i++) {
            $bytes /= 1024;
        }

        return number_format($bytes, $precision) . ' ' . $suffix[$i];
    }
970451
private static function recursiveDecode(&$bytes)
    {
        // Grab the first byte
        $first = array_shift($bytes);

        // Get the major type
        $major = $first & MajorType::BIT_MASK;
        $additional = $first & AdditionalType::BIT_MASK;

        switch($major)
        {
            case MajorType::POSITIVE_INT:
                return self::decodeIntValue($additional, $bytes);

            case MajorType::NEGATIVE_INT:
                $decoded = self::decodeIntValue($additional, $bytes);

                // Apply negative number logic
                $decoded += 1;
                $decoded *= -1;

                return $decoded;

            case MajorType::BYTE_STRING:
                return self::decodeByteString($additional, $bytes);

            case MajorType::UTF8_STRING:
                return self::decodeString($additional, $bytes);

            case MajorType::SEQUENCE:
                return self::decodeSequence($additional, $bytes);

            case MajorType::MAP:
                return self::decodeMap($additional, $bytes);

            case MajorType::SIMPLE_AND_FLOAT:
                return self::decodeSimple($additional, $bytes);

            default:
                return self::decodeTag($additional, $bytes);
        }
    }
29470
public function setBlockSize(int $bytes): HttpParser
    {
        $this->block_size = $bytes;

        if ($this->block_size > 8192 || $this->block_size < 1) {
            throw new RuntimeException('Block must not be higher than 8KB');
        }

        return $this;
    }
57516
public function show_bytes($bytes, &$unit = null)
    {
        if ($bytes >= 1073741824) {
            $unit = 'GB';
            $gb   = $bytes/1073741824;
            $str  = sprintf($gb >= 10 ? "%d " : "%.1f ", $gb) . $this->gettext($unit);
        }
        else if ($bytes >= 1048576) {
            $unit = 'MB';
            $mb   = $bytes/1048576;
            $str  = sprintf($mb >= 10 ? "%d " : "%.1f ", $mb) . $this->gettext($unit);
        }
        else if ($bytes >= 1024) {
            $unit = 'KB';
            $str  = sprintf("%d ",  round($bytes/1024)) . $this->gettext($unit);
        }
        else {
            $unit = 'B';
            $str  = sprintf('%d ', $bytes) . $this->gettext($unit);
        }

        return $str;
    }
944788
private function parity($byte) {
		$parity = 0;
		for($i=7; $i>=0; $i--) {
			$parity ^= ($byte >> $i) & 1;
		}
		return (bool) $parity;
	}
1231881
private function readBytes($bytes, $noBuffer)
    {
        if(!$this->socket) {
            return "";
        }

        if($noBuffer) {
            return fread($this->socket, $bytes);
        }

        $bytes_left = $bytes;
        $retval = "";
        while( !feof($this->socket) && $bytes_left > 0 ) {
            $res = fread($this->socket, $bytes_left);
            $retval.=$res;
            $bytes_left-=strlen($res);
        }

        return $retval;
    }
676326
public function stream_read($bytes)
    {
        if (!$this->currentlyOpenedFile->isOpenedForReading()) {
            return null;
        }
        $data = $this->currentlyOpenedFile->read($bytes);
        //file access time changes so stat cache needs to be cleared
        clearstatcache();

        return $data;
    }
783461
public String fromByteArray(byte[] bytes) {
    java.util.Objects.requireNonNull(bytes, "bytes");
    return fromByteArray(bytes, 0, bytes.length);
  }
184131
@Override
    public Object deserialize(byte[] bytes) throws IOException {
        KryoHolder kryoHolder = null;
        if (bytes == null) throw new RuntimeException("bytes can not be null");
        try {
            kryoHolder = KryoPoolImpl.getInstance().get();
            kryoHolder.input.setBuffer(bytes, 0, bytes.length);//call it ,and then use input object  ,discard any array
            return kryoHolder.kryo.readClassAndObject(kryoHolder.input);
        } catch (RuntimeException e) {
            throw new RuntimeException(e);
		} finally {
			if (kryoHolder != null) {
				KryoPoolImpl.getInstance().offer(kryoHolder);
			}
			// bytes = null; // for gc
		}
    }
478786
public function read(int $bytes): string
	{
		$bytesLeft = $bytes;

		$data = '';

		do
		{
			$chunk = fread($this->connection, min($bytesLeft, 4096));

			if($chunk === false || $chunk === '')
			{
				throw new RedisException($this->appendReadErrorReason('Failed to read data from the server.'));
			}

			$data .= $chunk;

			$bytesLeft = $bytes - strlen($data);
		}
		while($bytesLeft > 0);

		return $data;
	}
579911
private function limitBytes($bytes)
    {
        if ($bytes === null) {
            return $this->content;
        } elseif (intval($bytes) < (self::BYTE_LIMIT * 0.046875)) {
            // less than 24 kilobytes (512 kilobytes * 0.046875)
            throw new \InvalidArgumentException('Byte limit is set dangerously low! Default value=' . self::BYTE_LIMIT);
        }
        return $this->content = mb_strcut($this->content, 0, intval($bytes));
    }
938764
public static function fromBytes($bytes)
    {
        if (strlen($bytes) !== 16) {
            throw new InvalidArgumentException('$bytes string should contain 16 characters.');
        }

        $uuid = '';
        foreach (range(0, 15) as $step) {
            $uuid .= sprintf('%02x', ord($bytes[$step]));

            if (in_array($step, array(3, 5, 7, 9))) {
                $uuid .= '-';
            }
        }

        return Uuid::fromString($uuid);
    }