/**
 * Autogenerated by Thrift Compiler (0.9.1)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package org.apache.curator.generated;

import org.apache.thrift.scheme.IScheme;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;

import org.apache.thrift.scheme.TupleScheme;
import org.apache.thrift.protocol.TTupleProtocol;
import org.apache.thrift.protocol.TProtocolException;
import org.apache.thrift.EncodingUtils;
import org.apache.thrift.TException;
import org.apache.thrift.async.AsyncMethodCallback;
import org.apache.thrift.server.AbstractNonblockingServer.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Set;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.Collections;
import java.util.BitSet;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DiscoveryInstance implements org.apache.thrift.TBase<DiscoveryInstance, DiscoveryInstance._Fields>, java.io.Serializable, Cloneable, Comparable<DiscoveryInstance> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("DiscoveryInstance");

  private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.STRING, (short)2);
  private static final org.apache.thrift.protocol.TField ADDRESS_FIELD_DESC = new org.apache.thrift.protocol.TField("address", org.apache.thrift.protocol.TType.STRING, (short)3);
  private static final org.apache.thrift.protocol.TField PORT_FIELD_DESC = new org.apache.thrift.protocol.TField("port", org.apache.thrift.protocol.TType.I32, (short)4);
  private static final org.apache.thrift.protocol.TField SSL_PORT_FIELD_DESC = new org.apache.thrift.protocol.TField("sslPort", org.apache.thrift.protocol.TType.I32, (short)5);
  private static final org.apache.thrift.protocol.TField PAYLOAD_FIELD_DESC = new org.apache.thrift.protocol.TField("payload", org.apache.thrift.protocol.TType.STRING, (short)6);
  private static final org.apache.thrift.protocol.TField REGISTRATION_TIME_UTC_FIELD_DESC = new org.apache.thrift.protocol.TField("registrationTimeUTC", org.apache.thrift.protocol.TType.I64, (short)7);
  private static final org.apache.thrift.protocol.TField SERVICE_TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("serviceType", org.apache.thrift.protocol.TType.I32, (short)8);
  private static final org.apache.thrift.protocol.TField URI_SPEC_FIELD_DESC = new org.apache.thrift.protocol.TField("uriSpec", org.apache.thrift.protocol.TType.STRING, (short)9);

  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
  static {
    schemes.put(StandardScheme.class, new DiscoveryInstanceStandardSchemeFactory());
    schemes.put(TupleScheme.class, new DiscoveryInstanceTupleSchemeFactory());
  }

  public String name; // required
  public String id; // required
  public String address; // required
  public int port; // required
  public int sslPort; // required
  public ByteBuffer payload; // required
  public long registrationTimeUTC; // required
  /**
   * 
   * @see DiscoveryInstanceType
   */
  public DiscoveryInstanceType serviceType; // required
  public String uriSpec; // required

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    NAME((short)1, "name"),
    ID((short)2, "id"),
    ADDRESS((short)3, "address"),
    PORT((short)4, "port"),
    SSL_PORT((short)5, "sslPort"),
    PAYLOAD((short)6, "payload"),
    REGISTRATION_TIME_UTC((short)7, "registrationTimeUTC"),
    /**
     * 
     * @see DiscoveryInstanceType
     */
    SERVICE_TYPE((short)8, "serviceType"),
    URI_SPEC((short)9, "uriSpec");

    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

    static {
      for (_Fields field : EnumSet.allOf(_Fields.class)) {
        byName.put(field.getFieldName(), field);
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 1: // NAME
          return NAME;
        case 2: // ID
          return ID;
        case 3: // ADDRESS
          return ADDRESS;
        case 4: // PORT
          return PORT;
        case 5: // SSL_PORT
          return SSL_PORT;
        case 6: // PAYLOAD
          return PAYLOAD;
        case 7: // REGISTRATION_TIME_UTC
          return REGISTRATION_TIME_UTC;
        case 8: // SERVICE_TYPE
          return SERVICE_TYPE;
        case 9: // URI_SPEC
          return URI_SPEC;
        default:
          return null;
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, throwing an exception
     * if it is not found.
     */
    public static _Fields findByThriftIdOrThrow(int fieldId) {
      _Fields fields = findByThriftId(fieldId);
      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    public static _Fields findByName(String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final String _fieldName;

    _Fields(short thriftId, String fieldName) {
      _thriftId = thriftId;
      _fieldName = fieldName;
    }

    public short getThriftFieldId() {
      return _thriftId;
    }

    public String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments
  private static final int __PORT_ISSET_ID = 0;
  private static final int __SSLPORT_ISSET_ID = 1;
  private static final int __REGISTRATIONTIMEUTC_ISSET_ID = 2;
  private byte __isset_bitfield = 0;
  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.NAME, new org.apache.thrift.meta_data.FieldMetaData("name", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.ID, new org.apache.thrift.meta_data.FieldMetaData("id", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.ADDRESS, new org.apache.thrift.meta_data.FieldMetaData("address", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.PORT, new org.apache.thrift.meta_data.FieldMetaData("port", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
    tmpMap.put(_Fields.SSL_PORT, new org.apache.thrift.meta_data.FieldMetaData("sslPort", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
    tmpMap.put(_Fields.PAYLOAD, new org.apache.thrift.meta_data.FieldMetaData("payload", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
    tmpMap.put(_Fields.REGISTRATION_TIME_UTC, new org.apache.thrift.meta_data.FieldMetaData("registrationTimeUTC", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
    tmpMap.put(_Fields.SERVICE_TYPE, new org.apache.thrift.meta_data.FieldMetaData("serviceType", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, DiscoveryInstanceType.class)));
    tmpMap.put(_Fields.URI_SPEC, new org.apache.thrift.meta_data.FieldMetaData("uriSpec", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(DiscoveryInstance.class, metaDataMap);
  }

  public DiscoveryInstance() {
  }

  public DiscoveryInstance(
    String name,
    String id,
    String address,
    int port,
    int sslPort,
    ByteBuffer payload,
    long registrationTimeUTC,
    DiscoveryInstanceType serviceType,
    String uriSpec)
  {
    this();
    this.name = name;
    this.id = id;
    this.address = address;
    this.port = port;
    setPortIsSet(true);
    this.sslPort = sslPort;
    setSslPortIsSet(true);
    this.payload = payload;
    this.registrationTimeUTC = registrationTimeUTC;
    setRegistrationTimeUTCIsSet(true);
    this.serviceType = serviceType;
    this.uriSpec = uriSpec;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public DiscoveryInstance(DiscoveryInstance other) {
    __isset_bitfield = other.__isset_bitfield;
    if (other.isSetName()) {
      this.name = other.name;
    }
    if (other.isSetId()) {
      this.id = other.id;
    }
    if (other.isSetAddress()) {
      this.address = other.address;
    }
    this.port = other.port;
    this.sslPort = other.sslPort;
    if (other.isSetPayload()) {
      this.payload = org.apache.thrift.TBaseHelper.copyBinary(other.payload);
;
    }
    this.registrationTimeUTC = other.registrationTimeUTC;
    if (other.isSetServiceType()) {
      this.serviceType = other.serviceType;
    }
    if (other.isSetUriSpec()) {
      this.uriSpec = other.uriSpec;
    }
  }

  public DiscoveryInstance deepCopy() {
    return new DiscoveryInstance(this);
  }

  @Override
  public void clear() {
    this.name = null;
    this.id = null;
    this.address = null;
    setPortIsSet(false);
    this.port = 0;
    setSslPortIsSet(false);
    this.sslPort = 0;
    this.payload = null;
    setRegistrationTimeUTCIsSet(false);
    this.registrationTimeUTC = 0;
    this.serviceType = null;
    this.uriSpec = null;
  }

  public String getName() {
    return this.name;
  }

  public DiscoveryInstance setName(String name) {
    this.name = name;
    return this;
  }

  public void unsetName() {
    this.name = null;
  }

  /** Returns true if field name is set (has been assigned a value) and false otherwise */
  public boolean isSetName() {
    return this.name != null;
  }

  public void setNameIsSet(boolean value) {
    if (!value) {
      this.name = null;
    }
  }

  public String getId() {
    return this.id;
  }

  public DiscoveryInstance setId(String id) {
    this.id = id;
    return this;
  }

  public void unsetId() {
    this.id = null;
  }

  /** Returns true if field id is set (has been assigned a value) and false otherwise */
  public boolean isSetId() {
    return this.id != null;
  }

  public void setIdIsSet(boolean value) {
    if (!value) {
      this.id = null;
    }
  }

  public String getAddress() {
    return this.address;
  }

  public DiscoveryInstance setAddress(String address) {
    this.address = address;
    return this;
  }

  public void unsetAddress() {
    this.address = null;
  }

  /** Returns true if field address is set (has been assigned a value) and false otherwise */
  public boolean isSetAddress() {
    return this.address != null;
  }

  public void setAddressIsSet(boolean value) {
    if (!value) {
      this.address = null;
    }
  }

  public int getPort() {
    return this.port;
  }

  public DiscoveryInstance setPort(int port) {
    this.port = port;
    setPortIsSet(true);
    return this;
  }

  public void unsetPort() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __PORT_ISSET_ID);
  }

  /** Returns true if field port is set (has been assigned a value) and false otherwise */
  public boolean isSetPort() {
    return EncodingUtils.testBit(__isset_bitfield, __PORT_ISSET_ID);
  }

  public void setPortIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __PORT_ISSET_ID, value);
  }

  public int getSslPort() {
    return this.sslPort;
  }

  public DiscoveryInstance setSslPort(int sslPort) {
    this.sslPort = sslPort;
    setSslPortIsSet(true);
    return this;
  }

  public void unsetSslPort() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __SSLPORT_ISSET_ID);
  }

  /** Returns true if field sslPort is set (has been assigned a value) and false otherwise */
  public boolean isSetSslPort() {
    return EncodingUtils.testBit(__isset_bitfield, __SSLPORT_ISSET_ID);
  }

  public void setSslPortIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __SSLPORT_ISSET_ID, value);
  }

  public byte[] getPayload() {
    setPayload(org.apache.thrift.TBaseHelper.rightSize(payload));
    return payload == null ? null : payload.array();
  }

  public ByteBuffer bufferForPayload() {
    return payload;
  }

  public DiscoveryInstance setPayload(byte[] payload) {
    setPayload(payload == null ? (ByteBuffer)null : ByteBuffer.wrap(payload));
    return this;
  }

  public DiscoveryInstance setPayload(ByteBuffer payload) {
    this.payload = payload;
    return this;
  }

  public void unsetPayload() {
    this.payload = null;
  }

  /** Returns true if field payload is set (has been assigned a value) and false otherwise */
  public boolean isSetPayload() {
    return this.payload != null;
  }

  public void setPayloadIsSet(boolean value) {
    if (!value) {
      this.payload = null;
    }
  }

  public long getRegistrationTimeUTC() {
    return this.registrationTimeUTC;
  }

  public DiscoveryInstance setRegistrationTimeUTC(long registrationTimeUTC) {
    this.registrationTimeUTC = registrationTimeUTC;
    setRegistrationTimeUTCIsSet(true);
    return this;
  }

  public void unsetRegistrationTimeUTC() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __REGISTRATIONTIMEUTC_ISSET_ID);
  }

  /** Returns true if field registrationTimeUTC is set (has been assigned a value) and false otherwise */
  public boolean isSetRegistrationTimeUTC() {
    return EncodingUtils.testBit(__isset_bitfield, __REGISTRATIONTIMEUTC_ISSET_ID);
  }

  public void setRegistrationTimeUTCIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __REGISTRATIONTIMEUTC_ISSET_ID, value);
  }

  /**
   * 
   * @see DiscoveryInstanceType
   */
  public DiscoveryInstanceType getServiceType() {
    return this.serviceType;
  }

  /**
   * 
   * @see DiscoveryInstanceType
   */
  public DiscoveryInstance setServiceType(DiscoveryInstanceType serviceType) {
    this.serviceType = serviceType;
    return this;
  }

  public void unsetServiceType() {
    this.serviceType = null;
  }

  /** Returns true if field serviceType is set (has been assigned a value) and false otherwise */
  public boolean isSetServiceType() {
    return this.serviceType != null;
  }

  public void setServiceTypeIsSet(boolean value) {
    if (!value) {
      this.serviceType = null;
    }
  }

  public String getUriSpec() {
    return this.uriSpec;
  }

  public DiscoveryInstance setUriSpec(String uriSpec) {
    this.uriSpec = uriSpec;
    return this;
  }

  public void unsetUriSpec() {
    this.uriSpec = null;
  }

  /** Returns true if field uriSpec is set (has been assigned a value) and false otherwise */
  public boolean isSetUriSpec() {
    return this.uriSpec != null;
  }

  public void setUriSpecIsSet(boolean value) {
    if (!value) {
      this.uriSpec = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case NAME:
      if (value == null) {
        unsetName();
      } else {
        setName((String)value);
      }
      break;

    case ID:
      if (value == null) {
        unsetId();
      } else {
        setId((String)value);
      }
      break;

    case ADDRESS:
      if (value == null) {
        unsetAddress();
      } else {
        setAddress((String)value);
      }
      break;

    case PORT:
      if (value == null) {
        unsetPort();
      } else {
        setPort((Integer)value);
      }
      break;

    case SSL_PORT:
      if (value == null) {
        unsetSslPort();
      } else {
        setSslPort((Integer)value);
      }
      break;

    case PAYLOAD:
      if (value == null) {
        unsetPayload();
      } else {
        setPayload((ByteBuffer)value);
      }
      break;

    case REGISTRATION_TIME_UTC:
      if (value == null) {
        unsetRegistrationTimeUTC();
      } else {
        setRegistrationTimeUTC((Long)value);
      }
      break;

    case SERVICE_TYPE:
      if (value == null) {
        unsetServiceType();
      } else {
        setServiceType((DiscoveryInstanceType)value);
      }
      break;

    case URI_SPEC:
      if (value == null) {
        unsetUriSpec();
      } else {
        setUriSpec((String)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case NAME:
      return getName();

    case ID:
      return getId();

    case ADDRESS:
      return getAddress();

    case PORT:
      return Integer.valueOf(getPort());

    case SSL_PORT:
      return Integer.valueOf(getSslPort());

    case PAYLOAD:
      return getPayload();

    case REGISTRATION_TIME_UTC:
      return Long.valueOf(getRegistrationTimeUTC());

    case SERVICE_TYPE:
      return getServiceType();

    case URI_SPEC:
      return getUriSpec();

    }
    throw new IllegalStateException();
  }

  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
  public boolean isSet(_Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
    case NAME:
      return isSetName();
    case ID:
      return isSetId();
    case ADDRESS:
      return isSetAddress();
    case PORT:
      return isSetPort();
    case SSL_PORT:
      return isSetSslPort();
    case PAYLOAD:
      return isSetPayload();
    case REGISTRATION_TIME_UTC:
      return isSetRegistrationTimeUTC();
    case SERVICE_TYPE:
      return isSetServiceType();
    case URI_SPEC:
      return isSetUriSpec();
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null)
      return false;
    if (that instanceof DiscoveryInstance)
      return this.equals((DiscoveryInstance)that);
    return false;
  }

  public boolean equals(DiscoveryInstance that) {
    if (that == null)
      return false;

    boolean this_present_name = true && this.isSetName();
    boolean that_present_name = true && that.isSetName();
    if (this_present_name || that_present_name) {
      if (!(this_present_name && that_present_name))
        return false;
      if (!this.name.equals(that.name))
        return false;
    }

    boolean this_present_id = true && this.isSetId();
    boolean that_present_id = true && that.isSetId();
    if (this_present_id || that_present_id) {
      if (!(this_present_id && that_present_id))
        return false;
      if (!this.id.equals(that.id))
        return false;
    }

    boolean this_present_address = true && this.isSetAddress();
    boolean that_present_address = true && that.isSetAddress();
    if (this_present_address || that_present_address) {
      if (!(this_present_address && that_present_address))
        return false;
      if (!this.address.equals(that.address))
        return false;
    }

    boolean this_present_port = true;
    boolean that_present_port = true;
    if (this_present_port || that_present_port) {
      if (!(this_present_port && that_present_port))
        return false;
      if (this.port != that.port)
        return false;
    }

    boolean this_present_sslPort = true;
    boolean that_present_sslPort = true;
    if (this_present_sslPort || that_present_sslPort) {
      if (!(this_present_sslPort && that_present_sslPort))
        return false;
      if (this.sslPort != that.sslPort)
        return false;
    }

    boolean this_present_payload = true && this.isSetPayload();
    boolean that_present_payload = true && that.isSetPayload();
    if (this_present_payload || that_present_payload) {
      if (!(this_present_payload && that_present_payload))
        return false;
      if (!this.payload.equals(that.payload))
        return false;
    }

    boolean this_present_registrationTimeUTC = true;
    boolean that_present_registrationTimeUTC = true;
    if (this_present_registrationTimeUTC || that_present_registrationTimeUTC) {
      if (!(this_present_registrationTimeUTC && that_present_registrationTimeUTC))
        return false;
      if (this.registrationTimeUTC != that.registrationTimeUTC)
        return false;
    }

    boolean this_present_serviceType = true && this.isSetServiceType();
    boolean that_present_serviceType = true && that.isSetServiceType();
    if (this_present_serviceType || that_present_serviceType) {
      if (!(this_present_serviceType && that_present_serviceType))
        return false;
      if (!this.serviceType.equals(that.serviceType))
        return false;
    }

    boolean this_present_uriSpec = true && this.isSetUriSpec();
    boolean that_present_uriSpec = true && that.isSetUriSpec();
    if (this_present_uriSpec || that_present_uriSpec) {
      if (!(this_present_uriSpec && that_present_uriSpec))
        return false;
      if (!this.uriSpec.equals(that.uriSpec))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    return 0;
  }

  @Override
  public int compareTo(DiscoveryInstance other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetName()).compareTo(other.isSetName());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetName()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.name, other.name);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetId()).compareTo(other.isSetId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetId()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.id, other.id);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetAddress()).compareTo(other.isSetAddress());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetAddress()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.address, other.address);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetPort()).compareTo(other.isSetPort());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetPort()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.port, other.port);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetSslPort()).compareTo(other.isSetSslPort());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetSslPort()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.sslPort, other.sslPort);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetPayload()).compareTo(other.isSetPayload());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetPayload()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.payload, other.payload);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetRegistrationTimeUTC()).compareTo(other.isSetRegistrationTimeUTC());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetRegistrationTimeUTC()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.registrationTimeUTC, other.registrationTimeUTC);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetServiceType()).compareTo(other.isSetServiceType());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetServiceType()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.serviceType, other.serviceType);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetUriSpec()).compareTo(other.isSetUriSpec());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetUriSpec()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.uriSpec, other.uriSpec);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("DiscoveryInstance(");
    boolean first = true;

    sb.append("name:");
    if (this.name == null) {
      sb.append("null");
    } else {
      sb.append(this.name);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("id:");
    if (this.id == null) {
      sb.append("null");
    } else {
      sb.append(this.id);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("address:");
    if (this.address == null) {
      sb.append("null");
    } else {
      sb.append(this.address);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("port:");
    sb.append(this.port);
    first = false;
    if (!first) sb.append(", ");
    sb.append("sslPort:");
    sb.append(this.sslPort);
    first = false;
    if (!first) sb.append(", ");
    sb.append("payload:");
    if (this.payload == null) {
      sb.append("null");
    } else {
      org.apache.thrift.TBaseHelper.toString(this.payload, sb);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("registrationTimeUTC:");
    sb.append(this.registrationTimeUTC);
    first = false;
    if (!first) sb.append(", ");
    sb.append("serviceType:");
    if (this.serviceType == null) {
      sb.append("null");
    } else {
      sb.append(this.serviceType);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("uriSpec:");
    if (this.uriSpec == null) {
      sb.append("null");
    } else {
      sb.append(this.uriSpec);
    }
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
  }

  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    try {
      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
    try {
      // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
      __isset_bitfield = 0;
      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private static class DiscoveryInstanceStandardSchemeFactory implements SchemeFactory {
    public DiscoveryInstanceStandardScheme getScheme() {
      return new DiscoveryInstanceStandardScheme();
    }
  }

  private static class DiscoveryInstanceStandardScheme extends StandardScheme<DiscoveryInstance> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, DiscoveryInstance struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true)
      {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
          break;
        }
        switch (schemeField.id) {
          case 1: // NAME
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.name = iprot.readString();
              struct.setNameIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // ID
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.id = iprot.readString();
              struct.setIdIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // ADDRESS
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.address = iprot.readString();
              struct.setAddressIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 4: // PORT
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.port = iprot.readI32();
              struct.setPortIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 5: // SSL_PORT
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.sslPort = iprot.readI32();
              struct.setSslPortIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 6: // PAYLOAD
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.payload = iprot.readBinary();
              struct.setPayloadIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 7: // REGISTRATION_TIME_UTC
            if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
              struct.registrationTimeUTC = iprot.readI64();
              struct.setRegistrationTimeUTCIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 8: // SERVICE_TYPE
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.serviceType = DiscoveryInstanceType.findByValue(iprot.readI32());
              struct.setServiceTypeIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 9: // URI_SPEC
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.uriSpec = iprot.readString();
              struct.setUriSpecIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot, DiscoveryInstance struct) throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.name != null) {
        oprot.writeFieldBegin(NAME_FIELD_DESC);
        oprot.writeString(struct.name);
        oprot.writeFieldEnd();
      }
      if (struct.id != null) {
        oprot.writeFieldBegin(ID_FIELD_DESC);
        oprot.writeString(struct.id);
        oprot.writeFieldEnd();
      }
      if (struct.address != null) {
        oprot.writeFieldBegin(ADDRESS_FIELD_DESC);
        oprot.writeString(struct.address);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldBegin(PORT_FIELD_DESC);
      oprot.writeI32(struct.port);
      oprot.writeFieldEnd();
      oprot.writeFieldBegin(SSL_PORT_FIELD_DESC);
      oprot.writeI32(struct.sslPort);
      oprot.writeFieldEnd();
      if (struct.payload != null) {
        oprot.writeFieldBegin(PAYLOAD_FIELD_DESC);
        oprot.writeBinary(struct.payload);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldBegin(REGISTRATION_TIME_UTC_FIELD_DESC);
      oprot.writeI64(struct.registrationTimeUTC);
      oprot.writeFieldEnd();
      if (struct.serviceType != null) {
        oprot.writeFieldBegin(SERVICE_TYPE_FIELD_DESC);
        oprot.writeI32(struct.serviceType.getValue());
        oprot.writeFieldEnd();
      }
      if (struct.uriSpec != null) {
        oprot.writeFieldBegin(URI_SPEC_FIELD_DESC);
        oprot.writeString(struct.uriSpec);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class DiscoveryInstanceTupleSchemeFactory implements SchemeFactory {
    public DiscoveryInstanceTupleScheme getScheme() {
      return new DiscoveryInstanceTupleScheme();
    }
  }

  private static class DiscoveryInstanceTupleScheme extends TupleScheme<DiscoveryInstance> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, DiscoveryInstance struct) throws org.apache.thrift.TException {
      TTupleProtocol oprot = (TTupleProtocol) prot;
      BitSet optionals = new BitSet();
      if (struct.isSetName()) {
        optionals.set(0);
      }
      if (struct.isSetId()) {
        optionals.set(1);
      }
      if (struct.isSetAddress()) {
        optionals.set(2);
      }
      if (struct.isSetPort()) {
        optionals.set(3);
      }
      if (struct.isSetSslPort()) {
        optionals.set(4);
      }
      if (struct.isSetPayload()) {
        optionals.set(5);
      }
      if (struct.isSetRegistrationTimeUTC()) {
        optionals.set(6);
      }
      if (struct.isSetServiceType()) {
        optionals.set(7);
      }
      if (struct.isSetUriSpec()) {
        optionals.set(8);
      }
      oprot.writeBitSet(optionals, 9);
      if (struct.isSetName()) {
        oprot.writeString(struct.name);
      }
      if (struct.isSetId()) {
        oprot.writeString(struct.id);
      }
      if (struct.isSetAddress()) {
        oprot.writeString(struct.address);
      }
      if (struct.isSetPort()) {
        oprot.writeI32(struct.port);
      }
      if (struct.isSetSslPort()) {
        oprot.writeI32(struct.sslPort);
      }
      if (struct.isSetPayload()) {
        oprot.writeBinary(struct.payload);
      }
      if (struct.isSetRegistrationTimeUTC()) {
        oprot.writeI64(struct.registrationTimeUTC);
      }
      if (struct.isSetServiceType()) {
        oprot.writeI32(struct.serviceType.getValue());
      }
      if (struct.isSetUriSpec()) {
        oprot.writeString(struct.uriSpec);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, DiscoveryInstance struct) throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(9);
      if (incoming.get(0)) {
        struct.name = iprot.readString();
        struct.setNameIsSet(true);
      }
      if (incoming.get(1)) {
        struct.id = iprot.readString();
        struct.setIdIsSet(true);
      }
      if (incoming.get(2)) {
        struct.address = iprot.readString();
        struct.setAddressIsSet(true);
      }
      if (incoming.get(3)) {
        struct.port = iprot.readI32();
        struct.setPortIsSet(true);
      }
      if (incoming.get(4)) {
        struct.sslPort = iprot.readI32();
        struct.setSslPortIsSet(true);
      }
      if (incoming.get(5)) {
        struct.payload = iprot.readBinary();
        struct.setPayloadIsSet(true);
      }
      if (incoming.get(6)) {
        struct.registrationTimeUTC = iprot.readI64();
        struct.setRegistrationTimeUTCIsSet(true);
      }
      if (incoming.get(7)) {
        struct.serviceType = DiscoveryInstanceType.findByValue(iprot.readI32());
        struct.setServiceTypeIsSet(true);
      }
      if (incoming.get(8)) {
        struct.uriSpec = iprot.readString();
        struct.setUriSpecIsSet(true);
      }
    }
  }

}

