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

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

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

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

  private ProtobufTwist2d() {
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

  @Override
  public ProtobufTwist2d copyFrom(final ProtobufTwist2d other) {
    cachedSize = other.cachedSize;
    if ((bitField0_ | other.bitField0_) != 0) {
      bitField0_ = other.bitField0_;
      dx = other.dx;
      dy = other.dy;
      dtheta = other.dtheta;
    }
    return this;
  }

  @Override
  public ProtobufTwist2d mergeFrom(final ProtobufTwist2d other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasDx()) {
      setDx(other.dx);
    }
    if (other.hasDy()) {
      setDy(other.dy);
    }
    if (other.hasDtheta()) {
      setDtheta(other.dtheta);
    }
    return this;
  }

  @Override
  public ProtobufTwist2d clear() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    dx = 0D;
    dy = 0D;
    dtheta = 0D;
    return this;
  }

  @Override
  public ProtobufTwist2d 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 ProtobufTwist2d)) {
      return false;
    }
    ProtobufTwist2d other = (ProtobufTwist2d) o;
    return bitField0_ == other.bitField0_
      && (!hasDx() || ProtoUtil.isEqual(dx, other.dx))
      && (!hasDy() || ProtoUtil.isEqual(dy, other.dy))
      && (!hasDtheta() || ProtoUtil.isEqual(dtheta, other.dtheta));
  }

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

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

  @Override
  public ProtobufTwist2d mergeFrom(final JsonSource input) throws IOException {
    if (!input.beginObject()) {
      return this;
    }
    while (!input.isAtEnd()) {
      switch (input.readFieldHash()) {
        case 3220: {
          if (input.isAtField(FieldNames.dx)) {
            if (!input.trySkipNullValue()) {
              dx = input.readDouble();
              bitField0_ |= 0x00000001;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case 3221: {
          if (input.isAtField(FieldNames.dy)) {
            if (!input.trySkipNullValue()) {
              dy = input.readDouble();
              bitField0_ |= 0x00000002;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case -1321724742: {
          if (input.isAtField(FieldNames.dtheta)) {
            if (!input.trySkipNullValue()) {
              dtheta = input.readDouble();
              bitField0_ |= 0x00000004;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        default: {
          input.skipUnknownField();
          break;
        }
      }
    }
    input.endObject();
    return this;
  }

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

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

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

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

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

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

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

  private enum ProtobufTwist2dFactory implements MessageFactory<ProtobufTwist2d> {
    INSTANCE;

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

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

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

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