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

package com.google.protobuf;

import java.io.InputStream;
import java.nio.ByteBuffer;
import java.io.IOException;

public final class Any extends GeneratedMessage implements AnyOrBuilder
{
    private static final long serialVersionUID = 0L;
    private volatile Message cachedUnpackValue;
    public static final int TYPE_URL_FIELD_NUMBER = 1;
    private volatile Object typeUrl_;
    public static final int VALUE_FIELD_NUMBER = 2;
    private ByteString value_;
    private byte memoizedIsInitialized;
    private static final Any DEFAULT_INSTANCE;
    private static final Parser<Any> PARSER;
    
    private Any(final GeneratedMessage.Builder<?> builder) {
        super(builder);
        this.typeUrl_ = "";
        this.value_ = ByteString.EMPTY;
        this.memoizedIsInitialized = -1;
    }
    
    private Any() {
        this.typeUrl_ = "";
        this.value_ = ByteString.EMPTY;
        this.memoizedIsInitialized = -1;
        this.typeUrl_ = "";
        this.value_ = ByteString.EMPTY;
    }
    
    public static final Descriptors.Descriptor getDescriptor() {
        return AnyProto.internal_static_google_protobuf_Any_descriptor;
    }
    
    @Override
    protected FieldAccessorTable internalGetFieldAccessorTable() {
        return AnyProto.internal_static_google_protobuf_Any_fieldAccessorTable.ensureFieldAccessorsInitialized(Any.class, Builder.class);
    }
    
    private static String getTypeUrl(final String typeUrlPrefix, final Descriptors.Descriptor descriptor) {
        return typeUrlPrefix.endsWith("/") ? (typeUrlPrefix + descriptor.getFullName()) : (typeUrlPrefix + "/" + descriptor.getFullName());
    }
    
    private static String getTypeNameFromTypeUrl(final String typeUrl) {
        final int pos = typeUrl.lastIndexOf(47);
        return (pos == -1) ? "" : typeUrl.substring(pos + 1);
    }
    
    public static <T extends Message> Any pack(final T message) {
        return newBuilder().setTypeUrl(getTypeUrl("type.googleapis.com", message.getDescriptorForType())).setValue(message.toByteString()).build();
    }
    
    public static <T extends Message> Any pack(final T message, final String typeUrlPrefix) {
        return newBuilder().setTypeUrl(getTypeUrl(typeUrlPrefix, message.getDescriptorForType())).setValue(message.toByteString()).build();
    }
    
    public <T extends Message> boolean is(final Class<T> clazz) {
        final T defaultInstance = Internal.getDefaultInstance(clazz);
        return getTypeNameFromTypeUrl(this.getTypeUrl()).equals(defaultInstance.getDescriptorForType().getFullName());
    }
    
    public boolean isSameTypeAs(final Message message) {
        return getTypeNameFromTypeUrl(this.getTypeUrl()).equals(message.getDescriptorForType().getFullName());
    }
    
    public <T extends Message> T unpack(final Class<T> clazz) throws InvalidProtocolBufferException {
        boolean invalidClazz = false;
        if (this.cachedUnpackValue != null) {
            if (this.cachedUnpackValue.getClass() == clazz) {
                return (T)this.cachedUnpackValue;
            }
            invalidClazz = true;
        }
        if (invalidClazz || !this.is(clazz)) {
            throw new InvalidProtocolBufferException("Type of the Any message does not match the given class.");
        }
        final T defaultInstance = Internal.getDefaultInstance(clazz);
        final T result = (T)defaultInstance.getParserForType().parseFrom(this.getValue());
        return (T)(this.cachedUnpackValue = result);
    }
    
    public <T extends Message> T unpackSameTypeAs(final T message) throws InvalidProtocolBufferException {
        boolean invalidValue = false;
        if (this.cachedUnpackValue != null) {
            if (this.cachedUnpackValue.getClass() == message.getClass()) {
                return (T)this.cachedUnpackValue;
            }
            invalidValue = true;
        }
        if (invalidValue || !this.isSameTypeAs(message)) {
            throw new InvalidProtocolBufferException("Type of the Any message does not match the given exemplar.");
        }
        final T result = (T)message.getParserForType().parseFrom(this.getValue());
        return (T)(this.cachedUnpackValue = result);
    }
    
    @Override
    public String getTypeUrl() {
        final Object ref = this.typeUrl_;
        if (ref instanceof String) {
            return (String)ref;
        }
        final ByteString bs = (ByteString)ref;
        final String s = bs.toStringUtf8();
        return (String)(this.typeUrl_ = s);
    }
    
    @Override
    public ByteString getTypeUrlBytes() {
        final Object ref = this.typeUrl_;
        if (ref instanceof String) {
            final ByteString b = ByteString.copyFromUtf8((String)ref);
            return (ByteString)(this.typeUrl_ = b);
        }
        return (ByteString)ref;
    }
    
    @Override
    public ByteString getValue() {
        return this.value_;
    }
    
    @Override
    public final boolean isInitialized() {
        final byte isInitialized = this.memoizedIsInitialized;
        if (isInitialized == 1) {
            return true;
        }
        if (isInitialized == 0) {
            return false;
        }
        this.memoizedIsInitialized = 1;
        return true;
    }
    
    @Override
    public void writeTo(final CodedOutputStream output) throws IOException {
        if (!GeneratedMessage.isStringEmpty(this.typeUrl_)) {
            GeneratedMessage.writeString(output, 1, this.typeUrl_);
        }
        if (!this.value_.isEmpty()) {
            output.writeBytes(2, this.value_);
        }
        this.getUnknownFields().writeTo(output);
    }
    
    @Override
    public int getSerializedSize() {
        int size = this.memoizedSize;
        if (size != -1) {
            return size;
        }
        size = 0;
        if (!GeneratedMessage.isStringEmpty(this.typeUrl_)) {
            size += GeneratedMessage.computeStringSize(1, this.typeUrl_);
        }
        if (!this.value_.isEmpty()) {
            size += CodedOutputStream.computeBytesSize(2, this.value_);
        }
        size += this.getUnknownFields().getSerializedSize();
        return this.memoizedSize = size;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof Any)) {
            return super.equals(obj);
        }
        final Any other = (Any)obj;
        return this.getTypeUrl().equals(other.getTypeUrl()) && this.getValue().equals(other.getValue()) && this.getUnknownFields().equals(other.getUnknownFields());
    }
    
    @Override
    public int hashCode() {
        if (this.memoizedHashCode != 0) {
            return this.memoizedHashCode;
        }
        int hash = 41;
        hash = 19 * hash + getDescriptor().hashCode();
        hash = 37 * hash + 1;
        hash = 53 * hash + this.getTypeUrl().hashCode();
        hash = 37 * hash + 2;
        hash = 53 * hash + this.getValue().hashCode();
        hash = 29 * hash + this.getUnknownFields().hashCode();
        return this.memoizedHashCode = hash;
    }
    
    public static Any parseFrom(final ByteBuffer data) throws InvalidProtocolBufferException {
        return Any.PARSER.parseFrom(data);
    }
    
    public static Any parseFrom(final ByteBuffer data, final ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
        return Any.PARSER.parseFrom(data, extensionRegistry);
    }
    
    public static Any parseFrom(final ByteString data) throws InvalidProtocolBufferException {
        return Any.PARSER.parseFrom(data);
    }
    
    public static Any parseFrom(final ByteString data, final ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
        return Any.PARSER.parseFrom(data, extensionRegistry);
    }
    
    public static Any parseFrom(final byte[] data) throws InvalidProtocolBufferException {
        return Any.PARSER.parseFrom(data);
    }
    
    public static Any parseFrom(final byte[] data, final ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
        return Any.PARSER.parseFrom(data, extensionRegistry);
    }
    
    public static Any parseFrom(final InputStream input) throws IOException {
        return GeneratedMessage.parseWithIOException(Any.PARSER, input);
    }
    
    public static Any parseFrom(final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException {
        return GeneratedMessage.parseWithIOException(Any.PARSER, input, extensionRegistry);
    }
    
    public static Any parseDelimitedFrom(final InputStream input) throws IOException {
        return GeneratedMessage.parseDelimitedWithIOException(Any.PARSER, input);
    }
    
    public static Any parseDelimitedFrom(final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException {
        return GeneratedMessage.parseDelimitedWithIOException(Any.PARSER, input, extensionRegistry);
    }
    
    public static Any parseFrom(final CodedInputStream input) throws IOException {
        return GeneratedMessage.parseWithIOException(Any.PARSER, input);
    }
    
    public static Any parseFrom(final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException {
        return GeneratedMessage.parseWithIOException(Any.PARSER, input, extensionRegistry);
    }
    
    @Override
    public Builder newBuilderForType() {
        return newBuilder();
    }
    
    public static Builder newBuilder() {
        return Any.DEFAULT_INSTANCE.toBuilder();
    }
    
    public static Builder newBuilder(final Any prototype) {
        return Any.DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
    }
    
    @Override
    public Builder toBuilder() {
        return (this == Any.DEFAULT_INSTANCE) ? new Builder() : new Builder().mergeFrom(this);
    }
    
    @Override
    protected Builder newBuilderForType(final BuilderParent parent) {
        final Builder builder = new Builder(parent);
        return builder;
    }
    
    public static Any getDefaultInstance() {
        return Any.DEFAULT_INSTANCE;
    }
    
    public static Parser<Any> parser() {
        return Any.PARSER;
    }
    
    @Override
    public Parser<Any> getParserForType() {
        return Any.PARSER;
    }
    
    @Override
    public Any getDefaultInstanceForType() {
        return Any.DEFAULT_INSTANCE;
    }
    
    static {
        RuntimeVersion.validateProtobufGencodeVersion(RuntimeVersion.RuntimeDomain.PUBLIC, 4, 33, 0, "", "Any");
        DEFAULT_INSTANCE = new Any();
        PARSER = new AbstractParser<Any>() {
            @Override
            public Any parsePartialFrom(final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
                final Builder builder = Any.newBuilder();
                try {
                    builder.mergeFrom(input, extensionRegistry);
                }
                catch (final InvalidProtocolBufferException e) {
                    throw e.setUnfinishedMessage(builder.buildPartial());
                }
                catch (final UninitializedMessageException e2) {
                    throw e2.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
                }
                catch (final IOException e3) {
                    throw new InvalidProtocolBufferException(e3).setUnfinishedMessage(builder.buildPartial());
                }
                return builder.buildPartial();
            }
        };
    }
    
    public static final class Builder extends GeneratedMessage.Builder<Builder> implements AnyOrBuilder
    {
        private int bitField0_;
        private Object typeUrl_;
        private ByteString value_;
        
        public static final Descriptors.Descriptor getDescriptor() {
            return AnyProto.internal_static_google_protobuf_Any_descriptor;
        }
        
        @Override
        protected FieldAccessorTable internalGetFieldAccessorTable() {
            return AnyProto.internal_static_google_protobuf_Any_fieldAccessorTable.ensureFieldAccessorsInitialized(Any.class, Builder.class);
        }
        
        private Builder() {
            this.typeUrl_ = "";
            this.value_ = ByteString.EMPTY;
        }
        
        private Builder(final BuilderParent parent) {
            super(parent);
            this.typeUrl_ = "";
            this.value_ = ByteString.EMPTY;
        }
        
        @Override
        public Builder clear() {
            super.clear();
            this.bitField0_ = 0;
            this.typeUrl_ = "";
            this.value_ = ByteString.EMPTY;
            return this;
        }
        
        @Override
        public Descriptors.Descriptor getDescriptorForType() {
            return AnyProto.internal_static_google_protobuf_Any_descriptor;
        }
        
        @Override
        public Any getDefaultInstanceForType() {
            return Any.getDefaultInstance();
        }
        
        @Override
        public Any build() {
            final Any result = this.buildPartial();
            if (!result.isInitialized()) {
                throw AbstractMessage.Builder.newUninitializedMessageException(result);
            }
            return result;
        }
        
        @Override
        public Any buildPartial() {
            final Any result = new Any(this, null);
            if (this.bitField0_ != 0) {
                this.buildPartial0(result);
            }
            this.onBuilt();
            return result;
        }
        
        private void buildPartial0(final Any result) {
            final int from_bitField0_ = this.bitField0_;
            if ((from_bitField0_ & 0x1) != 0x0) {
                result.typeUrl_ = this.typeUrl_;
            }
            if ((from_bitField0_ & 0x2) != 0x0) {
                result.value_ = this.value_;
            }
        }
        
        @Override
        public Builder mergeFrom(final Message other) {
            if (other instanceof Any) {
                return this.mergeFrom((Any)other);
            }
            super.mergeFrom(other);
            return this;
        }
        
        public Builder mergeFrom(final Any other) {
            if (other == Any.getDefaultInstance()) {
                return this;
            }
            if (!other.getTypeUrl().isEmpty()) {
                this.typeUrl_ = other.typeUrl_;
                this.bitField0_ |= 0x1;
                this.onChanged();
            }
            if (!other.getValue().isEmpty()) {
                this.setValue(other.getValue());
            }
            this.mergeUnknownFields(other.getUnknownFields());
            this.onChanged();
            return this;
        }
        
        @Override
        public final boolean isInitialized() {
            return true;
        }
        
        @Override
        public Builder mergeFrom(final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException {
            if (extensionRegistry == null) {
                throw new NullPointerException();
            }
            try {
                boolean done = false;
                while (!done) {
                    final int tag = input.readTag();
                    switch (tag) {
                        case 0: {
                            done = true;
                            continue;
                        }
                        case 10: {
                            this.typeUrl_ = input.readStringRequireUtf8();
                            this.bitField0_ |= 0x1;
                            continue;
                        }
                        case 18: {
                            this.value_ = input.readBytes();
                            this.bitField0_ |= 0x2;
                            continue;
                        }
                        default: {
                            if (!super.parseUnknownField(input, extensionRegistry, tag)) {
                                done = true;
                                continue;
                            }
                            continue;
                        }
                    }
                }
            }
            catch (final InvalidProtocolBufferException e) {
                throw e.unwrapIOException();
            }
            finally {
                this.onChanged();
            }
            return this;
        }
        
        @Override
        public String getTypeUrl() {
            final Object ref = this.typeUrl_;
            if (!(ref instanceof String)) {
                final ByteString bs = (ByteString)ref;
                final String s = bs.toStringUtf8();
                return (String)(this.typeUrl_ = s);
            }
            return (String)ref;
        }
        
        @Override
        public ByteString getTypeUrlBytes() {
            final Object ref = this.typeUrl_;
            if (ref instanceof String) {
                final ByteString b = ByteString.copyFromUtf8((String)ref);
                return (ByteString)(this.typeUrl_ = b);
            }
            return (ByteString)ref;
        }
        
        public Builder setTypeUrl(final String value) {
            if (value == null) {
                throw new NullPointerException();
            }
            this.typeUrl_ = value;
            this.bitField0_ |= 0x1;
            this.onChanged();
            return this;
        }
        
        public Builder clearTypeUrl() {
            this.typeUrl_ = Any.getDefaultInstance().getTypeUrl();
            this.bitField0_ &= 0xFFFFFFFE;
            this.onChanged();
            return this;
        }
        
        public Builder setTypeUrlBytes(final ByteString value) {
            if (value == null) {
                throw new NullPointerException();
            }
            AbstractMessageLite.checkByteStringIsUtf8(value);
            this.typeUrl_ = value;
            this.bitField0_ |= 0x1;
            this.onChanged();
            return this;
        }
        
        @Override
        public ByteString getValue() {
            return this.value_;
        }
        
        public Builder setValue(final ByteString value) {
            if (value == null) {
                throw new NullPointerException();
            }
            this.value_ = value;
            this.bitField0_ |= 0x2;
            this.onChanged();
            return this;
        }
        
        public Builder clearValue() {
            this.bitField0_ &= 0xFFFFFFFD;
            this.value_ = Any.getDefaultInstance().getValue();
            this.onChanged();
            return this;
        }
    }
}
