// 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 FriendListGet {
  /**
   * Protobuf type {@code FriendListGetResp}
   */
  public static final class FriendListGetResp extends ProtoMessage<FriendListGetResp> implements Cloneable {
    private static final long serialVersionUID = 0L;

    /**
     * <code>optional uint32 ReceiveEnergyCnt = 3;</code>
     */
    private int receiveEnergyCnt;

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

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

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

    private FriendListGetResp() {
    }

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

    /**
     * <code>optional uint32 ReceiveEnergyCnt = 3;</code>
     * @return whether the receiveEnergyCnt field is set
     */
    public boolean hasReceiveEnergyCnt() {
      return (bitField0_ & 0x00000001) != 0;
    }

    /**
     * <code>optional uint32 ReceiveEnergyCnt = 3;</code>
     * @return this
     */
    public FriendListGetResp clearReceiveEnergyCnt() {
      bitField0_ &= ~0x00000001;
      receiveEnergyCnt = 0;
      return this;
    }

    /**
     * <code>optional uint32 ReceiveEnergyCnt = 3;</code>
     * @return the receiveEnergyCnt
     */
    public int getReceiveEnergyCnt() {
      return receiveEnergyCnt;
    }

    /**
     * <code>optional uint32 ReceiveEnergyCnt = 3;</code>
     * @param value the receiveEnergyCnt to set
     * @return this
     */
    public FriendListGetResp setReceiveEnergyCnt(final int value) {
      bitField0_ |= 0x00000001;
      receiveEnergyCnt = 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 FriendListGetResp 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 FriendListGetResp 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 FriendListGetResp 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 FriendListGetResp setNextPackage(final byte... values) {
      bitField0_ |= 0x00000002;
      nextPackage.copyFrom(values);
      return this;
    }

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

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

    /**
     * <code>repeated .FriendDetail Friends = 1;</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.FriendDetail> getFriends() {
      return friends;
    }

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

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

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

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

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

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

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

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

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

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

    @Override
    public FriendListGetResp mergeFrom(final FriendListGetResp other) {
      if (other.isEmpty()) {
        return this;
      }
      cachedSize = -1;
      if (other.hasReceiveEnergyCnt()) {
        setReceiveEnergyCnt(other.receiveEnergyCnt);
      }
      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 FriendListGetResp clear() {
      if (isEmpty()) {
        return this;
      }
      cachedSize = -1;
      bitField0_ = 0;
      receiveEnergyCnt = 0;
      nextPackage.clear();
      friends.clear();
      invites.clear();
      return this;
    }

    @Override
    public FriendListGetResp 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 FriendListGetResp)) {
        return false;
      }
      FriendListGetResp other = (FriendListGetResp) o;
      return bitField0_ == other.bitField0_
        && (!hasReceiveEnergyCnt() || receiveEnergyCnt == other.receiveEnergyCnt)
        && (!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) 24);
        output.writeUInt32NoTag(receiveEnergyCnt);
      }
      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) 10);
          output.writeMessageNoTag(friends.get(i));
        }
      }
      if ((bitField0_ & 0x00000008) != 0) {
        for (int i = 0; i < invites.length(); i++) {
          output.writeRawByte((byte) 18);
          output.writeMessageNoTag(invites.get(i));
        }
      }
    }

    @Override
    protected int computeSerializedSize() {
      int size = 0;
      if ((bitField0_ & 0x00000001) != 0) {
        size += 1 + ProtoSink.computeUInt32SizeNoTag(receiveEnergyCnt);
      }
      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 FriendListGetResp mergeFrom(final ProtoSource input) throws IOException {
      // Enabled Fall-Through Optimization (QuickBuffers)
      int tag = input.readTag();
      while (true) {
        switch (tag) {
          case 24: {
            // receiveEnergyCnt
            receiveEnergyCnt = input.readUInt32();
            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: {
            // friends
            tag = input.readRepeatedMessage(friends, tag);
            bitField0_ |= 0x00000004;
            if (tag != 18) {
              break;
            }
          }
          case 18: {
            // 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.writeUInt32(FieldNames.receiveEnergyCnt, receiveEnergyCnt);
      }
      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 FriendListGetResp mergeFrom(final JsonSource input) throws IOException {
      if (!input.beginObject()) {
        return this;
      }
      while (!input.isAtEnd()) {
        switch (input.readFieldHash()) {
          case -1854543298: {
            if (input.isAtField(FieldNames.receiveEnergyCnt)) {
              if (!input.trySkipNullValue()) {
                receiveEnergyCnt = input.readUInt32();
                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 FriendListGetResp clone() {
      return new FriendListGetResp().copyFrom(this);
    }

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

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

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

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

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

    private enum FriendListGetRespFactory implements MessageFactory<FriendListGetResp> {
      INSTANCE;

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

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

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

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

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