// Code generated by protocol buffer compiler. Do not edit!
package emu.nebula.proto;

import java.io.IOException;
import us.hebi.quickbuf.FieldName;
import us.hebi.quickbuf.InvalidProtocolBufferException;
import us.hebi.quickbuf.JsonSink;
import us.hebi.quickbuf.JsonSource;
import us.hebi.quickbuf.MessageFactory;
import us.hebi.quickbuf.ProtoMessage;
import us.hebi.quickbuf.ProtoSink;
import us.hebi.quickbuf.ProtoSource;
import us.hebi.quickbuf.RepeatedByte;
import us.hebi.quickbuf.Utf8String;

public final class AnyOuterClass {
  /**
   * Protobuf type {@code Any}
   */
  public static final class Any extends ProtoMessage<Any> implements Cloneable {
    private static final long serialVersionUID = 0L;

    /**
     * <code>optional bytes value = 2;</code>
     */
    private final RepeatedByte value_ = RepeatedByte.newEmptyInstance();

    /**
     * <code>optional bytes NextPackage = 2047;</code>
     */
    private final RepeatedByte nextPackage = RepeatedByte.newEmptyInstance();

    /**
     * <code>optional string type_url = 1;</code>
     */
    private final Utf8String typeUrl = Utf8String.newEmptyInstance();

    private Any() {
    }

    /**
     * @return a new empty instance of {@code Any}
     */
    public static Any newInstance() {
      return new Any();
    }

    /**
     * <code>optional bytes value = 2;</code>
     * @return whether the value_ field is set
     */
    public boolean hasValue() {
      return (bitField0_ & 0x00000001) != 0;
    }

    /**
     * <code>optional bytes value = 2;</code>
     * @return this
     */
    public Any clearValue() {
      bitField0_ &= ~0x00000001;
      value_.clear();
      return this;
    }

    /**
     * <code>optional bytes value = 2;</code>
     *
     * This method returns the internal storage object without modifying any has state.
     * The returned object should not be modified and be treated as read-only.
     *
     * Use {@link #getMutableValue()} if you want to modify it.
     *
     * @return internal storage object for reading
     */
    public RepeatedByte getValue() {
      return value_;
    }

    /**
     * <code>optional bytes value = 2;</code>
     *
     * This method returns the internal storage object and sets the corresponding
     * has state. The returned object will become part of this message and its
     * contents may be modified as long as the has state is not cleared.
     *
     * @return internal storage object for modifications
     */
    public RepeatedByte getMutableValue() {
      bitField0_ |= 0x00000001;
      return value_;
    }

    /**
     * <code>optional bytes value = 2;</code>
     * @param value the value_ to add
     * @return this
     */
    public Any addValue(final byte value) {
      bitField0_ |= 0x00000001;
      value_.add(value);
      return this;
    }

    /**
     * <code>optional bytes value = 2;</code>
     * @param values the value_ to add
     * @return this
     */
    public Any addAllValue(final byte... values) {
      bitField0_ |= 0x00000001;
      value_.addAll(values);
      return this;
    }

    /**
     * <code>optional bytes value = 2;</code>
     * @param values the value_ to set
     * @return this
     */
    public Any setValue(final byte... values) {
      bitField0_ |= 0x00000001;
      value_.copyFrom(values);
      return this;
    }

    /**
     * <code>optional bytes NextPackage = 2047;</code>
     * @return whether the nextPackage field is set
     */
    public boolean hasNextPackage() {
      return (bitField0_ & 0x00000002) != 0;
    }

    /**
     * <code>optional bytes NextPackage = 2047;</code>
     * @return this
     */
    public Any clearNextPackage() {
      bitField0_ &= ~0x00000002;
      nextPackage.clear();
      return this;
    }

    /**
     * <code>optional bytes NextPackage = 2047;</code>
     *
     * This method returns the internal storage object without modifying any has state.
     * The returned object should not be modified and be treated as read-only.
     *
     * Use {@link #getMutableNextPackage()} if you want to modify it.
     *
     * @return internal storage object for reading
     */
    public RepeatedByte getNextPackage() {
      return nextPackage;
    }

    /**
     * <code>optional bytes NextPackage = 2047;</code>
     *
     * This method returns the internal storage object and sets the corresponding
     * has state. The returned object will become part of this message and its
     * contents may be modified as long as the has state is not cleared.
     *
     * @return internal storage object for modifications
     */
    public RepeatedByte getMutableNextPackage() {
      bitField0_ |= 0x00000002;
      return nextPackage;
    }

    /**
     * <code>optional bytes NextPackage = 2047;</code>
     * @param value the nextPackage to add
     * @return this
     */
    public Any addNextPackage(final byte value) {
      bitField0_ |= 0x00000002;
      nextPackage.add(value);
      return this;
    }

    /**
     * <code>optional bytes NextPackage = 2047;</code>
     * @param values the nextPackage to add
     * @return this
     */
    public Any addAllNextPackage(final byte... values) {
      bitField0_ |= 0x00000002;
      nextPackage.addAll(values);
      return this;
    }

    /**
     * <code>optional bytes NextPackage = 2047;</code>
     * @param values the nextPackage to set
     * @return this
     */
    public Any setNextPackage(final byte... values) {
      bitField0_ |= 0x00000002;
      nextPackage.copyFrom(values);
      return this;
    }

    /**
     * <code>optional string type_url = 1;</code>
     * @return whether the typeUrl field is set
     */
    public boolean hasTypeUrl() {
      return (bitField0_ & 0x00000004) != 0;
    }

    /**
     * <code>optional string type_url = 1;</code>
     * @return this
     */
    public Any clearTypeUrl() {
      bitField0_ &= ~0x00000004;
      typeUrl.clear();
      return this;
    }

    /**
     * <code>optional string type_url = 1;</code>
     * @return the typeUrl
     */
    public String getTypeUrl() {
      return typeUrl.getString();
    }

    /**
     * <code>optional string type_url = 1;</code>
     * @return internal {@code Utf8String} representation of typeUrl for reading
     */
    public Utf8String getTypeUrlBytes() {
      return this.typeUrl;
    }

    /**
     * <code>optional string type_url = 1;</code>
     * @return internal {@code Utf8String} representation of typeUrl for modifications
     */
    public Utf8String getMutableTypeUrlBytes() {
      bitField0_ |= 0x00000004;
      return this.typeUrl;
    }

    /**
     * <code>optional string type_url = 1;</code>
     * @param value the typeUrl to set
     * @return this
     */
    public Any setTypeUrl(final CharSequence value) {
      bitField0_ |= 0x00000004;
      typeUrl.copyFrom(value);
      return this;
    }

    /**
     * <code>optional string type_url = 1;</code>
     * @param value the typeUrl to set
     * @return this
     */
    public Any setTypeUrl(final Utf8String value) {
      bitField0_ |= 0x00000004;
      typeUrl.copyFrom(value);
      return this;
    }

    @Override
    public Any copyFrom(final Any other) {
      cachedSize = other.cachedSize;
      if ((bitField0_ | other.bitField0_) != 0) {
        bitField0_ = other.bitField0_;
        value_.copyFrom(other.value_);
        nextPackage.copyFrom(other.nextPackage);
        typeUrl.copyFrom(other.typeUrl);
      }
      return this;
    }

    @Override
    public Any mergeFrom(final Any other) {
      if (other.isEmpty()) {
        return this;
      }
      cachedSize = -1;
      if (other.hasValue()) {
        getMutableValue().copyFrom(other.value_);
      }
      if (other.hasNextPackage()) {
        getMutableNextPackage().copyFrom(other.nextPackage);
      }
      if (other.hasTypeUrl()) {
        getMutableTypeUrlBytes().copyFrom(other.typeUrl);
      }
      return this;
    }

    @Override
    public Any clear() {
      if (isEmpty()) {
        return this;
      }
      cachedSize = -1;
      bitField0_ = 0;
      value_.clear();
      nextPackage.clear();
      typeUrl.clear();
      return this;
    }

    @Override
    public Any clearQuick() {
      if (isEmpty()) {
        return this;
      }
      cachedSize = -1;
      bitField0_ = 0;
      value_.clear();
      nextPackage.clear();
      typeUrl.clear();
      return this;
    }

    @Override
    public boolean equals(Object o) {
      if (o == this) {
        return true;
      }
      if (!(o instanceof Any)) {
        return false;
      }
      Any other = (Any) o;
      return bitField0_ == other.bitField0_
        && (!hasValue() || value_.equals(other.value_))
        && (!hasNextPackage() || nextPackage.equals(other.nextPackage))
        && (!hasTypeUrl() || typeUrl.equals(other.typeUrl));
    }

    @Override
    public void writeTo(final ProtoSink output) throws IOException {
      if ((bitField0_ & 0x00000001) != 0) {
        output.writeRawByte((byte) 18);
        output.writeBytesNoTag(value_);
      }
      if ((bitField0_ & 0x00000002) != 0) {
        output.writeRawLittleEndian16((short) 32762);
        output.writeBytesNoTag(nextPackage);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        output.writeRawByte((byte) 10);
        output.writeStringNoTag(typeUrl);
      }
    }

    @Override
    protected int computeSerializedSize() {
      int size = 0;
      if ((bitField0_ & 0x00000001) != 0) {
        size += 1 + ProtoSink.computeBytesSizeNoTag(value_);
      }
      if ((bitField0_ & 0x00000002) != 0) {
        size += 2 + ProtoSink.computeBytesSizeNoTag(nextPackage);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        size += 1 + ProtoSink.computeStringSizeNoTag(typeUrl);
      }
      return size;
    }

    @Override
    @SuppressWarnings("fallthrough")
    public Any mergeFrom(final ProtoSource input) throws IOException {
      // Enabled Fall-Through Optimization (QuickBuffers)
      int tag = input.readTag();
      while (true) {
        switch (tag) {
          case 18: {
            // value_
            input.readBytes(value_);
            bitField0_ |= 0x00000001;
            tag = input.readTag();
            if (tag != 16378) {
              break;
            }
          }
          case 16378: {
            // nextPackage
            input.readBytes(nextPackage);
            bitField0_ |= 0x00000002;
            tag = input.readTag();
            if (tag != 10) {
              break;
            }
          }
          case 10: {
            // typeUrl
            input.readString(typeUrl);
            bitField0_ |= 0x00000004;
            tag = input.readTag();
            if (tag != 0) {
              break;
            }
          }
          case 0: {
            return this;
          }
          default: {
            if (!input.skipField(tag)) {
              return this;
            }
            tag = input.readTag();
            break;
          }
        }
      }
    }

    @Override
    public void writeTo(final JsonSink output) throws IOException {
      output.beginObject();
      if ((bitField0_ & 0x00000001) != 0) {
        output.writeBytes(FieldNames.value_, value_);
      }
      if ((bitField0_ & 0x00000002) != 0) {
        output.writeBytes(FieldNames.nextPackage, nextPackage);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        output.writeString(FieldNames.typeUrl, typeUrl);
      }
      output.endObject();
    }

    @Override
    public Any mergeFrom(final JsonSource input) throws IOException {
      if (!input.beginObject()) {
        return this;
      }
      while (!input.isAtEnd()) {
        switch (input.readFieldHash()) {
          case 111972721: {
            if (input.isAtField(FieldNames.value_)) {
              if (!input.trySkipNullValue()) {
                input.readBytes(value_);
                bitField0_ |= 0x00000001;
              }
            } else {
              input.skipUnknownField();
            }
            break;
          }
          case -2082324045: {
            if (input.isAtField(FieldNames.nextPackage)) {
              if (!input.trySkipNullValue()) {
                input.readBytes(nextPackage);
                bitField0_ |= 0x00000002;
              }
            } else {
              input.skipUnknownField();
            }
            break;
          }
          case -853099563:
          case -675981590: {
            if (input.isAtField(FieldNames.typeUrl)) {
              if (!input.trySkipNullValue()) {
                input.readString(typeUrl);
                bitField0_ |= 0x00000004;
              }
            } else {
              input.skipUnknownField();
            }
            break;
          }
          default: {
            input.skipUnknownField();
            break;
          }
        }
      }
      input.endObject();
      return this;
    }

    @Override
    public Any clone() {
      return new Any().copyFrom(this);
    }

    @Override
    public boolean isEmpty() {
      return ((bitField0_) == 0);
    }

    public static Any parseFrom(final byte[] data) throws InvalidProtocolBufferException {
      return ProtoMessage.mergeFrom(new Any(), data).checkInitialized();
    }

    public static Any parseFrom(final ProtoSource input) throws IOException {
      return ProtoMessage.mergeFrom(new Any(), input).checkInitialized();
    }

    public static Any parseFrom(final JsonSource input) throws IOException {
      return ProtoMessage.mergeFrom(new Any(), input).checkInitialized();
    }

    /**
     * @return factory for creating Any messages
     */
    public static MessageFactory<Any> getFactory() {
      return AnyFactory.INSTANCE;
    }

    private enum AnyFactory implements MessageFactory<Any> {
      INSTANCE;

      @Override
      public Any create() {
        return Any.newInstance();
      }
    }

    /**
     * Contains name constants used for serializing JSON
     */
    static class FieldNames {
      static final FieldName value_ = FieldName.forField("value");

      static final FieldName nextPackage = FieldName.forField("NextPackage");

      static final FieldName typeUrl = FieldName.forField("typeUrl", "type_url");
    }
  }
}
