// 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 ProtobufChassisAccelerations}
 */
@SuppressWarnings("hiding")
public final class ProtobufChassisAccelerations extends ProtoMessage<ProtobufChassisAccelerations> implements Cloneable {
  private static final long serialVersionUID = 0L;

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

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

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

  private ProtobufChassisAccelerations() {
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

  @Override
  public ProtobufChassisAccelerations copyFrom(final ProtobufChassisAccelerations other) {
    cachedSize = other.cachedSize;
    if ((bitField0_ | other.bitField0_) != 0) {
      bitField0_ = other.bitField0_;
      ax = other.ax;
      ay = other.ay;
      alpha = other.alpha;
    }
    return this;
  }

  @Override
  public ProtobufChassisAccelerations mergeFrom(final ProtobufChassisAccelerations other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasAx()) {
      setAx(other.ax);
    }
    if (other.hasAy()) {
      setAy(other.ay);
    }
    if (other.hasAlpha()) {
      setAlpha(other.alpha);
    }
    return this;
  }

  @Override
  public ProtobufChassisAccelerations clear() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    ax = 0D;
    ay = 0D;
    alpha = 0D;
    return this;
  }

  @Override
  public ProtobufChassisAccelerations 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 ProtobufChassisAccelerations)) {
      return false;
    }
    ProtobufChassisAccelerations other = (ProtobufChassisAccelerations) o;
    return bitField0_ == other.bitField0_
      && (!hasAx() || ProtoUtil.isEqual(ax, other.ax))
      && (!hasAy() || ProtoUtil.isEqual(ay, other.ay))
      && (!hasAlpha() || ProtoUtil.isEqual(alpha, other.alpha));
  }

  @Override
  public void writeTo(final ProtoSink output) throws IOException {
    if ((bitField0_ & 0x00000001) != 0) {
      output.writeRawByte((byte) 9);
      output.writeDoubleNoTag(ax);
    }
    if ((bitField0_ & 0x00000002) != 0) {
      output.writeRawByte((byte) 17);
      output.writeDoubleNoTag(ay);
    }
    if ((bitField0_ & 0x00000004) != 0) {
      output.writeRawByte((byte) 25);
      output.writeDoubleNoTag(alpha);
    }
  }

  @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;
    }
    return size;
  }

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

  @Override
  public ProtobufChassisAccelerations mergeFrom(final JsonSource input) throws IOException {
    if (!input.beginObject()) {
      return this;
    }
    while (!input.isAtEnd()) {
      switch (input.readFieldHash()) {
        case 3127: {
          if (input.isAtField(FieldNames.ax)) {
            if (!input.trySkipNullValue()) {
              ax = input.readDouble();
              bitField0_ |= 0x00000001;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case 3128: {
          if (input.isAtField(FieldNames.ay)) {
            if (!input.trySkipNullValue()) {
              ay = input.readDouble();
              bitField0_ |= 0x00000002;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case 92909918: {
          if (input.isAtField(FieldNames.alpha)) {
            if (!input.trySkipNullValue()) {
              alpha = input.readDouble();
              bitField0_ |= 0x00000004;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        default: {
          input.skipUnknownField();
          break;
        }
      }
    }
    input.endObject();
    return this;
  }

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

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

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

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

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

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

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

  private enum ProtobufChassisAccelerationsFactory implements MessageFactory<ProtobufChassisAccelerations> {
    INSTANCE;

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

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

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

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