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

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

  private ProtobufDifferentialDriveKinematics() {
  }

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

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

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

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

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

  @Override
  public ProtobufDifferentialDriveKinematics copyFrom(
      final ProtobufDifferentialDriveKinematics other) {
    cachedSize = other.cachedSize;
    if ((bitField0_ | other.bitField0_) != 0) {
      bitField0_ = other.bitField0_;
      trackwidth = other.trackwidth;
    }
    return this;
  }

  @Override
  public ProtobufDifferentialDriveKinematics mergeFrom(
      final ProtobufDifferentialDriveKinematics other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasTrackwidth()) {
      setTrackwidth(other.trackwidth);
    }
    return this;
  }

  @Override
  public ProtobufDifferentialDriveKinematics clear() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    trackwidth = 0D;
    return this;
  }

  @Override
  public ProtobufDifferentialDriveKinematics 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 ProtobufDifferentialDriveKinematics)) {
      return false;
    }
    ProtobufDifferentialDriveKinematics other = (ProtobufDifferentialDriveKinematics) o;
    return bitField0_ == other.bitField0_
      && (!hasTrackwidth() || ProtoUtil.isEqual(trackwidth, other.trackwidth));
  }

  @Override
  public void writeTo(final ProtoSink output) throws IOException {
    if ((bitField0_ & 0x00000001) != 0) {
      output.writeRawByte((byte) 9);
      output.writeDoubleNoTag(trackwidth);
    }
  }

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

  @Override
  @SuppressWarnings("fallthrough")
  public ProtobufDifferentialDriveKinematics mergeFrom(final ProtoSource input) throws IOException {
    // Enabled Fall-Through Optimization (QuickBuffers)
    int tag = input.readTag();
    while (true) {
      switch (tag) {
        case 9: {
          // trackwidth
          trackwidth = input.readDouble();
          bitField0_ |= 0x00000001;
          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.trackwidth, trackwidth);
    }
    output.endObject();
  }

  @Override
  public ProtobufDifferentialDriveKinematics mergeFrom(final JsonSource input) throws IOException {
    if (!input.beginObject()) {
      return this;
    }
    while (!input.isAtEnd()) {
      switch (input.readFieldHash()) {
        case 1181766491: {
          if (input.isAtField(FieldNames.trackwidth)) {
            if (!input.trySkipNullValue()) {
              trackwidth = input.readDouble();
              bitField0_ |= 0x00000001;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        default: {
          input.skipUnknownField();
          break;
        }
      }
    }
    input.endObject();
    return this;
  }

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

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

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

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

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

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

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

  private enum ProtobufDifferentialDriveKinematicsFactory implements MessageFactory<ProtobufDifferentialDriveKinematics> {
    INSTANCE;

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

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