// 
// Decompiled by Procyon v0.6.0
// 

package com.google.protobuf;

import java.util.Locale;
import java.util.logging.Logger;

public final class RuntimeVersion
{
    public static final RuntimeDomain OSS_DOMAIN;
    public static final int OSS_MAJOR = 4;
    public static final int OSS_MINOR = 33;
    public static final int OSS_PATCH = 0;
    public static final String OSS_SUFFIX = "";
    public static final RuntimeDomain DOMAIN;
    public static final int MAJOR = 4;
    public static final int MINOR = 33;
    public static final int PATCH = 0;
    public static final String SUFFIX = "";
    private static final int MAX_WARNING_COUNT = 20;
    static int majorWarningLoggedCount;
    static int minorWarningLoggedCount;
    static boolean preleaseRuntimeWarningLogged;
    private static final String VERSION_STRING;
    private static final Logger logger;
    
    public static void validateProtobufGencodeVersion(final RuntimeDomain domain, final int major, final int minor, final int patch, final String suffix, final String location) {
        validateProtobufGencodeVersionImpl(domain, major, minor, patch, suffix, location);
    }
    
    private static void validateProtobufGencodeVersionImpl(final RuntimeDomain domain, final int major, final int minor, final int patch, final String suffix, final String location) {
        if (checkDisabled()) {
            return;
        }
        if (major < 0 || minor < 0 || patch < 0) {
            throw new ProtobufRuntimeVersionException("Invalid gencode version: " + versionString(major, minor, patch, suffix));
        }
        if (domain != RuntimeVersion.DOMAIN) {
            throw new ProtobufRuntimeVersionException(String.format(Locale.US, "Detected mismatched Protobuf Gencode/Runtime domains when loading %s: gencode %s, runtime %s. Cross-domain usage of Protobuf is not supported.", location, domain, RuntimeVersion.DOMAIN));
        }
        String gencodeVersionString = null;
        if (!"".isEmpty() && !RuntimeVersion.preleaseRuntimeWarningLogged) {
            if (gencodeVersionString == null) {
                gencodeVersionString = versionString(major, minor, patch, suffix);
            }
            RuntimeVersion.logger.warning(String.format(Locale.US, " Protobuf prelease version %s in use. This is not recommended for production use.\n You can ignore this message if you are deliberately testing a prerelease. Otherwise you should switch to a non-prerelease Protobuf version.", RuntimeVersion.VERSION_STRING));
            RuntimeVersion.preleaseRuntimeWarningLogged = true;
        }
        if (major == 4 && minor == 33 && patch == 0 && suffix.equals("")) {
            return;
        }
        if (major != 4) {
            if (major != 3 || RuntimeVersion.majorWarningLoggedCount >= 20) {
                throw new ProtobufRuntimeVersionException(String.format(Locale.US, "Detected mismatched Protobuf Gencode/Runtime major versions when loading %s: gencode %s, runtime %s. Same major version is required.", location, versionString(major, minor, patch, suffix), RuntimeVersion.VERSION_STRING));
            }
            gencodeVersionString = versionString(major, minor, patch, suffix);
            RuntimeVersion.logger.warning(String.format(Locale.US, " Protobuf gencode version %s is exactly one major version older than the runtime version %s at %s. Please update the gencode to avoid compatibility violations in the next runtime release.", gencodeVersionString, RuntimeVersion.VERSION_STRING, location));
            ++RuntimeVersion.majorWarningLoggedCount;
        }
        if (33 < minor || (minor == 33 && 0 < patch)) {
            if (gencodeVersionString == null) {
                gencodeVersionString = versionString(major, minor, patch, suffix);
            }
            throw new ProtobufRuntimeVersionException(String.format(Locale.US, "Detected incompatible Protobuf Gencode/Runtime versions when loading %s: gencode %s, runtime %s. Runtime version cannot be older than the linked gencode version.", location, gencodeVersionString, RuntimeVersion.VERSION_STRING));
        }
        if (suffix.isEmpty() && "".isEmpty()) {
            return;
        }
        if (!suffix.isEmpty()) {
            if (gencodeVersionString == null) {
                gencodeVersionString = versionString(major, minor, patch, suffix);
            }
            throw new ProtobufRuntimeVersionException(String.format(Locale.US, "Detected mismatched Protobuf Gencode/Runtime version suffixes when loading %s: gencode %s, runtime %s. Prerelease gencode must be used with the same runtime.", location, gencodeVersionString, RuntimeVersion.VERSION_STRING));
        }
        if (major == 4 && minor == 33 && patch == 0) {
            if (gencodeVersionString == null) {
                gencodeVersionString = versionString(major, minor, patch, suffix);
            }
            throw new ProtobufRuntimeVersionException(String.format(Locale.US, "Detected mismatched Protobuf Gencode/Runtime version suffixes when loading %s: gencode %s, runtime %s. Prelease runtimes must only be used with exact match gencode (including suffix) or non-prerelease gencode versions of a lower version.", location, gencodeVersionString, RuntimeVersion.VERSION_STRING));
        }
    }
    
    private static String versionString(final int major, final int minor, final int patch, final String suffix) {
        return String.format(Locale.US, "%d.%d.%d%s", major, minor, patch, suffix);
    }
    
    private static boolean checkDisabled() {
        final String disableFlag = System.getenv("TEMPORARILY_DISABLE_PROTOBUF_VERSION_CHECK");
        return disableFlag != null && disableFlag.equals("true");
    }
    
    private RuntimeVersion() {
    }
    
    static {
        OSS_DOMAIN = RuntimeDomain.PUBLIC;
        DOMAIN = RuntimeVersion.OSS_DOMAIN;
        RuntimeVersion.majorWarningLoggedCount = 0;
        RuntimeVersion.minorWarningLoggedCount = 0;
        RuntimeVersion.preleaseRuntimeWarningLogged = false;
        VERSION_STRING = versionString(4, 33, 0, "");
        logger = Logger.getLogger(RuntimeVersion.class.getName());
    }
    
    public enum RuntimeDomain
    {
        GOOGLE_INTERNAL, 
        PUBLIC;
    }
    
    public static final class ProtobufRuntimeVersionException extends RuntimeException
    {
        public ProtobufRuntimeVersionException(final String message) {
            super(message);
        }
    }
}
