/**
 * Autogenerated by Thrift Compiler (0.10.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package com.worldpay.innovation.wpwithin.rpc;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.10.0)", date = "2017-01-24")
public class WPWithinCallback {

  /**
   * WorldpayWithin Callback Service - RPC clients implement this service to enable callbacks from WorldpayWithin Service
   */
  public interface Iface {

    public void beginServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsToSupply) throws com.worldpay.innovation.wpwithin.rpc.types.Error, org.apache.thrift.TException;

    public void endServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsReceived) throws com.worldpay.innovation.wpwithin.rpc.types.Error, org.apache.thrift.TException;

  }

  public interface AsyncIface {

    public void beginServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsToSupply, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler) throws org.apache.thrift.TException;

    public void endServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsReceived, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler) throws org.apache.thrift.TException;

  }

  public static class Client extends org.apache.thrift.TServiceClient implements Iface {
    public static class Factory implements org.apache.thrift.TServiceClientFactory<Client> {
      public Factory() {}
      public Client getClient(org.apache.thrift.protocol.TProtocol prot) {
        return new Client(prot);
      }
      public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
        return new Client(iprot, oprot);
      }
    }

    public Client(org.apache.thrift.protocol.TProtocol prot)
    {
      super(prot, prot);
    }

    public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
      super(iprot, oprot);
    }

    public void beginServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsToSupply) throws com.worldpay.innovation.wpwithin.rpc.types.Error, org.apache.thrift.TException
    {
      send_beginServiceDelivery(serviceID, serviceDeliveryToken, unitsToSupply);
      recv_beginServiceDelivery();
    }

    public void send_beginServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsToSupply) throws org.apache.thrift.TException
    {
      beginServiceDelivery_args args = new beginServiceDelivery_args();
      args.setServiceID(serviceID);
      args.setServiceDeliveryToken(serviceDeliveryToken);
      args.setUnitsToSupply(unitsToSupply);
      sendBase("beginServiceDelivery", args);
    }

    public void recv_beginServiceDelivery() throws com.worldpay.innovation.wpwithin.rpc.types.Error, org.apache.thrift.TException
    {
      beginServiceDelivery_result result = new beginServiceDelivery_result();
      receiveBase(result, "beginServiceDelivery");
      if (result.err != null) {
        throw result.err;
      }
      return;
    }

    public void endServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsReceived) throws com.worldpay.innovation.wpwithin.rpc.types.Error, org.apache.thrift.TException
    {
      send_endServiceDelivery(serviceID, serviceDeliveryToken, unitsReceived);
      recv_endServiceDelivery();
    }

    public void send_endServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsReceived) throws org.apache.thrift.TException
    {
      endServiceDelivery_args args = new endServiceDelivery_args();
      args.setServiceID(serviceID);
      args.setServiceDeliveryToken(serviceDeliveryToken);
      args.setUnitsReceived(unitsReceived);
      sendBase("endServiceDelivery", args);
    }

    public void recv_endServiceDelivery() throws com.worldpay.innovation.wpwithin.rpc.types.Error, org.apache.thrift.TException
    {
      endServiceDelivery_result result = new endServiceDelivery_result();
      receiveBase(result, "endServiceDelivery");
      if (result.err != null) {
        throw result.err;
      }
      return;
    }

  }
  public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface {
    public static class Factory implements org.apache.thrift.async.TAsyncClientFactory<AsyncClient> {
      private org.apache.thrift.async.TAsyncClientManager clientManager;
      private org.apache.thrift.protocol.TProtocolFactory protocolFactory;
      public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) {
        this.clientManager = clientManager;
        this.protocolFactory = protocolFactory;
      }
      public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) {
        return new AsyncClient(protocolFactory, clientManager, transport);
      }
    }

    public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) {
      super(protocolFactory, clientManager, transport);
    }

    public void beginServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsToSupply, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler) throws org.apache.thrift.TException {
      checkReady();
      beginServiceDelivery_call method_call = new beginServiceDelivery_call(serviceID, serviceDeliveryToken, unitsToSupply, resultHandler, this, ___protocolFactory, ___transport);
      this.___currentMethod = method_call;
      ___manager.call(method_call);
    }

    public static class beginServiceDelivery_call extends org.apache.thrift.async.TAsyncMethodCall<Void> {
      private int serviceID;
      private com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken;
      private int unitsToSupply;
      public beginServiceDelivery_call(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsToSupply, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
        super(client, protocolFactory, transport, resultHandler, false);
        this.serviceID = serviceID;
        this.serviceDeliveryToken = serviceDeliveryToken;
        this.unitsToSupply = unitsToSupply;
      }

      public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
        prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("beginServiceDelivery", org.apache.thrift.protocol.TMessageType.CALL, 0));
        beginServiceDelivery_args args = new beginServiceDelivery_args();
        args.setServiceID(serviceID);
        args.setServiceDeliveryToken(serviceDeliveryToken);
        args.setUnitsToSupply(unitsToSupply);
        args.write(prot);
        prot.writeMessageEnd();
      }

      public Void getResult() throws com.worldpay.innovation.wpwithin.rpc.types.Error, org.apache.thrift.TException {
        if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
          throw new java.lang.IllegalStateException("Method call not finished!");
        }
        org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
        org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
        return null;
      }
    }

    public void endServiceDelivery(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsReceived, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler) throws org.apache.thrift.TException {
      checkReady();
      endServiceDelivery_call method_call = new endServiceDelivery_call(serviceID, serviceDeliveryToken, unitsReceived, resultHandler, this, ___protocolFactory, ___transport);
      this.___currentMethod = method_call;
      ___manager.call(method_call);
    }

    public static class endServiceDelivery_call extends org.apache.thrift.async.TAsyncMethodCall<Void> {
      private int serviceID;
      private com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken;
      private int unitsReceived;
      public endServiceDelivery_call(int serviceID, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken, int unitsReceived, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
        super(client, protocolFactory, transport, resultHandler, false);
        this.serviceID = serviceID;
        this.serviceDeliveryToken = serviceDeliveryToken;
        this.unitsReceived = unitsReceived;
      }

      public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
        prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("endServiceDelivery", org.apache.thrift.protocol.TMessageType.CALL, 0));
        endServiceDelivery_args args = new endServiceDelivery_args();
        args.setServiceID(serviceID);
        args.setServiceDeliveryToken(serviceDeliveryToken);
        args.setUnitsReceived(unitsReceived);
        args.write(prot);
        prot.writeMessageEnd();
      }

      public Void getResult() throws com.worldpay.innovation.wpwithin.rpc.types.Error, org.apache.thrift.TException {
        if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
          throw new java.lang.IllegalStateException("Method call not finished!");
        }
        org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
        org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
        return null;
      }
    }

  }

  public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> implements org.apache.thrift.TProcessor {
    private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(Processor.class.getName());
    public Processor(I iface) {
      super(iface, getProcessMap(new java.util.HashMap<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>>()));
    }

    protected Processor(I iface, java.util.Map<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> processMap) {
      super(iface, getProcessMap(processMap));
    }

    private static <I extends Iface> java.util.Map<java.lang.String,  org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> getProcessMap(java.util.Map<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends  org.apache.thrift.TBase>> processMap) {
      processMap.put("beginServiceDelivery", new beginServiceDelivery());
      processMap.put("endServiceDelivery", new endServiceDelivery());
      return processMap;
    }

    public static class beginServiceDelivery<I extends Iface> extends org.apache.thrift.ProcessFunction<I, beginServiceDelivery_args> {
      public beginServiceDelivery() {
        super("beginServiceDelivery");
      }

      public beginServiceDelivery_args getEmptyArgsInstance() {
        return new beginServiceDelivery_args();
      }

      protected boolean isOneway() {
        return false;
      }

      public beginServiceDelivery_result getResult(I iface, beginServiceDelivery_args args) throws org.apache.thrift.TException {
        beginServiceDelivery_result result = new beginServiceDelivery_result();
        try {
          iface.beginServiceDelivery(args.serviceID, args.serviceDeliveryToken, args.unitsToSupply);
        } catch (com.worldpay.innovation.wpwithin.rpc.types.Error err) {
          result.err = err;
        }
        return result;
      }
    }

    public static class endServiceDelivery<I extends Iface> extends org.apache.thrift.ProcessFunction<I, endServiceDelivery_args> {
      public endServiceDelivery() {
        super("endServiceDelivery");
      }

      public endServiceDelivery_args getEmptyArgsInstance() {
        return new endServiceDelivery_args();
      }

      protected boolean isOneway() {
        return false;
      }

      public endServiceDelivery_result getResult(I iface, endServiceDelivery_args args) throws org.apache.thrift.TException {
        endServiceDelivery_result result = new endServiceDelivery_result();
        try {
          iface.endServiceDelivery(args.serviceID, args.serviceDeliveryToken, args.unitsReceived);
        } catch (com.worldpay.innovation.wpwithin.rpc.types.Error err) {
          result.err = err;
        }
        return result;
      }
    }

  }

  public static class AsyncProcessor<I extends AsyncIface> extends org.apache.thrift.TBaseAsyncProcessor<I> {
    private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(AsyncProcessor.class.getName());
    public AsyncProcessor(I iface) {
      super(iface, getProcessMap(new java.util.HashMap<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>>()));
    }

    protected AsyncProcessor(I iface, java.util.Map<java.lang.String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase, ?>> processMap) {
      super(iface, getProcessMap(processMap));
    }

    private static <I extends AsyncIface> java.util.Map<java.lang.String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase,?>> getProcessMap(java.util.Map<java.lang.String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase, ?>> processMap) {
      processMap.put("beginServiceDelivery", new beginServiceDelivery());
      processMap.put("endServiceDelivery", new endServiceDelivery());
      return processMap;
    }

    public static class beginServiceDelivery<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, beginServiceDelivery_args, Void> {
      public beginServiceDelivery() {
        super("beginServiceDelivery");
      }

      public beginServiceDelivery_args getEmptyArgsInstance() {
        return new beginServiceDelivery_args();
      }

      public org.apache.thrift.async.AsyncMethodCallback<Void> getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) {
        final org.apache.thrift.AsyncProcessFunction fcall = this;
        return new org.apache.thrift.async.AsyncMethodCallback<Void>() { 
          public void onComplete(Void o) {
            beginServiceDelivery_result result = new beginServiceDelivery_result();
            try {
              fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid);
            } catch (org.apache.thrift.transport.TTransportException e) {
              _LOGGER.error("TTransportException writing to internal frame buffer", e);
              fb.close();
            } catch (java.lang.Exception e) {
              _LOGGER.error("Exception writing to internal frame buffer", e);
              onError(e);
            }
          }
          public void onError(java.lang.Exception e) {
            byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
            org.apache.thrift.TSerializable msg;
            beginServiceDelivery_result result = new beginServiceDelivery_result();
            if (e instanceof com.worldpay.innovation.wpwithin.rpc.types.Error) {
              result.err = (com.worldpay.innovation.wpwithin.rpc.types.Error) e;
              result.setErrIsSet(true);
              msg = result;
            } else if (e instanceof org.apache.thrift.transport.TTransportException) {
              _LOGGER.error("TTransportException inside handler", e);
              fb.close();
              return;
            } else if (e instanceof org.apache.thrift.TApplicationException) {
              _LOGGER.error("TApplicationException inside handler", e);
              msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
              msg = (org.apache.thrift.TApplicationException)e;
            } else {
              _LOGGER.error("Exception inside handler", e);
              msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
              msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
            }
            try {
              fcall.sendResponse(fb,msg,msgType,seqid);
            } catch (java.lang.Exception ex) {
              _LOGGER.error("Exception writing to internal frame buffer", ex);
              fb.close();
            }
          }
        };
      }

      protected boolean isOneway() {
        return false;
      }

      public void start(I iface, beginServiceDelivery_args args, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler) throws org.apache.thrift.TException {
        iface.beginServiceDelivery(args.serviceID, args.serviceDeliveryToken, args.unitsToSupply,resultHandler);
      }
    }

    public static class endServiceDelivery<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, endServiceDelivery_args, Void> {
      public endServiceDelivery() {
        super("endServiceDelivery");
      }

      public endServiceDelivery_args getEmptyArgsInstance() {
        return new endServiceDelivery_args();
      }

      public org.apache.thrift.async.AsyncMethodCallback<Void> getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) {
        final org.apache.thrift.AsyncProcessFunction fcall = this;
        return new org.apache.thrift.async.AsyncMethodCallback<Void>() { 
          public void onComplete(Void o) {
            endServiceDelivery_result result = new endServiceDelivery_result();
            try {
              fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid);
            } catch (org.apache.thrift.transport.TTransportException e) {
              _LOGGER.error("TTransportException writing to internal frame buffer", e);
              fb.close();
            } catch (java.lang.Exception e) {
              _LOGGER.error("Exception writing to internal frame buffer", e);
              onError(e);
            }
          }
          public void onError(java.lang.Exception e) {
            byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
            org.apache.thrift.TSerializable msg;
            endServiceDelivery_result result = new endServiceDelivery_result();
            if (e instanceof com.worldpay.innovation.wpwithin.rpc.types.Error) {
              result.err = (com.worldpay.innovation.wpwithin.rpc.types.Error) e;
              result.setErrIsSet(true);
              msg = result;
            } else if (e instanceof org.apache.thrift.transport.TTransportException) {
              _LOGGER.error("TTransportException inside handler", e);
              fb.close();
              return;
            } else if (e instanceof org.apache.thrift.TApplicationException) {
              _LOGGER.error("TApplicationException inside handler", e);
              msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
              msg = (org.apache.thrift.TApplicationException)e;
            } else {
              _LOGGER.error("Exception inside handler", e);
              msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
              msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
            }
            try {
              fcall.sendResponse(fb,msg,msgType,seqid);
            } catch (java.lang.Exception ex) {
              _LOGGER.error("Exception writing to internal frame buffer", ex);
              fb.close();
            }
          }
        };
      }

      protected boolean isOneway() {
        return false;
      }

      public void start(I iface, endServiceDelivery_args args, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler) throws org.apache.thrift.TException {
        iface.endServiceDelivery(args.serviceID, args.serviceDeliveryToken, args.unitsReceived,resultHandler);
      }
    }

  }

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

    private static final org.apache.thrift.protocol.TField SERVICE_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("serviceID", org.apache.thrift.protocol.TType.I32, (short)1);
    private static final org.apache.thrift.protocol.TField SERVICE_DELIVERY_TOKEN_FIELD_DESC = new org.apache.thrift.protocol.TField("serviceDeliveryToken", org.apache.thrift.protocol.TType.STRUCT, (short)2);
    private static final org.apache.thrift.protocol.TField UNITS_TO_SUPPLY_FIELD_DESC = new org.apache.thrift.protocol.TField("unitsToSupply", org.apache.thrift.protocol.TType.I32, (short)3);

    private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new beginServiceDelivery_argsStandardSchemeFactory();
    private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new beginServiceDelivery_argsTupleSchemeFactory();

    public int serviceID; // required
    public com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken; // required
    public int unitsToSupply; // 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 {
      SERVICE_ID((short)1, "serviceID"),
      SERVICE_DELIVERY_TOKEN((short)2, "serviceDeliveryToken"),
      UNITS_TO_SUPPLY((short)3, "unitsToSupply");

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

      static {
        for (_Fields field : java.util.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: // SERVICE_ID
            return SERVICE_ID;
          case 2: // SERVICE_DELIVERY_TOKEN
            return SERVICE_DELIVERY_TOKEN;
          case 3: // UNITS_TO_SUPPLY
            return UNITS_TO_SUPPLY;
          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 java.lang.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(java.lang.String name) {
        return byName.get(name);
      }

      private final short _thriftId;
      private final java.lang.String _fieldName;

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

      public short getThriftFieldId() {
        return _thriftId;
      }

      public java.lang.String getFieldName() {
        return _fieldName;
      }
    }

    // isset id assignments
    private static final int __SERVICEID_ISSET_ID = 0;
    private static final int __UNITSTOSUPPLY_ISSET_ID = 1;
    private byte __isset_bitfield = 0;
    public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
      java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
      tmpMap.put(_Fields.SERVICE_ID, new org.apache.thrift.meta_data.FieldMetaData("serviceID", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
      tmpMap.put(_Fields.SERVICE_DELIVERY_TOKEN, new org.apache.thrift.meta_data.FieldMetaData("serviceDeliveryToken", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken.class)));
      tmpMap.put(_Fields.UNITS_TO_SUPPLY, new org.apache.thrift.meta_data.FieldMetaData("unitsToSupply", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
      metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(beginServiceDelivery_args.class, metaDataMap);
    }

    public beginServiceDelivery_args() {
    }

    public beginServiceDelivery_args(
      int serviceID,
      com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken,
      int unitsToSupply)
    {
      this();
      this.serviceID = serviceID;
      setServiceIDIsSet(true);
      this.serviceDeliveryToken = serviceDeliveryToken;
      this.unitsToSupply = unitsToSupply;
      setUnitsToSupplyIsSet(true);
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public beginServiceDelivery_args(beginServiceDelivery_args other) {
      __isset_bitfield = other.__isset_bitfield;
      this.serviceID = other.serviceID;
      if (other.isSetServiceDeliveryToken()) {
        this.serviceDeliveryToken = new com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken(other.serviceDeliveryToken);
      }
      this.unitsToSupply = other.unitsToSupply;
    }

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

    @Override
    public void clear() {
      setServiceIDIsSet(false);
      this.serviceID = 0;
      this.serviceDeliveryToken = null;
      setUnitsToSupplyIsSet(false);
      this.unitsToSupply = 0;
    }

    public int getServiceID() {
      return this.serviceID;
    }

    public beginServiceDelivery_args setServiceID(int serviceID) {
      this.serviceID = serviceID;
      setServiceIDIsSet(true);
      return this;
    }

    public void unsetServiceID() {
      __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __SERVICEID_ISSET_ID);
    }

    /** Returns true if field serviceID is set (has been assigned a value) and false otherwise */
    public boolean isSetServiceID() {
      return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __SERVICEID_ISSET_ID);
    }

    public void setServiceIDIsSet(boolean value) {
      __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __SERVICEID_ISSET_ID, value);
    }

    public com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken getServiceDeliveryToken() {
      return this.serviceDeliveryToken;
    }

    public beginServiceDelivery_args setServiceDeliveryToken(com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken) {
      this.serviceDeliveryToken = serviceDeliveryToken;
      return this;
    }

    public void unsetServiceDeliveryToken() {
      this.serviceDeliveryToken = null;
    }

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

    public void setServiceDeliveryTokenIsSet(boolean value) {
      if (!value) {
        this.serviceDeliveryToken = null;
      }
    }

    public int getUnitsToSupply() {
      return this.unitsToSupply;
    }

    public beginServiceDelivery_args setUnitsToSupply(int unitsToSupply) {
      this.unitsToSupply = unitsToSupply;
      setUnitsToSupplyIsSet(true);
      return this;
    }

    public void unsetUnitsToSupply() {
      __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __UNITSTOSUPPLY_ISSET_ID);
    }

    /** Returns true if field unitsToSupply is set (has been assigned a value) and false otherwise */
    public boolean isSetUnitsToSupply() {
      return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __UNITSTOSUPPLY_ISSET_ID);
    }

    public void setUnitsToSupplyIsSet(boolean value) {
      __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __UNITSTOSUPPLY_ISSET_ID, value);
    }

    public void setFieldValue(_Fields field, java.lang.Object value) {
      switch (field) {
      case SERVICE_ID:
        if (value == null) {
          unsetServiceID();
        } else {
          setServiceID((java.lang.Integer)value);
        }
        break;

      case SERVICE_DELIVERY_TOKEN:
        if (value == null) {
          unsetServiceDeliveryToken();
        } else {
          setServiceDeliveryToken((com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken)value);
        }
        break;

      case UNITS_TO_SUPPLY:
        if (value == null) {
          unsetUnitsToSupply();
        } else {
          setUnitsToSupply((java.lang.Integer)value);
        }
        break;

      }
    }

    public java.lang.Object getFieldValue(_Fields field) {
      switch (field) {
      case SERVICE_ID:
        return getServiceID();

      case SERVICE_DELIVERY_TOKEN:
        return getServiceDeliveryToken();

      case UNITS_TO_SUPPLY:
        return getUnitsToSupply();

      }
      throw new java.lang.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 java.lang.IllegalArgumentException();
      }

      switch (field) {
      case SERVICE_ID:
        return isSetServiceID();
      case SERVICE_DELIVERY_TOKEN:
        return isSetServiceDeliveryToken();
      case UNITS_TO_SUPPLY:
        return isSetUnitsToSupply();
      }
      throw new java.lang.IllegalStateException();
    }

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

    public boolean equals(beginServiceDelivery_args that) {
      if (that == null)
        return false;
      if (this == that)
        return true;

      boolean this_present_serviceID = true;
      boolean that_present_serviceID = true;
      if (this_present_serviceID || that_present_serviceID) {
        if (!(this_present_serviceID && that_present_serviceID))
          return false;
        if (this.serviceID != that.serviceID)
          return false;
      }

      boolean this_present_serviceDeliveryToken = true && this.isSetServiceDeliveryToken();
      boolean that_present_serviceDeliveryToken = true && that.isSetServiceDeliveryToken();
      if (this_present_serviceDeliveryToken || that_present_serviceDeliveryToken) {
        if (!(this_present_serviceDeliveryToken && that_present_serviceDeliveryToken))
          return false;
        if (!this.serviceDeliveryToken.equals(that.serviceDeliveryToken))
          return false;
      }

      boolean this_present_unitsToSupply = true;
      boolean that_present_unitsToSupply = true;
      if (this_present_unitsToSupply || that_present_unitsToSupply) {
        if (!(this_present_unitsToSupply && that_present_unitsToSupply))
          return false;
        if (this.unitsToSupply != that.unitsToSupply)
          return false;
      }

      return true;
    }

    @Override
    public int hashCode() {
      int hashCode = 1;

      hashCode = hashCode * 8191 + serviceID;

      hashCode = hashCode * 8191 + ((isSetServiceDeliveryToken()) ? 131071 : 524287);
      if (isSetServiceDeliveryToken())
        hashCode = hashCode * 8191 + serviceDeliveryToken.hashCode();

      hashCode = hashCode * 8191 + unitsToSupply;

      return hashCode;
    }

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

      int lastComparison = 0;

      lastComparison = java.lang.Boolean.valueOf(isSetServiceID()).compareTo(other.isSetServiceID());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetServiceID()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.serviceID, other.serviceID);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      lastComparison = java.lang.Boolean.valueOf(isSetServiceDeliveryToken()).compareTo(other.isSetServiceDeliveryToken());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetServiceDeliveryToken()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.serviceDeliveryToken, other.serviceDeliveryToken);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      lastComparison = java.lang.Boolean.valueOf(isSetUnitsToSupply()).compareTo(other.isSetUnitsToSupply());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetUnitsToSupply()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.unitsToSupply, other.unitsToSupply);
        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 {
      scheme(iprot).read(iprot, this);
    }

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

    @Override
    public java.lang.String toString() {
      java.lang.StringBuilder sb = new java.lang.StringBuilder("beginServiceDelivery_args(");
      boolean first = true;

      sb.append("serviceID:");
      sb.append(this.serviceID);
      first = false;
      if (!first) sb.append(", ");
      sb.append("serviceDeliveryToken:");
      if (this.serviceDeliveryToken == null) {
        sb.append("null");
      } else {
        sb.append(this.serviceDeliveryToken);
      }
      first = false;
      if (!first) sb.append(", ");
      sb.append("unitsToSupply:");
      sb.append(this.unitsToSupply);
      first = false;
      sb.append(")");
      return sb.toString();
    }

    public void validate() throws org.apache.thrift.TException {
      // check for required fields
      // check for sub-struct validity
      if (serviceDeliveryToken != null) {
        serviceDeliveryToken.validate();
      }
    }

    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, java.lang.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 beginServiceDelivery_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
      public beginServiceDelivery_argsStandardScheme getScheme() {
        return new beginServiceDelivery_argsStandardScheme();
      }
    }

    private static class beginServiceDelivery_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme<beginServiceDelivery_args> {

      public void read(org.apache.thrift.protocol.TProtocol iprot, beginServiceDelivery_args 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: // SERVICE_ID
              if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                struct.serviceID = iprot.readI32();
                struct.setServiceIDIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 2: // SERVICE_DELIVERY_TOKEN
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.serviceDeliveryToken = new com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken();
                struct.serviceDeliveryToken.read(iprot);
                struct.setServiceDeliveryTokenIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 3: // UNITS_TO_SUPPLY
              if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                struct.unitsToSupply = iprot.readI32();
                struct.setUnitsToSupplyIsSet(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, beginServiceDelivery_args struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        oprot.writeFieldBegin(SERVICE_ID_FIELD_DESC);
        oprot.writeI32(struct.serviceID);
        oprot.writeFieldEnd();
        if (struct.serviceDeliveryToken != null) {
          oprot.writeFieldBegin(SERVICE_DELIVERY_TOKEN_FIELD_DESC);
          struct.serviceDeliveryToken.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldBegin(UNITS_TO_SUPPLY_FIELD_DESC);
        oprot.writeI32(struct.unitsToSupply);
        oprot.writeFieldEnd();
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

    }

    private static class beginServiceDelivery_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
      public beginServiceDelivery_argsTupleScheme getScheme() {
        return new beginServiceDelivery_argsTupleScheme();
      }
    }

    private static class beginServiceDelivery_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme<beginServiceDelivery_args> {

      @Override
      public void write(org.apache.thrift.protocol.TProtocol prot, beginServiceDelivery_args struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
        java.util.BitSet optionals = new java.util.BitSet();
        if (struct.isSetServiceID()) {
          optionals.set(0);
        }
        if (struct.isSetServiceDeliveryToken()) {
          optionals.set(1);
        }
        if (struct.isSetUnitsToSupply()) {
          optionals.set(2);
        }
        oprot.writeBitSet(optionals, 3);
        if (struct.isSetServiceID()) {
          oprot.writeI32(struct.serviceID);
        }
        if (struct.isSetServiceDeliveryToken()) {
          struct.serviceDeliveryToken.write(oprot);
        }
        if (struct.isSetUnitsToSupply()) {
          oprot.writeI32(struct.unitsToSupply);
        }
      }

      @Override
      public void read(org.apache.thrift.protocol.TProtocol prot, beginServiceDelivery_args struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
        java.util.BitSet incoming = iprot.readBitSet(3);
        if (incoming.get(0)) {
          struct.serviceID = iprot.readI32();
          struct.setServiceIDIsSet(true);
        }
        if (incoming.get(1)) {
          struct.serviceDeliveryToken = new com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken();
          struct.serviceDeliveryToken.read(iprot);
          struct.setServiceDeliveryTokenIsSet(true);
        }
        if (incoming.get(2)) {
          struct.unitsToSupply = iprot.readI32();
          struct.setUnitsToSupplyIsSet(true);
        }
      }
    }

    private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
      return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
    }
  }

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

    private static final org.apache.thrift.protocol.TField ERR_FIELD_DESC = new org.apache.thrift.protocol.TField("err", org.apache.thrift.protocol.TType.STRUCT, (short)1);

    private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new beginServiceDelivery_resultStandardSchemeFactory();
    private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new beginServiceDelivery_resultTupleSchemeFactory();

    public com.worldpay.innovation.wpwithin.rpc.types.Error err; // 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 {
      ERR((short)1, "err");

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

      static {
        for (_Fields field : java.util.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: // ERR
            return ERR;
          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 java.lang.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(java.lang.String name) {
        return byName.get(name);
      }

      private final short _thriftId;
      private final java.lang.String _fieldName;

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

      public short getThriftFieldId() {
        return _thriftId;
      }

      public java.lang.String getFieldName() {
        return _fieldName;
      }
    }

    // isset id assignments
    public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
      java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
      tmpMap.put(_Fields.ERR, new org.apache.thrift.meta_data.FieldMetaData("err", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.worldpay.innovation.wpwithin.rpc.types.Error.class)));
      metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(beginServiceDelivery_result.class, metaDataMap);
    }

    public beginServiceDelivery_result() {
    }

    public beginServiceDelivery_result(
      com.worldpay.innovation.wpwithin.rpc.types.Error err)
    {
      this();
      this.err = err;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public beginServiceDelivery_result(beginServiceDelivery_result other) {
      if (other.isSetErr()) {
        this.err = new com.worldpay.innovation.wpwithin.rpc.types.Error(other.err);
      }
    }

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

    @Override
    public void clear() {
      this.err = null;
    }

    public com.worldpay.innovation.wpwithin.rpc.types.Error getErr() {
      return this.err;
    }

    public beginServiceDelivery_result setErr(com.worldpay.innovation.wpwithin.rpc.types.Error err) {
      this.err = err;
      return this;
    }

    public void unsetErr() {
      this.err = null;
    }

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

    public void setErrIsSet(boolean value) {
      if (!value) {
        this.err = null;
      }
    }

    public void setFieldValue(_Fields field, java.lang.Object value) {
      switch (field) {
      case ERR:
        if (value == null) {
          unsetErr();
        } else {
          setErr((com.worldpay.innovation.wpwithin.rpc.types.Error)value);
        }
        break;

      }
    }

    public java.lang.Object getFieldValue(_Fields field) {
      switch (field) {
      case ERR:
        return getErr();

      }
      throw new java.lang.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 java.lang.IllegalArgumentException();
      }

      switch (field) {
      case ERR:
        return isSetErr();
      }
      throw new java.lang.IllegalStateException();
    }

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

    public boolean equals(beginServiceDelivery_result that) {
      if (that == null)
        return false;
      if (this == that)
        return true;

      boolean this_present_err = true && this.isSetErr();
      boolean that_present_err = true && that.isSetErr();
      if (this_present_err || that_present_err) {
        if (!(this_present_err && that_present_err))
          return false;
        if (!this.err.equals(that.err))
          return false;
      }

      return true;
    }

    @Override
    public int hashCode() {
      int hashCode = 1;

      hashCode = hashCode * 8191 + ((isSetErr()) ? 131071 : 524287);
      if (isSetErr())
        hashCode = hashCode * 8191 + err.hashCode();

      return hashCode;
    }

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

      int lastComparison = 0;

      lastComparison = java.lang.Boolean.valueOf(isSetErr()).compareTo(other.isSetErr());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetErr()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.err, other.err);
        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 {
      scheme(iprot).read(iprot, this);
    }

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

    @Override
    public java.lang.String toString() {
      java.lang.StringBuilder sb = new java.lang.StringBuilder("beginServiceDelivery_result(");
      boolean first = true;

      sb.append("err:");
      if (this.err == null) {
        sb.append("null");
      } else {
        sb.append(this.err);
      }
      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, java.lang.ClassNotFoundException {
      try {
        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 beginServiceDelivery_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
      public beginServiceDelivery_resultStandardScheme getScheme() {
        return new beginServiceDelivery_resultStandardScheme();
      }
    }

    private static class beginServiceDelivery_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme<beginServiceDelivery_result> {

      public void read(org.apache.thrift.protocol.TProtocol iprot, beginServiceDelivery_result 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: // ERR
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.err = new com.worldpay.innovation.wpwithin.rpc.types.Error();
                struct.err.read(iprot);
                struct.setErrIsSet(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, beginServiceDelivery_result struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        if (struct.err != null) {
          oprot.writeFieldBegin(ERR_FIELD_DESC);
          struct.err.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

    }

    private static class beginServiceDelivery_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
      public beginServiceDelivery_resultTupleScheme getScheme() {
        return new beginServiceDelivery_resultTupleScheme();
      }
    }

    private static class beginServiceDelivery_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme<beginServiceDelivery_result> {

      @Override
      public void write(org.apache.thrift.protocol.TProtocol prot, beginServiceDelivery_result struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
        java.util.BitSet optionals = new java.util.BitSet();
        if (struct.isSetErr()) {
          optionals.set(0);
        }
        oprot.writeBitSet(optionals, 1);
        if (struct.isSetErr()) {
          struct.err.write(oprot);
        }
      }

      @Override
      public void read(org.apache.thrift.protocol.TProtocol prot, beginServiceDelivery_result struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
        java.util.BitSet incoming = iprot.readBitSet(1);
        if (incoming.get(0)) {
          struct.err = new com.worldpay.innovation.wpwithin.rpc.types.Error();
          struct.err.read(iprot);
          struct.setErrIsSet(true);
        }
      }
    }

    private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
      return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
    }
  }

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

    private static final org.apache.thrift.protocol.TField SERVICE_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("serviceID", org.apache.thrift.protocol.TType.I32, (short)1);
    private static final org.apache.thrift.protocol.TField SERVICE_DELIVERY_TOKEN_FIELD_DESC = new org.apache.thrift.protocol.TField("serviceDeliveryToken", org.apache.thrift.protocol.TType.STRUCT, (short)2);
    private static final org.apache.thrift.protocol.TField UNITS_RECEIVED_FIELD_DESC = new org.apache.thrift.protocol.TField("unitsReceived", org.apache.thrift.protocol.TType.I32, (short)3);

    private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new endServiceDelivery_argsStandardSchemeFactory();
    private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new endServiceDelivery_argsTupleSchemeFactory();

    public int serviceID; // required
    public com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken; // required
    public int unitsReceived; // 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 {
      SERVICE_ID((short)1, "serviceID"),
      SERVICE_DELIVERY_TOKEN((short)2, "serviceDeliveryToken"),
      UNITS_RECEIVED((short)3, "unitsReceived");

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

      static {
        for (_Fields field : java.util.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: // SERVICE_ID
            return SERVICE_ID;
          case 2: // SERVICE_DELIVERY_TOKEN
            return SERVICE_DELIVERY_TOKEN;
          case 3: // UNITS_RECEIVED
            return UNITS_RECEIVED;
          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 java.lang.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(java.lang.String name) {
        return byName.get(name);
      }

      private final short _thriftId;
      private final java.lang.String _fieldName;

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

      public short getThriftFieldId() {
        return _thriftId;
      }

      public java.lang.String getFieldName() {
        return _fieldName;
      }
    }

    // isset id assignments
    private static final int __SERVICEID_ISSET_ID = 0;
    private static final int __UNITSRECEIVED_ISSET_ID = 1;
    private byte __isset_bitfield = 0;
    public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
      java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
      tmpMap.put(_Fields.SERVICE_ID, new org.apache.thrift.meta_data.FieldMetaData("serviceID", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
      tmpMap.put(_Fields.SERVICE_DELIVERY_TOKEN, new org.apache.thrift.meta_data.FieldMetaData("serviceDeliveryToken", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken.class)));
      tmpMap.put(_Fields.UNITS_RECEIVED, new org.apache.thrift.meta_data.FieldMetaData("unitsReceived", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
      metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(endServiceDelivery_args.class, metaDataMap);
    }

    public endServiceDelivery_args() {
    }

    public endServiceDelivery_args(
      int serviceID,
      com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken,
      int unitsReceived)
    {
      this();
      this.serviceID = serviceID;
      setServiceIDIsSet(true);
      this.serviceDeliveryToken = serviceDeliveryToken;
      this.unitsReceived = unitsReceived;
      setUnitsReceivedIsSet(true);
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public endServiceDelivery_args(endServiceDelivery_args other) {
      __isset_bitfield = other.__isset_bitfield;
      this.serviceID = other.serviceID;
      if (other.isSetServiceDeliveryToken()) {
        this.serviceDeliveryToken = new com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken(other.serviceDeliveryToken);
      }
      this.unitsReceived = other.unitsReceived;
    }

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

    @Override
    public void clear() {
      setServiceIDIsSet(false);
      this.serviceID = 0;
      this.serviceDeliveryToken = null;
      setUnitsReceivedIsSet(false);
      this.unitsReceived = 0;
    }

    public int getServiceID() {
      return this.serviceID;
    }

    public endServiceDelivery_args setServiceID(int serviceID) {
      this.serviceID = serviceID;
      setServiceIDIsSet(true);
      return this;
    }

    public void unsetServiceID() {
      __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __SERVICEID_ISSET_ID);
    }

    /** Returns true if field serviceID is set (has been assigned a value) and false otherwise */
    public boolean isSetServiceID() {
      return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __SERVICEID_ISSET_ID);
    }

    public void setServiceIDIsSet(boolean value) {
      __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __SERVICEID_ISSET_ID, value);
    }

    public com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken getServiceDeliveryToken() {
      return this.serviceDeliveryToken;
    }

    public endServiceDelivery_args setServiceDeliveryToken(com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken serviceDeliveryToken) {
      this.serviceDeliveryToken = serviceDeliveryToken;
      return this;
    }

    public void unsetServiceDeliveryToken() {
      this.serviceDeliveryToken = null;
    }

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

    public void setServiceDeliveryTokenIsSet(boolean value) {
      if (!value) {
        this.serviceDeliveryToken = null;
      }
    }

    public int getUnitsReceived() {
      return this.unitsReceived;
    }

    public endServiceDelivery_args setUnitsReceived(int unitsReceived) {
      this.unitsReceived = unitsReceived;
      setUnitsReceivedIsSet(true);
      return this;
    }

    public void unsetUnitsReceived() {
      __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __UNITSRECEIVED_ISSET_ID);
    }

    /** Returns true if field unitsReceived is set (has been assigned a value) and false otherwise */
    public boolean isSetUnitsReceived() {
      return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __UNITSRECEIVED_ISSET_ID);
    }

    public void setUnitsReceivedIsSet(boolean value) {
      __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __UNITSRECEIVED_ISSET_ID, value);
    }

    public void setFieldValue(_Fields field, java.lang.Object value) {
      switch (field) {
      case SERVICE_ID:
        if (value == null) {
          unsetServiceID();
        } else {
          setServiceID((java.lang.Integer)value);
        }
        break;

      case SERVICE_DELIVERY_TOKEN:
        if (value == null) {
          unsetServiceDeliveryToken();
        } else {
          setServiceDeliveryToken((com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken)value);
        }
        break;

      case UNITS_RECEIVED:
        if (value == null) {
          unsetUnitsReceived();
        } else {
          setUnitsReceived((java.lang.Integer)value);
        }
        break;

      }
    }

    public java.lang.Object getFieldValue(_Fields field) {
      switch (field) {
      case SERVICE_ID:
        return getServiceID();

      case SERVICE_DELIVERY_TOKEN:
        return getServiceDeliveryToken();

      case UNITS_RECEIVED:
        return getUnitsReceived();

      }
      throw new java.lang.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 java.lang.IllegalArgumentException();
      }

      switch (field) {
      case SERVICE_ID:
        return isSetServiceID();
      case SERVICE_DELIVERY_TOKEN:
        return isSetServiceDeliveryToken();
      case UNITS_RECEIVED:
        return isSetUnitsReceived();
      }
      throw new java.lang.IllegalStateException();
    }

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

    public boolean equals(endServiceDelivery_args that) {
      if (that == null)
        return false;
      if (this == that)
        return true;

      boolean this_present_serviceID = true;
      boolean that_present_serviceID = true;
      if (this_present_serviceID || that_present_serviceID) {
        if (!(this_present_serviceID && that_present_serviceID))
          return false;
        if (this.serviceID != that.serviceID)
          return false;
      }

      boolean this_present_serviceDeliveryToken = true && this.isSetServiceDeliveryToken();
      boolean that_present_serviceDeliveryToken = true && that.isSetServiceDeliveryToken();
      if (this_present_serviceDeliveryToken || that_present_serviceDeliveryToken) {
        if (!(this_present_serviceDeliveryToken && that_present_serviceDeliveryToken))
          return false;
        if (!this.serviceDeliveryToken.equals(that.serviceDeliveryToken))
          return false;
      }

      boolean this_present_unitsReceived = true;
      boolean that_present_unitsReceived = true;
      if (this_present_unitsReceived || that_present_unitsReceived) {
        if (!(this_present_unitsReceived && that_present_unitsReceived))
          return false;
        if (this.unitsReceived != that.unitsReceived)
          return false;
      }

      return true;
    }

    @Override
    public int hashCode() {
      int hashCode = 1;

      hashCode = hashCode * 8191 + serviceID;

      hashCode = hashCode * 8191 + ((isSetServiceDeliveryToken()) ? 131071 : 524287);
      if (isSetServiceDeliveryToken())
        hashCode = hashCode * 8191 + serviceDeliveryToken.hashCode();

      hashCode = hashCode * 8191 + unitsReceived;

      return hashCode;
    }

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

      int lastComparison = 0;

      lastComparison = java.lang.Boolean.valueOf(isSetServiceID()).compareTo(other.isSetServiceID());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetServiceID()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.serviceID, other.serviceID);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      lastComparison = java.lang.Boolean.valueOf(isSetServiceDeliveryToken()).compareTo(other.isSetServiceDeliveryToken());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetServiceDeliveryToken()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.serviceDeliveryToken, other.serviceDeliveryToken);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      lastComparison = java.lang.Boolean.valueOf(isSetUnitsReceived()).compareTo(other.isSetUnitsReceived());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetUnitsReceived()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.unitsReceived, other.unitsReceived);
        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 {
      scheme(iprot).read(iprot, this);
    }

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

    @Override
    public java.lang.String toString() {
      java.lang.StringBuilder sb = new java.lang.StringBuilder("endServiceDelivery_args(");
      boolean first = true;

      sb.append("serviceID:");
      sb.append(this.serviceID);
      first = false;
      if (!first) sb.append(", ");
      sb.append("serviceDeliveryToken:");
      if (this.serviceDeliveryToken == null) {
        sb.append("null");
      } else {
        sb.append(this.serviceDeliveryToken);
      }
      first = false;
      if (!first) sb.append(", ");
      sb.append("unitsReceived:");
      sb.append(this.unitsReceived);
      first = false;
      sb.append(")");
      return sb.toString();
    }

    public void validate() throws org.apache.thrift.TException {
      // check for required fields
      // check for sub-struct validity
      if (serviceDeliveryToken != null) {
        serviceDeliveryToken.validate();
      }
    }

    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, java.lang.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 endServiceDelivery_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
      public endServiceDelivery_argsStandardScheme getScheme() {
        return new endServiceDelivery_argsStandardScheme();
      }
    }

    private static class endServiceDelivery_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme<endServiceDelivery_args> {

      public void read(org.apache.thrift.protocol.TProtocol iprot, endServiceDelivery_args 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: // SERVICE_ID
              if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                struct.serviceID = iprot.readI32();
                struct.setServiceIDIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 2: // SERVICE_DELIVERY_TOKEN
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.serviceDeliveryToken = new com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken();
                struct.serviceDeliveryToken.read(iprot);
                struct.setServiceDeliveryTokenIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 3: // UNITS_RECEIVED
              if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                struct.unitsReceived = iprot.readI32();
                struct.setUnitsReceivedIsSet(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, endServiceDelivery_args struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        oprot.writeFieldBegin(SERVICE_ID_FIELD_DESC);
        oprot.writeI32(struct.serviceID);
        oprot.writeFieldEnd();
        if (struct.serviceDeliveryToken != null) {
          oprot.writeFieldBegin(SERVICE_DELIVERY_TOKEN_FIELD_DESC);
          struct.serviceDeliveryToken.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldBegin(UNITS_RECEIVED_FIELD_DESC);
        oprot.writeI32(struct.unitsReceived);
        oprot.writeFieldEnd();
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

    }

    private static class endServiceDelivery_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
      public endServiceDelivery_argsTupleScheme getScheme() {
        return new endServiceDelivery_argsTupleScheme();
      }
    }

    private static class endServiceDelivery_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme<endServiceDelivery_args> {

      @Override
      public void write(org.apache.thrift.protocol.TProtocol prot, endServiceDelivery_args struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
        java.util.BitSet optionals = new java.util.BitSet();
        if (struct.isSetServiceID()) {
          optionals.set(0);
        }
        if (struct.isSetServiceDeliveryToken()) {
          optionals.set(1);
        }
        if (struct.isSetUnitsReceived()) {
          optionals.set(2);
        }
        oprot.writeBitSet(optionals, 3);
        if (struct.isSetServiceID()) {
          oprot.writeI32(struct.serviceID);
        }
        if (struct.isSetServiceDeliveryToken()) {
          struct.serviceDeliveryToken.write(oprot);
        }
        if (struct.isSetUnitsReceived()) {
          oprot.writeI32(struct.unitsReceived);
        }
      }

      @Override
      public void read(org.apache.thrift.protocol.TProtocol prot, endServiceDelivery_args struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
        java.util.BitSet incoming = iprot.readBitSet(3);
        if (incoming.get(0)) {
          struct.serviceID = iprot.readI32();
          struct.setServiceIDIsSet(true);
        }
        if (incoming.get(1)) {
          struct.serviceDeliveryToken = new com.worldpay.innovation.wpwithin.rpc.types.ServiceDeliveryToken();
          struct.serviceDeliveryToken.read(iprot);
          struct.setServiceDeliveryTokenIsSet(true);
        }
        if (incoming.get(2)) {
          struct.unitsReceived = iprot.readI32();
          struct.setUnitsReceivedIsSet(true);
        }
      }
    }

    private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
      return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
    }
  }

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

    private static final org.apache.thrift.protocol.TField ERR_FIELD_DESC = new org.apache.thrift.protocol.TField("err", org.apache.thrift.protocol.TType.STRUCT, (short)1);

    private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new endServiceDelivery_resultStandardSchemeFactory();
    private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new endServiceDelivery_resultTupleSchemeFactory();

    public com.worldpay.innovation.wpwithin.rpc.types.Error err; // 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 {
      ERR((short)1, "err");

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

      static {
        for (_Fields field : java.util.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: // ERR
            return ERR;
          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 java.lang.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(java.lang.String name) {
        return byName.get(name);
      }

      private final short _thriftId;
      private final java.lang.String _fieldName;

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

      public short getThriftFieldId() {
        return _thriftId;
      }

      public java.lang.String getFieldName() {
        return _fieldName;
      }
    }

    // isset id assignments
    public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
      java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
      tmpMap.put(_Fields.ERR, new org.apache.thrift.meta_data.FieldMetaData("err", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.worldpay.innovation.wpwithin.rpc.types.Error.class)));
      metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(endServiceDelivery_result.class, metaDataMap);
    }

    public endServiceDelivery_result() {
    }

    public endServiceDelivery_result(
      com.worldpay.innovation.wpwithin.rpc.types.Error err)
    {
      this();
      this.err = err;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public endServiceDelivery_result(endServiceDelivery_result other) {
      if (other.isSetErr()) {
        this.err = new com.worldpay.innovation.wpwithin.rpc.types.Error(other.err);
      }
    }

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

    @Override
    public void clear() {
      this.err = null;
    }

    public com.worldpay.innovation.wpwithin.rpc.types.Error getErr() {
      return this.err;
    }

    public endServiceDelivery_result setErr(com.worldpay.innovation.wpwithin.rpc.types.Error err) {
      this.err = err;
      return this;
    }

    public void unsetErr() {
      this.err = null;
    }

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

    public void setErrIsSet(boolean value) {
      if (!value) {
        this.err = null;
      }
    }

    public void setFieldValue(_Fields field, java.lang.Object value) {
      switch (field) {
      case ERR:
        if (value == null) {
          unsetErr();
        } else {
          setErr((com.worldpay.innovation.wpwithin.rpc.types.Error)value);
        }
        break;

      }
    }

    public java.lang.Object getFieldValue(_Fields field) {
      switch (field) {
      case ERR:
        return getErr();

      }
      throw new java.lang.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 java.lang.IllegalArgumentException();
      }

      switch (field) {
      case ERR:
        return isSetErr();
      }
      throw new java.lang.IllegalStateException();
    }

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

    public boolean equals(endServiceDelivery_result that) {
      if (that == null)
        return false;
      if (this == that)
        return true;

      boolean this_present_err = true && this.isSetErr();
      boolean that_present_err = true && that.isSetErr();
      if (this_present_err || that_present_err) {
        if (!(this_present_err && that_present_err))
          return false;
        if (!this.err.equals(that.err))
          return false;
      }

      return true;
    }

    @Override
    public int hashCode() {
      int hashCode = 1;

      hashCode = hashCode * 8191 + ((isSetErr()) ? 131071 : 524287);
      if (isSetErr())
        hashCode = hashCode * 8191 + err.hashCode();

      return hashCode;
    }

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

      int lastComparison = 0;

      lastComparison = java.lang.Boolean.valueOf(isSetErr()).compareTo(other.isSetErr());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetErr()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.err, other.err);
        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 {
      scheme(iprot).read(iprot, this);
    }

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

    @Override
    public java.lang.String toString() {
      java.lang.StringBuilder sb = new java.lang.StringBuilder("endServiceDelivery_result(");
      boolean first = true;

      sb.append("err:");
      if (this.err == null) {
        sb.append("null");
      } else {
        sb.append(this.err);
      }
      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, java.lang.ClassNotFoundException {
      try {
        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 endServiceDelivery_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
      public endServiceDelivery_resultStandardScheme getScheme() {
        return new endServiceDelivery_resultStandardScheme();
      }
    }

    private static class endServiceDelivery_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme<endServiceDelivery_result> {

      public void read(org.apache.thrift.protocol.TProtocol iprot, endServiceDelivery_result 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: // ERR
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.err = new com.worldpay.innovation.wpwithin.rpc.types.Error();
                struct.err.read(iprot);
                struct.setErrIsSet(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, endServiceDelivery_result struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        if (struct.err != null) {
          oprot.writeFieldBegin(ERR_FIELD_DESC);
          struct.err.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

    }

    private static class endServiceDelivery_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
      public endServiceDelivery_resultTupleScheme getScheme() {
        return new endServiceDelivery_resultTupleScheme();
      }
    }

    private static class endServiceDelivery_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme<endServiceDelivery_result> {

      @Override
      public void write(org.apache.thrift.protocol.TProtocol prot, endServiceDelivery_result struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
        java.util.BitSet optionals = new java.util.BitSet();
        if (struct.isSetErr()) {
          optionals.set(0);
        }
        oprot.writeBitSet(optionals, 1);
        if (struct.isSetErr()) {
          struct.err.write(oprot);
        }
      }

      @Override
      public void read(org.apache.thrift.protocol.TProtocol prot, endServiceDelivery_result struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
        java.util.BitSet incoming = iprot.readBitSet(1);
        if (incoming.get(0)) {
          struct.err = new com.worldpay.innovation.wpwithin.rpc.types.Error();
          struct.err.read(iprot);
          struct.setErrIsSet(true);
        }
      }
    }

    private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
      return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
    }
  }

}
