private int nextType() {
        int type;
        if (_depth > 0) {
            while (_next >= _end && _level > 0) {
                _end = popEnd();
            }
            type = type();
            _next++;
            if (type >= SIZE1 && type <= SIZE5) {
                int size = decodeVariableLengthInt(type);
                pushEnd(_end);
                _end = _next + size;
                type = _bytes[_next++] & 0xFF;
            }
            if (type >= CLASS1 && type <= CLASS5) {
                type = decodeVariableLengthInt(type) + CLASS1;
            } else if (type == Buffer.LONGREC_TYPE)
                return -1;
        } else {
            _next = 0;
            _end = _size;
            _serializedItemCount = 0;
            releaseValueCache();
            if (_level != 0) {
                _level = 0;
                if (_endArray != null && _endArray.length > TOO_MANY_LEVELS_THRESHOLD) {
                    _endArray = null;
                }
            }
            if (_size == 0) {
                throw new ConversionException("Value is undefined");
            }
            type = _bytes[_next++] & 0xFF;
            if (type >= CLASS1 && type <= CLASS5) {
                type = decodeVariableLengthInt(type) + CLASS1;
            } else if (type == Buffer.LONGREC_TYPE)
                return -1;
        }
        return type;
    }