@param BytesWalker $walker

@return string
167595
public function getSignature(BytesWalker $walker)
    {
        static $signatures = [
            Constants::SIGNATURE_SUCCESS => self::SUCCESS,
            Constants::SIGNATURE_FAILURE => self::FAILURE,
            Constants::SIGNATURE_RECORD => self::RECORD,
            Constants::SIGNATURE_IGNORE => self::IGNORED,
            Constants::SIGNATURE_UNBOUND_RELATIONSHIP => 'UNBOUND_RELATIONSHIP',
            Constants::SIGNATURE_NODE => 'NODE',
            Constants::SIGNATURE_PATH => 'PATH',
            Constants::SIGNATURE_RELATIONSHIP => 'RELATIONSHIP',
        ];

        $sigMarker = $walker->read(1);
        $ordMarker = ord($sigMarker);

        return $signatures[$ordMarker];

//        if (Constants::SIGNATURE_SUCCESS === $ordMarker) {
//            return self::SUCCESS;
//        }
//
//        if ($this->isSignature(Constants::SIGNATURE_FAILURE, $sigMarker)) {
//            return self::FAILURE;
//        }
//
//        if ($this->isSignature(Constants::SIGNATURE_RECORD, $sigMarker)) {
//            return self::RECORD;
//        }
//
//        if ($this->isSignature(Constants::SIGNATURE_IGNORE, $sigMarker)) {
//            return self::IGNORED;
//        }
//
//        if ($this->isSignature(Constants::SIGNATURE_UNBOUND_RELATIONSHIP, $sigMarker)) {
//            return "UNBOUND_RELATIONSHIP";
//        }
//
//        if ($this->isSignature(Constants::SIGNATURE_NODE, $sigMarker)) {
//            return "NODE";
//        }
//
//        if ($this->isSignature(Constants::SIGNATURE_PATH, $sigMarker)) {
//            return "PATH";
//        }
//
//        if ($this->isSignature(Constants::SIGNATURE_RELATIONSHIP, $sigMarker)) {
//            return "RELATIONSHIP";
//        }
//
//        throw new SerializationException(sprintf('Unable to guess the signature for byte "%s"', Helper::prettyHex($sigMarker)));
    }
874278
public static function bytesToString(int $bytes, int $round = 0): string
    {
        return self::getMeasure($bytes, 0, $round);
    }
1147723
protected function formatBytes($bytes)
    {
        $bytes = (int) $bytes;

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

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

        return $bytes . ' B';
    }
392085
public function getBytes()
    {
        $bytes = '';

        $hex = $this->toString();
        $hex = str_replace('-', '', $hex);

        foreach (range(-2, -32, 2) as $step) {
            $bytes = chr(hexdec(substr($hex, $step, 2))) . $bytes;
        }

        return $bytes;
    }
219468
public function unpackElement(BytesWalker $walker)
    {
        $marker = $walker->read(1);
        $byte = hexdec(bin2hex($marker));
        $ordMarker = ord($marker);
        $markerHigh = $ordMarker & 0xf0;
        $markerLow = $ordMarker & 0x0f;

        // Structures
        if (0xb0 <= $ordMarker && $ordMarker <= 0xbf) {
            $walker->rewind(1);
            $structureSize = $this->getStructureSize($walker);
            $sig = $this->getSignature($walker);
            $str = new Structure($sig, $structureSize);
            $done = 0;
            while ($done < $structureSize) {
                $elt = $this->unpackElement($walker);
                $str->addElement($elt);
                ++$done;
            }

            return $str;
        }

        if ($markerHigh === Constants::MAP_TINY) {
            $size = $markerLow;
            $map = [];
            for ($i = 0; $i < $size; ++$i) {
                $identifier = $this->unpackElement($walker);
                $value = $this->unpackElement($walker);
                $map[$identifier] = $value;
            }

            return $map;
        }

        if (Constants::MAP_8 === $byte) {
            $size = $this->readUnsignedShortShort($walker);

            return $this->unpackMap($size, $walker);
        }

        if ($byte === Constants::MAP_16) {
            $size = $this->readUnsignedShort($walker);

            return $this->unpackMap($size, $walker);
        }

        if ($markerHigh === Constants::TEXT_TINY) {
            $textSize = $this->getLowNibbleValue($marker);

            return $this->unpackText($textSize, $walker);
        }

        if ($byte === Constants::TEXT_8) {
            $textSize = $this->readUnsignedShortShort($walker);

            return $this->unpackText($textSize, $walker);
        }

        if ($byte === Constants::TEXT_16) {
            $textSize = $this->readUnsignedShort($walker);

            return $this->unpackText($textSize, $walker);
        }

        if ($byte === Constants::TEXT_32) {
            $textSize = $this->readUnsignedLong($walker);

            return $this->unpackText($textSize, $walker);
        }

        if ($byte === Constants::INT_8) {
            $integer = $this->readSignedShortShort($walker);

            return $this->unpackInteger($integer);
        }

        if ($byte === Constants::INT_16) {
            $integer = $this->readSignedShort($walker);

            return $this->unpackInteger($integer);
        }

        if ($byte === Constants::INT_32) {
            $integer = $this->readSignedLong($walker);

            return $this->unpackInteger($integer);
        }

        if ($byte === Constants::INT_64) {
            $integer = $this->readSignedLongLong($walker);

            return $this->unpackInteger($integer);
        }

        if ($markerHigh === Constants::LIST_TINY) {
            $size = $this->getLowNibbleValue($marker);

            return $this->unpackList($size, $walker);
        }

        if ($byte === Constants::LIST_8) {
            $size = $this->readUnsignedShortShort($walker);

            return $this->unpackList($size, $walker);
        }

        if ($byte === Constants::LIST_16) {
            $size = $this->readUnsignedShort($walker);

            return $this->unpackList($size, $walker);
        }

        if ($byte === Constants::LIST_32) {
            $size = $this->readUnsignedLong($walker);

            return $this->unpackList($size, $walker);
        }

        // Checks for TINY INTS
        if ($this->isInRange(0x00, 0x7f, $marker) || $this->isInRange(0xf0, 0xff, $marker)) {
            $walker->rewind(1);
            $integer = $this->readSignedShortShort($walker);

            return $this->unpackInteger($integer);
        }

        // Checks for floats
        if ($byte === Constants::MARKER_FLOAT) {
            list(, $v) = unpack('d', strrev($walker->read(8)));

            return (float) $v;
        }

        // Checks Primitive Values NULL, TRUE, FALSE
        if ($byte === Constants::MARKER_NULL) {
            return;
        }

        if ($byte === Constants::MARKER_TRUE) {
            return true;
        }

        if ($byte === Constants::MARKER_FALSE) {
            return false;
        }

        throw new SerializationException(sprintf('Unable to find serialization type for marker %s', Helper::prettyHex($marker)));
    }
803347
private function formatSize($bytes)
    {
        $unit = 1024;
        if ($bytes <= $unit) {
            return $bytes.' b';
        }
        $exp = (int)(log($bytes) / log($unit));
        $pre = 'kMGTPE';
        $pre = $pre[$exp - 1];

        return sprintf('%.1f %sB', $bytes / pow($unit, $exp), $pre);
    }
268393
public function formatFilesize($bytes)
    {
        $units = array('bytes', 'kb', 'MB', 'GB', 'TB', 'PB');
        $level = floor(log($bytes)/log(1024));

        $output = sprintf('%.2f %s', ($bytes/pow(1024, floor($level))), $units[$level]);

        return $output;
    }
1281164
private function toDecimal(string $bytes) : string
    {
        $result = '0';
        $power = '1';

        for ($i = \strlen($bytes) - 1; $i >= 0; $i--) {
            $index = \ord($bytes[$i]);

            if ($index !== 0) {
                $result = $this->add($result, ($index === 1)
                    ? $power
                    : $this->mul($power, (string) $index)
                );
            }

            if ($i !== 0) {
                $power = $this->mul($power, '256');
            }
        }

        return $result;
    }
1156490
final static public function sizeBytesToText (int $bytes=0) : string
	{
		if ($bytes >= pow(1024,8)) 			return number_format($bytes / pow(1024,8), 2) . ' YB';
		elseif ($bytes >= pow(1024,7)) 		return number_format($bytes / pow(1024,7), 2) . ' ZB';
		elseif ($bytes >= pow(1024,6)) 		return number_format($bytes / pow(1024,6), 2) . ' EB';
		elseif ($bytes >= pow(1024,5)) 		return number_format($bytes / pow(1024,5), 2) . ' PB';
		elseif ($bytes >= pow(1024,4)) 		return number_format($bytes / pow(1024,4), 2) . ' TB';
		elseif ($bytes >= pow(1024,3)) 		return number_format($bytes / pow(1024,3), 2) . ' GB';
		elseif ($bytes >= pow(1024,2)) 		return number_format($bytes / pow(1024,2), 2) . ' MB';
		elseif ($bytes >= pow(1024,1)) 		return number_format($bytes / pow(1024,1), 2) . ' KB';		
		elseif ($bytes > 1) 				return $bytes . ' bytes';		
		elseif ($bytes <= 1) 				return $bytes . ' byte';
	}
460294
public function readBytes(int $bytes): string
	{
		if ($this->connected() === false)
		{
			throw new \Exception('Not connected');
		}

		$response = fread($this->connection, $bytes);

		if ($response === false)
		{
			throw new \Exception('Nothing to read');
		}

		return $response;
	}
384803
public static function convertSizeToText(string $bytes): string
    {
        $kb = 1 << 10;
        $mb = $kb << 10;
        $gb = $mb << 10;
        $tb = $gb << 10;

        if ($bytes < $kb) {
            return $bytes . ' Б';
        } elseif ($bytes < $mb) {
            return number_format($bytes / $kb, 2, ',', '') . ' КБ';
        } elseif ($bytes < $gb) {
            return number_format($bytes / $mb, 2, ',', '') . ' MБ';
        } elseif ($bytes < $tb) {
            return number_format($bytes / $gb, 2, ',', '') . ' ГБ';
        }

        return number_format($bytes / $tb, 2, ',', '') . ' ТБ';
    }
663707
private static function sizeFormat($bytes)
    {
        $kb = 1024;
        $mb = $kb * 1024;
        $gb = $mb * 1024;
        $tb = $gb * 1024;

        if (($bytes >= 0) && ($bytes < $kb)) {
            return $bytes . ' B';
        } elseif (($bytes >= $kb) && ($bytes < $mb)) {
            return ceil($bytes / $kb) . ' KB';
        } elseif (($bytes >= $mb) && ($bytes < $gb)) {
            return ceil($bytes / $mb) . ' MB';
        } elseif (($bytes >= $gb) && ($bytes < $tb)) {
            return ceil($bytes / $gb) . ' GB';
        } elseif ($bytes >= $tb) {
            return ceil($bytes / $tb) . ' TB';
        } else {
            return $bytes . ' B';
        }
    }
409386
public static function encode($bytes)
    {
        $i = 0; $index = 0;
        $base32 = '';
        $bytesLen = \strlen($bytes);

        while ($i < $bytesLen) {
            $currByte = \ord($bytes[$i]);

            /* Is the current digit going to span a byte boundary? */
            if ($index > 3) {
                if (($i + 1) < $bytesLen) {
                    $nextByte = \ord($bytes[$i+1]);
                } else {
                    $nextByte = 0;
                }

                $digit = $currByte & (0xFF >> $index);
                $index = ($index + 5) % 8;
                $digit <<= $index;
                $digit |= $nextByte >> (8 - $index);
                $i++;
            } else {
                $digit = ($currByte >> (8 - ($index + 5))) & 0x1F;
                $index = ($index + 5) % 8;
                if ($index === 0) {
                    $i++;
                }
            }

            $base32 .= self::$base32Chars[$digit];
        }
        return $base32;
    }
613497
public static function say_size($bytes, $unit = 'B', $stop = false): string
  {
// pretty printer for byte values
//
    $i = 0;
    $units = ['', 'K', 'M', 'G', 'T'];
    while ( $stop || ($bytes > 2000) ){
      $i++;
      $bytes /= 1024;
      if ( $stop === $units[$i] ){
        break;
      }
    }
    return sprintf("%5.2f %s".$unit, $bytes, $units[$i]);
  }
367085
private function formatMemory($bytes)
    {
        $units = ['B', 'KiB', 'MiB', 'GiB'];
        $mod = 1024;
        $power = ($bytes > 0) ? (int) floor(log($bytes, $mod)) : 0;

        return sprintf('%01.2f %s', $bytes / pow($mod, $power), $units[$power]);
    }
803562
private function encodeByteSequence(array $bytes, int &$size): string
    {
        $ret = '';
        $size = 0;
        foreach ($bytes as $b) {
            if (isset($this->safeMap[$b])) {
                $ret .= $this->safeMap[$b];
                ++$size;
            } else {
                $ret .= self::$qpMap[$b];
                $size += 3;
            }
        }

        return $ret;
    }
254628
public function unpackMap($size, BytesWalker $walker)
    {
        $map = [];
        for ($i = 0; $i < $size; ++$i) {
            $identifier = $this->unpackElement($walker);
            $value = $this->unpackElement($walker);
            $map[$identifier] = $value;
        }

        return $map;
    }