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

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

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

  private ProtobufPose3d() {
  }

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

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

  /**
   * <code>optional .wpi.proto.ProtobufTranslation3d translation = 1;</code>
   * @return this
   */
  public ProtobufPose3d clearTranslation() {
    bitField0_ &= ~0x00000001;
    translation.clear();
    return this;
  }

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

  /**
   * <code>optional .wpi.proto.ProtobufTranslation3d translation = 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 ProtobufTranslation3d getMutableTranslation() {
    bitField0_ |= 0x00000001;
    return translation;
  }

  /**
   * <code>optional .wpi.proto.ProtobufTranslation3d translation = 1;</code>
   * @param value the translation to set
   * @return this
   */
  public ProtobufPose3d setTranslation(final ProtobufTranslation3d value) {
    bitField0_ |= 0x00000001;
    translation.copyFrom(value);
    return this;
  }

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

  /**
   * <code>optional .wpi.proto.ProtobufRotation3d rotation = 2;</code>
   * @return this
   */
  public ProtobufPose3d clearRotation() {
    bitField0_ &= ~0x00000002;
    rotation.clear();
    return this;
  }

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

  /**
   * <code>optional .wpi.proto.ProtobufRotation3d rotation = 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 ProtobufRotation3d getMutableRotation() {
    bitField0_ |= 0x00000002;
    return rotation;
  }

  /**
   * <code>optional .wpi.proto.ProtobufRotation3d rotation = 2;</code>
   * @param value the rotation to set
   * @return this
   */
  public ProtobufPose3d setRotation(final ProtobufRotation3d value) {
    bitField0_ |= 0x00000002;
    rotation.copyFrom(value);
    return this;
  }

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

  @Override
  public ProtobufPose3d mergeFrom(final ProtobufPose3d other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasTranslation()) {
      getMutableTranslation().mergeFrom(other.translation);
    }
    if (other.hasRotation()) {
      getMutableRotation().mergeFrom(other.rotation);
    }
    return this;
  }

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

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

  @Override
  public boolean equals(Object o) {
    if (o == this) {
      return true;
    }
    if (!(o instanceof ProtobufPose3d)) {
      return false;
    }
    ProtobufPose3d other = (ProtobufPose3d) o;
    return bitField0_ == other.bitField0_
      && (!hasTranslation() || translation.equals(other.translation))
      && (!hasRotation() || rotation.equals(other.rotation));
  }

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

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

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

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

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

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

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

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

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

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

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

  private enum ProtobufPose3dFactory implements MessageFactory<ProtobufPose3d> {
    INSTANCE;

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

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

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