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

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

  /**
   * <code>optional .wpi.proto.ProtobufRotation2d angle = 2;</code>
   */
  private final ProtobufRotation2d angle = ProtobufRotation2d.newInstance();

  private ProtobufSwerveModuleVelocity() {
  }

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

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

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

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

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

  /**
   * <code>optional .wpi.proto.ProtobufRotation2d angle = 2;</code>
   * @return whether the angle field is set
   */
  public boolean hasAngle() {
    return (bitField0_ & 0x00000002) != 0;
  }

  /**
   * <code>optional .wpi.proto.ProtobufRotation2d angle = 2;</code>
   * @return this
   */
  public ProtobufSwerveModuleVelocity clearAngle() {
    bitField0_ &= ~0x00000002;
    angle.clear();
    return this;
  }

  /**
   * <code>optional .wpi.proto.ProtobufRotation2d angle = 2;</code>
   *
   * This method returns the internal storage object without modifying any has state.
   * The returned object should not be modified and be treated as read-only.
   *
   * Use {@link #getMutableAngle()} if you want to modify it.
   *
   * @return internal storage object for reading
   */
  public ProtobufRotation2d getAngle() {
    return angle;
  }

  /**
   * <code>optional .wpi.proto.ProtobufRotation2d angle = 2;</code>
   *
   * This method returns the internal storage object and sets the corresponding
   * has state. The returned object will become part of this message and its
   * contents may be modified as long as the has state is not cleared.
   *
   * @return internal storage object for modifications
   */
  public ProtobufRotation2d getMutableAngle() {
    bitField0_ |= 0x00000002;
    return angle;
  }

  /**
   * <code>optional .wpi.proto.ProtobufRotation2d angle = 2;</code>
   * @param value the angle to set
   * @return this
   */
  public ProtobufSwerveModuleVelocity setAngle(final ProtobufRotation2d value) {
    bitField0_ |= 0x00000002;
    angle.copyFrom(value);
    return this;
  }

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

  @Override
  public ProtobufSwerveModuleVelocity mergeFrom(final ProtobufSwerveModuleVelocity other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasVelocity()) {
      setVelocity(other.velocity);
    }
    if (other.hasAngle()) {
      getMutableAngle().mergeFrom(other.angle);
    }
    return this;
  }

  @Override
  public ProtobufSwerveModuleVelocity clear() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    velocity = 0D;
    angle.clear();
    return this;
  }

  @Override
  public ProtobufSwerveModuleVelocity clearQuick() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    angle.clearQuick();
    return this;
  }

  @Override
  public boolean equals(Object o) {
    if (o == this) {
      return true;
    }
    if (!(o instanceof ProtobufSwerveModuleVelocity)) {
      return false;
    }
    ProtobufSwerveModuleVelocity other = (ProtobufSwerveModuleVelocity) o;
    return bitField0_ == other.bitField0_
      && (!hasVelocity() || ProtoUtil.isEqual(velocity, other.velocity))
      && (!hasAngle() || angle.equals(other.angle));
  }

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

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

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

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

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

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

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

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

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

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

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

  private enum ProtobufSwerveModuleVelocityFactory implements MessageFactory<ProtobufSwerveModuleVelocity> {
    INSTANCE;

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

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

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