private static function decodeEntry($buffer, &$offset)
    {
        $offsetMarker = $offset;

        switch ($byte = $buffer[$offset++]) {
            case 'd':
                $dictionary = array();
                for (;;) {
                    if ($buffer[$offset] === 'e') {
                        $offset++;
                        break;
                    }

                    $key = self::decodeEntry($buffer, $offset);
                    if (!is_string($key) && !is_numeric($key)) {
                        throw new DecodingException("One of the dictionary keys is not a string or an integer: " . gettype($key), $offset);
                    }
                    $dictionary[$key] = self::decodeEntry($buffer, $offset);
                }
                return $dictionary;

            case 'l':
                $list = array();
                for (;;) {
                    if ($buffer[$offset] === 'e') {
                        $offset++;
                        break;
                    }
                    $list[] = self::decodeEntry($buffer, $offset);
                }
                return $list;

            case 'e':
            case 'i':
                return self::getIntegerFromBuffer($buffer, $offset);

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                $number = self::getStringFromBuffer($buffer, $offsetMarker);
                $offset = $offsetMarker;
                return $number;

            default:
                throw new DecodingException("Unknown prefix: $byte", $offset);
        }
    }
private static function decodeEntry($buffer, &$offset)
    {
        $offsetMarker = $offset;

        switch ($byte = $buffer[$offset++]) {
            case 'd':
                $dictionary = array();
                for (;;) {
                    if ($buffer[$offset] === 'e') {
                        $offset++;
                        break;
                    }

                    $key = self::decodeEntry($buffer, $offset);
                    if (!is_string($key) && !is_numeric($key)) {
                        throw new DecodingException("One of the dictionary keys is not a string or an integer: " . gettype($key), $offset);
                    }
                    $dictionary[$key] = self::decodeEntry($buffer, $offset);
                }
                return $dictionary;

            case 'l':
                $list = array();
                for (;;) {
                    if ($buffer[$offset] === 'e') {
                        $offset++;
                        break;
                    }
                    $list[] = self::decodeEntry($buffer, $offset);
                }
                return $list;

            case 'e':
            case 'i':
                return self::getIntegerFromBuffer($buffer, $offset);

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                $number = self::getStringFromBuffer($buffer, $offsetMarker);
                $offset = $offsetMarker;
                return $number;

            default:
                throw new DecodingException("Unknown prefix: $byte", $offset);
        }
    }
private static function decodeEntry ( $ buffer , & $ offset ) { $ offsetMarker = $ offset ; switch ( $ byte = $ buffer [ $ offset ++ ] ) { case 'd' : $ dictionary = array ( ) ; for ( ; ; ) { if ( $ buffer [ $ offset ] === 'e' ) { $ offset ++ ; break ; } $ key = self :: decodeEntry ( $ buffer , $ offset ) ; if ( ! is_string ( $ key ) && ! is_numeric ( $ key ) ) { throw new DecodingException ( "One of the dictionary keys is not a string or an integer: " . gettype ( $ key ) , $ offset ) ; } $ dictionary [ $ key ] = self :: decodeEntry ( $ buffer , $ offset ) ; } return $ dictionary ; case 'l' : $ list = array ( ) ; for ( ; ; ) { if ( $ buffer [ $ offset ] === 'e' ) { $ offset ++ ; break ; } $ list [ ] = self :: decodeEntry ( $ buffer , $ offset ) ; } return $ list ; case 'e' : case 'i' : return self :: getIntegerFromBuffer ( $ buffer , $ offset ) ; case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : $ number = self :: getStringFromBuffer ( $ buffer , $ offsetMarker ) ; $ offset = $ offsetMarker ; return $ number ; default : throw new DecodingException ( "Unknown prefix: $byte" , $ offset ) ; } }
Decodes the next Bencode entry from the buffer.

@param string $buffer Buffer containing the Bencode string.
@param int $offset Current position in the buffer.
@return mixed
Decodes the next Bencode entry from the buffer .