// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
// Code generated by protocol buffer compiler. Do not edit!
package org.wpilib.math.proto;

import java.io.IOException;
import us.hebi.quickbuf.Descriptors;
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.ProtoUtil;

/**
 * Protobuf type {@code ProtobufQuaternion}
 */
@SuppressWarnings("hiding")
public final class ProtobufQuaternion extends ProtoMessage<ProtobufQuaternion> implements Cloneable {
  private static final long serialVersionUID = 0L;

  /**
   * <code>optional double w = 1;</code>
   */
  private double w;

  /**
   * <code>optional double x = 2;</code>
   */
  private double x;

  /**
   * <code>optional double y = 3;</code>
   */
  private double y;

  /**
   * <code>optional double z = 4;</code>
   */
  private double z;

  private ProtobufQuaternion() {
  }

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

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

  /**
   * <code>optional double w = 1;</code>
   * @return this
   */
  public ProtobufQuaternion clearW() {
    bitField0_ &= ~0x00000001;
    w = 0D;
    return this;
  }

  /**
   * <code>optional double w = 1;</code>
   * @return the w
   */
  public double getW() {
    return w;
  }

  /**
   * <code>optional double w = 1;</code>
   * @param value the w to set
   * @return this
   */
  public ProtobufQuaternion setW(final double value) {
    bitField0_ |= 0x00000001;
    w = value;
    return this;
  }

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

  /**
   * <code>optional double x = 2;</code>
   * @return this
   */
  public ProtobufQuaternion clearX() {
    bitField0_ &= ~0x00000002;
    x = 0D;
    return this;
  }

  /**
   * <code>optional double x = 2;</code>
   * @return the x
   */
  public double getX() {
    return x;
  }

  /**
   * <code>optional double x = 2;</code>
   * @param value the x to set
   * @return this
   */
  public ProtobufQuaternion setX(final double value) {
    bitField0_ |= 0x00000002;
    x = value;
    return this;
  }

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

  /**
   * <code>optional double y = 3;</code>
   * @return this
   */
  public ProtobufQuaternion clearY() {
    bitField0_ &= ~0x00000004;
    y = 0D;
    return this;
  }

  /**
   * <code>optional double y = 3;</code>
   * @return the y
   */
  public double getY() {
    return y;
  }

  /**
   * <code>optional double y = 3;</code>
   * @param value the y to set
   * @return this
   */
  public ProtobufQuaternion setY(final double value) {
    bitField0_ |= 0x00000004;
    y = value;
    return this;
  }

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

  /**
   * <code>optional double z = 4;</code>
   * @return this
   */
  public ProtobufQuaternion clearZ() {
    bitField0_ &= ~0x00000008;
    z = 0D;
    return this;
  }

  /**
   * <code>optional double z = 4;</code>
   * @return the z
   */
  public double getZ() {
    return z;
  }

  /**
   * <code>optional double z = 4;</code>
   * @param value the z to set
   * @return this
   */
  public ProtobufQuaternion setZ(final double value) {
    bitField0_ |= 0x00000008;
    z = value;
    return this;
  }

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

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

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

  @Override
  public ProtobufQuaternion 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 ProtobufQuaternion)) {
      return false;
    }
    ProtobufQuaternion other = (ProtobufQuaternion) o;
    return bitField0_ == other.bitField0_
      && (!hasW() || ProtoUtil.isEqual(w, other.w))
      && (!hasX() || ProtoUtil.isEqual(x, other.x))
      && (!hasY() || ProtoUtil.isEqual(y, other.y))
      && (!hasZ() || ProtoUtil.isEqual(z, other.z));
  }

  @Override
  public void writeTo(final ProtoSink output) throws IOException {
    if ((bitField0_ & 0x00000001) != 0) {
      output.writeRawByte((byte) 9);
      output.writeDoubleNoTag(w);
    }
    if ((bitField0_ & 0x00000002) != 0) {
      output.writeRawByte((byte) 17);
      output.writeDoubleNoTag(x);
    }
    if ((bitField0_ & 0x00000004) != 0) {
      output.writeRawByte((byte) 25);
      output.writeDoubleNoTag(y);
    }
    if ((bitField0_ & 0x00000008) != 0) {
      output.writeRawByte((byte) 33);
      output.writeDoubleNoTag(z);
    }
  }

  @Override
  protected int computeSerializedSize() {
    int size = 0;
    if ((bitField0_ & 0x00000001) != 0) {
      size += 9;
    }
    if ((bitField0_ & 0x00000002) != 0) {
      size += 9;
    }
    if ((bitField0_ & 0x00000004) != 0) {
      size += 9;
    }
    if ((bitField0_ & 0x00000008) != 0) {
      size += 9;
    }
    return size;
  }

  @Override
  @SuppressWarnings("fallthrough")
  public ProtobufQuaternion mergeFrom(final ProtoSource input) throws IOException {
    // Enabled Fall-Through Optimization (QuickBuffers)
    int tag = input.readTag();
    while (true) {
      switch (tag) {
        case 9: {
          // w
          w = input.readDouble();
          bitField0_ |= 0x00000001;
          tag = input.readTag();
          if (tag != 17) {
            break;
          }
        }
        case 17: {
          // x
          x = input.readDouble();
          bitField0_ |= 0x00000002;
          tag = input.readTag();
          if (tag != 25) {
            break;
          }
        }
        case 25: {
          // y
          y = input.readDouble();
          bitField0_ |= 0x00000004;
          tag = input.readTag();
          if (tag != 33) {
            break;
          }
        }
        case 33: {
          // z
          z = input.readDouble();
          bitField0_ |= 0x00000008;
          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.writeDouble(FieldNames.w, w);
    }
    if ((bitField0_ & 0x00000002) != 0) {
      output.writeDouble(FieldNames.x, x);
    }
    if ((bitField0_ & 0x00000004) != 0) {
      output.writeDouble(FieldNames.y, y);
    }
    if ((bitField0_ & 0x00000008) != 0) {
      output.writeDouble(FieldNames.z, z);
    }
    output.endObject();
  }

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

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

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

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

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

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

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

  /**
   * @return this type's descriptor.
   */
  public static Descriptors.Descriptor getDescriptor() {
    return ProtobufGeometry3dDescriptor.wpi_proto_ProtobufQuaternion_descriptor;
  }

  private enum ProtobufQuaternionFactory implements MessageFactory<ProtobufQuaternion> {
    INSTANCE;

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

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

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

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

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