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

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

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

  private ProtobufDifferentialDriveWheelVoltages() {
  }

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

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

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

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

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

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

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

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

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

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

  @Override
  public ProtobufDifferentialDriveWheelVoltages mergeFrom(
      final ProtobufDifferentialDriveWheelVoltages other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasLeft()) {
      setLeft(other.left);
    }
    if (other.hasRight()) {
      setRight(other.right);
    }
    return this;
  }

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

  @Override
  public ProtobufDifferentialDriveWheelVoltages 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 ProtobufDifferentialDriveWheelVoltages)) {
      return false;
    }
    ProtobufDifferentialDriveWheelVoltages other = (ProtobufDifferentialDriveWheelVoltages) o;
    return bitField0_ == other.bitField0_
      && (!hasLeft() || ProtoUtil.isEqual(left, other.left))
      && (!hasRight() || ProtoUtil.isEqual(right, other.right));
  }

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

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

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

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

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

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

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

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

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

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

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

  private enum ProtobufDifferentialDriveWheelVoltagesFactory implements MessageFactory<ProtobufDifferentialDriveWheelVoltages> {
    INSTANCE;

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

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

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