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

  /**
   * <code>optional double value = 1;</code>
   */
  private double value_;

  private ProtobufRotation2d() {
  }

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

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

  /**
   * <code>optional double value = 1;</code>
   * @return this
   */
  public ProtobufRotation2d clearValue() {
    bitField0_ &= ~0x00000001;
    value_ = 0D;
    return this;
  }

  /**
   * <code>optional double value = 1;</code>
   * @return the value_
   */
  public double getValue() {
    return value_;
  }

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

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

  @Override
  public ProtobufRotation2d mergeFrom(final ProtobufRotation2d other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasValue()) {
      setValue(other.value_);
    }
    return this;
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

  private enum ProtobufRotation2dFactory implements MessageFactory<ProtobufRotation2d> {
    INSTANCE;

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

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