// 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.RepeatedMessage;

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

    /**
     * <code>optional bool Limit = 1;</code>
     */
    private boolean limit;

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

    /**
     * <code>repeated .Friend Friends = 2;</code>
     */
    private final RepeatedMessage<Public.Friend> friends = RepeatedMessage.newEmptyInstance(Public.Friend.getFactory());

    /**
     * <code>repeated .Friend Invites = 3;</code>
     */
    private final RepeatedMessage<Public.Friend> invites = RepeatedMessage.newEmptyInstance(Public.Friend.getFactory());

    private FriendAllAgreeResp() {
    }

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

    /**
     * <code>optional bool Limit = 1;</code>
     * @return whether the limit field is set
     */
    public boolean hasLimit() {
      return (bitField0_ & 0x00000001) != 0;
    }

    /**
     * <code>optional bool Limit = 1;</code>
     * @return this
     */
    public FriendAllAgreeResp clearLimit() {
      bitField0_ &= ~0x00000001;
      limit = false;
      return this;
    }

    /**
     * <code>optional bool Limit = 1;</code>
     * @return the limit
     */
    public boolean getLimit() {
      return limit;
    }

    /**
     * <code>optional bool Limit = 1;</code>
     * @param value the limit to set
     * @return this
     */
    public FriendAllAgreeResp setLimit(final boolean value) {
      bitField0_ |= 0x00000001;
      limit = value;
      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 FriendAllAgreeResp 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 FriendAllAgreeResp 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 FriendAllAgreeResp 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 FriendAllAgreeResp setNextPackage(final byte... values) {
      bitField0_ |= 0x00000002;
      nextPackage.copyFrom(values);
      return this;
    }

    /**
     * <code>repeated .Friend Friends = 2;</code>
     * @return whether the friends field is set
     */
    public boolean hasFriends() {
      return (bitField0_ & 0x00000004) != 0;
    }

    /**
     * <code>repeated .Friend Friends = 2;</code>
     * @return this
     */
    public FriendAllAgreeResp clearFriends() {
      bitField0_ &= ~0x00000004;
      friends.clear();
      return this;
    }

    /**
     * <code>repeated .Friend Friends = 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 #getMutableFriends()} if you want to modify it.
     *
     * @return internal storage object for reading
     */
    public RepeatedMessage<Public.Friend> getFriends() {
      return friends;
    }

    /**
     * <code>repeated .Friend Friends = 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 RepeatedMessage<Public.Friend> getMutableFriends() {
      bitField0_ |= 0x00000004;
      return friends;
    }

    /**
     * <code>repeated .Friend Friends = 2;</code>
     * @param value the friends to add
     * @return this
     */
    public FriendAllAgreeResp addFriends(final Public.Friend value) {
      bitField0_ |= 0x00000004;
      friends.add(value);
      return this;
    }

    /**
     * <code>repeated .Friend Friends = 2;</code>
     * @param values the friends to add
     * @return this
     */
    public FriendAllAgreeResp addAllFriends(final Public.Friend... values) {
      bitField0_ |= 0x00000004;
      friends.addAll(values);
      return this;
    }

    /**
     * <code>repeated .Friend Invites = 3;</code>
     * @return whether the invites field is set
     */
    public boolean hasInvites() {
      return (bitField0_ & 0x00000008) != 0;
    }

    /**
     * <code>repeated .Friend Invites = 3;</code>
     * @return this
     */
    public FriendAllAgreeResp clearInvites() {
      bitField0_ &= ~0x00000008;
      invites.clear();
      return this;
    }

    /**
     * <code>repeated .Friend Invites = 3;</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 #getMutableInvites()} if you want to modify it.
     *
     * @return internal storage object for reading
     */
    public RepeatedMessage<Public.Friend> getInvites() {
      return invites;
    }

    /**
     * <code>repeated .Friend Invites = 3;</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 RepeatedMessage<Public.Friend> getMutableInvites() {
      bitField0_ |= 0x00000008;
      return invites;
    }

    /**
     * <code>repeated .Friend Invites = 3;</code>
     * @param value the invites to add
     * @return this
     */
    public FriendAllAgreeResp addInvites(final Public.Friend value) {
      bitField0_ |= 0x00000008;
      invites.add(value);
      return this;
    }

    /**
     * <code>repeated .Friend Invites = 3;</code>
     * @param values the invites to add
     * @return this
     */
    public FriendAllAgreeResp addAllInvites(final Public.Friend... values) {
      bitField0_ |= 0x00000008;
      invites.addAll(values);
      return this;
    }

    @Override
    public FriendAllAgreeResp copyFrom(final FriendAllAgreeResp other) {
      cachedSize = other.cachedSize;
      if ((bitField0_ | other.bitField0_) != 0) {
        bitField0_ = other.bitField0_;
        limit = other.limit;
        nextPackage.copyFrom(other.nextPackage);
        friends.copyFrom(other.friends);
        invites.copyFrom(other.invites);
      }
      return this;
    }

    @Override
    public FriendAllAgreeResp mergeFrom(final FriendAllAgreeResp other) {
      if (other.isEmpty()) {
        return this;
      }
      cachedSize = -1;
      if (other.hasLimit()) {
        setLimit(other.limit);
      }
      if (other.hasNextPackage()) {
        getMutableNextPackage().copyFrom(other.nextPackage);
      }
      if (other.hasFriends()) {
        getMutableFriends().addAll(other.friends);
      }
      if (other.hasInvites()) {
        getMutableInvites().addAll(other.invites);
      }
      return this;
    }

    @Override
    public FriendAllAgreeResp clear() {
      if (isEmpty()) {
        return this;
      }
      cachedSize = -1;
      bitField0_ = 0;
      limit = false;
      nextPackage.clear();
      friends.clear();
      invites.clear();
      return this;
    }

    @Override
    public FriendAllAgreeResp clearQuick() {
      if (isEmpty()) {
        return this;
      }
      cachedSize = -1;
      bitField0_ = 0;
      nextPackage.clear();
      friends.clearQuick();
      invites.clearQuick();
      return this;
    }

    @Override
    public boolean equals(Object o) {
      if (o == this) {
        return true;
      }
      if (!(o instanceof FriendAllAgreeResp)) {
        return false;
      }
      FriendAllAgreeResp other = (FriendAllAgreeResp) o;
      return bitField0_ == other.bitField0_
        && (!hasLimit() || limit == other.limit)
        && (!hasNextPackage() || nextPackage.equals(other.nextPackage))
        && (!hasFriends() || friends.equals(other.friends))
        && (!hasInvites() || invites.equals(other.invites));
    }

    @Override
    public void writeTo(final ProtoSink output) throws IOException {
      if ((bitField0_ & 0x00000001) != 0) {
        output.writeRawByte((byte) 8);
        output.writeBoolNoTag(limit);
      }
      if ((bitField0_ & 0x00000002) != 0) {
        output.writeRawLittleEndian16((short) 32762);
        output.writeBytesNoTag(nextPackage);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        for (int i = 0; i < friends.length(); i++) {
          output.writeRawByte((byte) 18);
          output.writeMessageNoTag(friends.get(i));
        }
      }
      if ((bitField0_ & 0x00000008) != 0) {
        for (int i = 0; i < invites.length(); i++) {
          output.writeRawByte((byte) 26);
          output.writeMessageNoTag(invites.get(i));
        }
      }
    }

    @Override
    protected int computeSerializedSize() {
      int size = 0;
      if ((bitField0_ & 0x00000001) != 0) {
        size += 2;
      }
      if ((bitField0_ & 0x00000002) != 0) {
        size += 2 + ProtoSink.computeBytesSizeNoTag(nextPackage);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        size += (1 * friends.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(friends);
      }
      if ((bitField0_ & 0x00000008) != 0) {
        size += (1 * invites.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(invites);
      }
      return size;
    }

    @Override
    @SuppressWarnings("fallthrough")
    public FriendAllAgreeResp mergeFrom(final ProtoSource input) throws IOException {
      // Enabled Fall-Through Optimization (QuickBuffers)
      int tag = input.readTag();
      while (true) {
        switch (tag) {
          case 8: {
            // limit
            limit = input.readBool();
            bitField0_ |= 0x00000001;
            tag = input.readTag();
            if (tag != 16378) {
              break;
            }
          }
          case 16378: {
            // nextPackage
            input.readBytes(nextPackage);
            bitField0_ |= 0x00000002;
            tag = input.readTag();
            if (tag != 18) {
              break;
            }
          }
          case 18: {
            // friends
            tag = input.readRepeatedMessage(friends, tag);
            bitField0_ |= 0x00000004;
            if (tag != 26) {
              break;
            }
          }
          case 26: {
            // invites
            tag = input.readRepeatedMessage(invites, tag);
            bitField0_ |= 0x00000008;
            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.writeBool(FieldNames.limit, limit);
      }
      if ((bitField0_ & 0x00000002) != 0) {
        output.writeBytes(FieldNames.nextPackage, nextPackage);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        output.writeRepeatedMessage(FieldNames.friends, friends);
      }
      if ((bitField0_ & 0x00000008) != 0) {
        output.writeRepeatedMessage(FieldNames.invites, invites);
      }
      output.endObject();
    }

    @Override
    public FriendAllAgreeResp mergeFrom(final JsonSource input) throws IOException {
      if (!input.beginObject()) {
        return this;
      }
      while (!input.isAtEnd()) {
        switch (input.readFieldHash()) {
          case 73423771: {
            if (input.isAtField(FieldNames.limit)) {
              if (!input.trySkipNullValue()) {
                limit = input.readBool();
                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 1064558965: {
            if (input.isAtField(FieldNames.friends)) {
              if (!input.trySkipNullValue()) {
                input.readRepeatedMessage(friends);
                bitField0_ |= 0x00000004;
              }
            } else {
              input.skipUnknownField();
            }
            break;
          }
          case -670283158: {
            if (input.isAtField(FieldNames.invites)) {
              if (!input.trySkipNullValue()) {
                input.readRepeatedMessage(invites);
                bitField0_ |= 0x00000008;
              }
            } else {
              input.skipUnknownField();
            }
            break;
          }
          default: {
            input.skipUnknownField();
            break;
          }
        }
      }
      input.endObject();
      return this;
    }

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

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

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

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

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

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

    private enum FriendAllAgreeRespFactory implements MessageFactory<FriendAllAgreeResp> {
      INSTANCE;

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

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

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

      static final FieldName friends = FieldName.forField("Friends");

      static final FieldName invites = FieldName.forField("Invites");
    }
  }
}
