// 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;

/**
 * Protobuf type {@code ProtobufRotation3d}
 */
@SuppressWarnings("hiding")
public final class ProtobufRotation3d extends ProtoMessage<ProtobufRotation3d> implements Cloneable {
  private static final long serialVersionUID = 0L;

  /**
   * <code>optional .wpi.proto.ProtobufQuaternion q = 1;</code>
   */
  private final ProtobufQuaternion q = ProtobufQuaternion.newInstance();

  private ProtobufRotation3d() {
  }

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

  /**
   * <code>optional .wpi.proto.ProtobufQuaternion q = 1;</code>
   * @return whether the q field is set
   */
  public boolean hasQ() {
    return (bitField0_ & 0x00000001) != 0;
  }

  /**
   * <code>optional .wpi.proto.ProtobufQuaternion q = 1;</code>
   * @return this
   */
  public ProtobufRotation3d clearQ() {
    bitField0_ &= ~0x00000001;
    q.clear();
    return this;
  }

  /**
   * <code>optional .wpi.proto.ProtobufQuaternion q = 1;</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 #getMutableQ()} if you want to modify it.
   *
   * @return internal storage object for reading
   */
  public ProtobufQuaternion getQ() {
    return q;
  }

  /**
   * <code>optional .wpi.proto.ProtobufQuaternion q = 1;</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 ProtobufQuaternion getMutableQ() {
    bitField0_ |= 0x00000001;
    return q;
  }

  /**
   * <code>optional .wpi.proto.ProtobufQuaternion q = 1;</code>
   * @param value the q to set
   * @return this
   */
  public ProtobufRotation3d setQ(final ProtobufQuaternion value) {
    bitField0_ |= 0x00000001;
    q.copyFrom(value);
    return this;
  }

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

  @Override
  public ProtobufRotation3d mergeFrom(final ProtobufRotation3d other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasQ()) {
      getMutableQ().mergeFrom(other.q);
    }
    return this;
  }

  @Override
  public ProtobufRotation3d clear() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    q.clear();
    return this;
  }

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

  @Override
  public boolean equals(Object o) {
    if (o == this) {
      return true;
    }
    if (!(o instanceof ProtobufRotation3d)) {
      return false;
    }
    ProtobufRotation3d other = (ProtobufRotation3d) o;
    return bitField0_ == other.bitField0_
      && (!hasQ() || q.equals(other.q));
  }

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

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

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

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

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

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

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

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

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

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

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

  private enum ProtobufRotation3dFactory implements MessageFactory<ProtobufRotation3d> {
    INSTANCE;

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

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