// Code generated by protocol buffer compiler. Do not edit!
package emu.lunarcore.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;

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

    /**
     * <code>optional sint32 x = 1;</code>
     */
    private int x;

    /**
     * <code>optional sint32 y = 2;</code>
     */
    private int y;

    /**
     * <code>optional sint32 z = 3;</code>
     */
    private int z;

    private Vector() {
    }

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

    /**
     * <code>optional sint32 x = 1;</code>
     * @return whether the x field is set
     */
    public boolean hasX() {
      return (bitField0_ & 0x00000001) != 0;
    }

    /**
     * <code>optional sint32 x = 1;</code>
     * @return this
     */
    public Vector clearX() {
      bitField0_ &= ~0x00000001;
      x = 0;
      return this;
    }

    /**
     * <code>optional sint32 x = 1;</code>
     * @return the x
     */
    public int getX() {
      return x;
    }

    /**
     * <code>optional sint32 x = 1;</code>
     * @param value the x to set
     * @return this
     */
    public Vector setX(final int value) {
      bitField0_ |= 0x00000001;
      x = value;
      return this;
    }

    /**
     * <code>optional sint32 y = 2;</code>
     * @return whether the y field is set
     */
    public boolean hasY() {
      return (bitField0_ & 0x00000002) != 0;
    }

    /**
     * <code>optional sint32 y = 2;</code>
     * @return this
     */
    public Vector clearY() {
      bitField0_ &= ~0x00000002;
      y = 0;
      return this;
    }

    /**
     * <code>optional sint32 y = 2;</code>
     * @return the y
     */
    public int getY() {
      return y;
    }

    /**
     * <code>optional sint32 y = 2;</code>
     * @param value the y to set
     * @return this
     */
    public Vector setY(final int value) {
      bitField0_ |= 0x00000002;
      y = value;
      return this;
    }

    /**
     * <code>optional sint32 z = 3;</code>
     * @return whether the z field is set
     */
    public boolean hasZ() {
      return (bitField0_ & 0x00000004) != 0;
    }

    /**
     * <code>optional sint32 z = 3;</code>
     * @return this
     */
    public Vector clearZ() {
      bitField0_ &= ~0x00000004;
      z = 0;
      return this;
    }

    /**
     * <code>optional sint32 z = 3;</code>
     * @return the z
     */
    public int getZ() {
      return z;
    }

    /**
     * <code>optional sint32 z = 3;</code>
     * @param value the z to set
     * @return this
     */
    public Vector setZ(final int value) {
      bitField0_ |= 0x00000004;
      z = value;
      return this;
    }

    @Override
    public Vector copyFrom(final Vector other) {
      cachedSize = other.cachedSize;
      if ((bitField0_ | other.bitField0_) != 0) {
        bitField0_ = other.bitField0_;
        x = other.x;
        y = other.y;
        z = other.z;
      }
      return this;
    }

    @Override
    public Vector mergeFrom(final Vector other) {
      if (other.isEmpty()) {
        return this;
      }
      cachedSize = -1;
      if (other.hasX()) {
        setX(other.x);
      }
      if (other.hasY()) {
        setY(other.y);
      }
      if (other.hasZ()) {
        setZ(other.z);
      }
      return this;
    }

    @Override
    public Vector clear() {
      if (isEmpty()) {
        return this;
      }
      cachedSize = -1;
      bitField0_ = 0;
      x = 0;
      y = 0;
      z = 0;
      return this;
    }

    @Override
    public Vector clearQuick() {
      if (isEmpty()) {
        return this;
      }
      cachedSize = -1;
      bitField0_ = 0;
      return this;
    }

    @Override
    public boolean equals(Object o) {
      if (o == this) {
        return true;
      }
      if (!(o instanceof Vector)) {
        return false;
      }
      Vector other = (Vector) o;
      return bitField0_ == other.bitField0_
        && (!hasX() || x == other.x)
        && (!hasY() || y == other.y)
        && (!hasZ() || z == other.z);
    }

    @Override
    public void writeTo(final ProtoSink output) throws IOException {
      if ((bitField0_ & 0x00000001) != 0) {
        output.writeRawByte((byte) 8);
        output.writeSInt32NoTag(x);
      }
      if ((bitField0_ & 0x00000002) != 0) {
        output.writeRawByte((byte) 16);
        output.writeSInt32NoTag(y);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        output.writeRawByte((byte) 24);
        output.writeSInt32NoTag(z);
      }
    }

    @Override
    protected int computeSerializedSize() {
      int size = 0;
      if ((bitField0_ & 0x00000001) != 0) {
        size += 1 + ProtoSink.computeSInt32SizeNoTag(x);
      }
      if ((bitField0_ & 0x00000002) != 0) {
        size += 1 + ProtoSink.computeSInt32SizeNoTag(y);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        size += 1 + ProtoSink.computeSInt32SizeNoTag(z);
      }
      return size;
    }

    @Override
    @SuppressWarnings("fallthrough")
    public Vector mergeFrom(final ProtoSource input) throws IOException {
      // Enabled Fall-Through Optimization (QuickBuffers)
      int tag = input.readTag();
      while (true) {
        switch (tag) {
          case 8: {
            // x
            x = input.readSInt32();
            bitField0_ |= 0x00000001;
            tag = input.readTag();
            if (tag != 16) {
              break;
            }
          }
          case 16: {
            // y
            y = input.readSInt32();
            bitField0_ |= 0x00000002;
            tag = input.readTag();
            if (tag != 24) {
              break;
            }
          }
          case 24: {
            // z
            z = input.readSInt32();
            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.writeSInt32(FieldNames.x, x);
      }
      if ((bitField0_ & 0x00000002) != 0) {
        output.writeSInt32(FieldNames.y, y);
      }
      if ((bitField0_ & 0x00000004) != 0) {
        output.writeSInt32(FieldNames.z, z);
      }
      output.endObject();
    }

    @Override
    public Vector mergeFrom(final JsonSource input) throws IOException {
      if (!input.beginObject()) {
        return this;
      }
      while (!input.isAtEnd()) {
        switch (input.readFieldHash()) {
          case 120: {
            if (input.isAtField(FieldNames.x)) {
              if (!input.trySkipNullValue()) {
                x = input.readSInt32();
                bitField0_ |= 0x00000001;
              }
            } else {
              input.skipUnknownField();
            }
            break;
          }
          case 121: {
            if (input.isAtField(FieldNames.y)) {
              if (!input.trySkipNullValue()) {
                y = input.readSInt32();
                bitField0_ |= 0x00000002;
              }
            } else {
              input.skipUnknownField();
            }
            break;
          }
          case 122: {
            if (input.isAtField(FieldNames.z)) {
              if (!input.trySkipNullValue()) {
                z = input.readSInt32();
                bitField0_ |= 0x00000004;
              }
            } else {
              input.skipUnknownField();
            }
            break;
          }
          default: {
            input.skipUnknownField();
            break;
          }
        }
      }
      input.endObject();
      return this;
    }

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

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

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

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

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

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

    private enum VectorFactory implements MessageFactory<Vector> {
      INSTANCE;

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

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

      static final FieldName y = FieldName.forField("y");

      static final FieldName z = FieldName.forField("z");
    }
  }
}
