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

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

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

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

  private ProtobufChassisVelocities() {
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

  @Override
  public ProtobufChassisVelocities copyFrom(final ProtobufChassisVelocities other) {
    cachedSize = other.cachedSize;
    if ((bitField0_ | other.bitField0_) != 0) {
      bitField0_ = other.bitField0_;
      vx = other.vx;
      vy = other.vy;
      omega = other.omega;
    }
    return this;
  }

  @Override
  public ProtobufChassisVelocities mergeFrom(final ProtobufChassisVelocities other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasVx()) {
      setVx(other.vx);
    }
    if (other.hasVy()) {
      setVy(other.vy);
    }
    if (other.hasOmega()) {
      setOmega(other.omega);
    }
    return this;
  }

  @Override
  public ProtobufChassisVelocities clear() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    vx = 0D;
    vy = 0D;
    omega = 0D;
    return this;
  }

  @Override
  public ProtobufChassisVelocities 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 ProtobufChassisVelocities)) {
      return false;
    }
    ProtobufChassisVelocities other = (ProtobufChassisVelocities) o;
    return bitField0_ == other.bitField0_
      && (!hasVx() || ProtoUtil.isEqual(vx, other.vx))
      && (!hasVy() || ProtoUtil.isEqual(vy, other.vy))
      && (!hasOmega() || ProtoUtil.isEqual(omega, other.omega));
  }

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

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

  @Override
  public ProtobufChassisVelocities mergeFrom(final JsonSource input) throws IOException {
    if (!input.beginObject()) {
      return this;
    }
    while (!input.isAtEnd()) {
      switch (input.readFieldHash()) {
        case 3778: {
          if (input.isAtField(FieldNames.vx)) {
            if (!input.trySkipNullValue()) {
              vx = input.readDouble();
              bitField0_ |= 0x00000001;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case 3779: {
          if (input.isAtField(FieldNames.vy)) {
            if (!input.trySkipNullValue()) {
              vy = input.readDouble();
              bitField0_ |= 0x00000002;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case 105858401: {
          if (input.isAtField(FieldNames.omega)) {
            if (!input.trySkipNullValue()) {
              omega = input.readDouble();
              bitField0_ |= 0x00000004;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        default: {
          input.skipUnknownField();
          break;
        }
      }
    }
    input.endObject();
    return this;
  }

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

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

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

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

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

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

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

  private enum ProtobufChassisVelocitiesFactory implements MessageFactory<ProtobufChassisVelocities> {
    INSTANCE;

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

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

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

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