/**
 * Autogenerated by Thrift Compiler (0.14.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Thrift;
using Thrift.Collections;
using System.ServiceModel;
using System.Runtime.Serialization;

using Thrift.Protocol;
using Thrift.Protocol.Entities;
using Thrift.Protocol.Utilities;
using Thrift.Transport;
using Thrift.Transport.Client;
using Thrift.Transport.Server;
using Thrift.Processor;


#pragma warning disable IDE0079  // remove unnecessary pragmas
#pragma warning disable IDE1006  // parts of the code use IDL spelling

namespace Thrift5253
{
  public partial class MyService
  {
    [ServiceContract(Namespace="")]
    public interface IAsync
    {
      [OperationContract]
      global::System.Threading.Tasks.Task<global::Thrift5253.BrokenResult> BrokenAsync(global::Thrift5253.BrokenArgs foo, CancellationToken cancellationToken = default);

      [OperationContract]
      global::System.Threading.Tasks.Task<global::Thrift5253.WorksRslt> WorksAsync(global::Thrift5253.WorksArrrgs foo, CancellationToken cancellationToken = default);

      [OperationContract]
      global::System.Threading.Tasks.Task<global::Thrift5253.InternalStructs> InternalStructsAsync(global::Thrift5253.InternalStructs foo, CancellationToken cancellationToken = default);

      [OperationContract]
      global::System.Threading.Tasks.Task<global::Thrift5253.AsyncProcessor> AsyncProcessorAsync(global::Thrift5253.AsyncProcessor foo, CancellationToken cancellationToken = default);

      [OperationContract]
      global::System.Threading.Tasks.Task<global::Thrift5253.Client> ClientAsync(global::Thrift5253.Client foo, CancellationToken cancellationToken = default);

      [OperationContract]
      global::System.Threading.Tasks.Task<global::Thrift5253.IAsync> IAsyncAsync(global::Thrift5253.IAsync foo, CancellationToken cancellationToken = default);

    }


    public class Client : TBaseClient, IDisposable, IAsync
    {
      public Client(TProtocol protocol) : this(protocol, protocol)
      {
      }

      public Client(TProtocol inputProtocol, TProtocol outputProtocol) : base(inputProtocol, outputProtocol)      {
      }
      public async global::System.Threading.Tasks.Task<global::Thrift5253.BrokenResult> BrokenAsync(global::Thrift5253.BrokenArgs foo, CancellationToken cancellationToken = default)
      {
        await OutputProtocol.WriteMessageBeginAsync(new TMessage("Broken", TMessageType.Call, SeqId), cancellationToken);
        
        var args = new InternalStructs.BrokenArgs() {
          Foo = foo,
        };
        
        await args.WriteAsync(OutputProtocol, cancellationToken);
        await OutputProtocol.WriteMessageEndAsync(cancellationToken);
        await OutputProtocol.Transport.FlushAsync(cancellationToken);
        
        var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);
        if (msg.Type == TMessageType.Exception)
        {
          var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);
          await InputProtocol.ReadMessageEndAsync(cancellationToken);
          throw x;
        }

        var result = new InternalStructs.BrokenResult();
        await result.ReadAsync(InputProtocol, cancellationToken);
        await InputProtocol.ReadMessageEndAsync(cancellationToken);
        if (result.__isset.success)
        {
          return result.Success;
        }
        throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "Broken failed: unknown result");
      }

      public async global::System.Threading.Tasks.Task<global::Thrift5253.WorksRslt> WorksAsync(global::Thrift5253.WorksArrrgs foo, CancellationToken cancellationToken = default)
      {
        await OutputProtocol.WriteMessageBeginAsync(new TMessage("Works", TMessageType.Call, SeqId), cancellationToken);
        
        var args = new InternalStructs.WorksArgs() {
          Foo = foo,
        };
        
        await args.WriteAsync(OutputProtocol, cancellationToken);
        await OutputProtocol.WriteMessageEndAsync(cancellationToken);
        await OutputProtocol.Transport.FlushAsync(cancellationToken);
        
        var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);
        if (msg.Type == TMessageType.Exception)
        {
          var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);
          await InputProtocol.ReadMessageEndAsync(cancellationToken);
          throw x;
        }

        var result = new InternalStructs.WorksResult();
        await result.ReadAsync(InputProtocol, cancellationToken);
        await InputProtocol.ReadMessageEndAsync(cancellationToken);
        if (result.__isset.success)
        {
          return result.Success;
        }
        throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "Works failed: unknown result");
      }

      public async global::System.Threading.Tasks.Task<global::Thrift5253.InternalStructs> InternalStructsAsync(global::Thrift5253.InternalStructs foo, CancellationToken cancellationToken = default)
      {
        await OutputProtocol.WriteMessageBeginAsync(new TMessage("InternalStructs", TMessageType.Call, SeqId), cancellationToken);
        
        var args = new InternalStructs.InternalStructsArgs() {
          Foo = foo,
        };
        
        await args.WriteAsync(OutputProtocol, cancellationToken);
        await OutputProtocol.WriteMessageEndAsync(cancellationToken);
        await OutputProtocol.Transport.FlushAsync(cancellationToken);
        
        var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);
        if (msg.Type == TMessageType.Exception)
        {
          var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);
          await InputProtocol.ReadMessageEndAsync(cancellationToken);
          throw x;
        }

        var result = new InternalStructs.InternalStructsResult();
        await result.ReadAsync(InputProtocol, cancellationToken);
        await InputProtocol.ReadMessageEndAsync(cancellationToken);
        if (result.__isset.success)
        {
          return result.Success;
        }
        throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "InternalStructs failed: unknown result");
      }

      public async global::System.Threading.Tasks.Task<global::Thrift5253.AsyncProcessor> AsyncProcessorAsync(global::Thrift5253.AsyncProcessor foo, CancellationToken cancellationToken = default)
      {
        await OutputProtocol.WriteMessageBeginAsync(new TMessage("AsyncProcessorAsync", TMessageType.Call, SeqId), cancellationToken);
        
        var args = new InternalStructs.AsyncProcessorArgs() {
          Foo = foo,
        };
        
        await args.WriteAsync(OutputProtocol, cancellationToken);
        await OutputProtocol.WriteMessageEndAsync(cancellationToken);
        await OutputProtocol.Transport.FlushAsync(cancellationToken);
        
        var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);
        if (msg.Type == TMessageType.Exception)
        {
          var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);
          await InputProtocol.ReadMessageEndAsync(cancellationToken);
          throw x;
        }

        var result = new InternalStructs.AsyncProcessorResult();
        await result.ReadAsync(InputProtocol, cancellationToken);
        await InputProtocol.ReadMessageEndAsync(cancellationToken);
        if (result.__isset.success)
        {
          return result.Success;
        }
        throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "AsyncProcessorAsync failed: unknown result");
      }

      public async global::System.Threading.Tasks.Task<global::Thrift5253.Client> ClientAsync(global::Thrift5253.Client foo, CancellationToken cancellationToken = default)
      {
        await OutputProtocol.WriteMessageBeginAsync(new TMessage("Client", TMessageType.Call, SeqId), cancellationToken);
        
        var args = new InternalStructs.ClientArgs() {
          Foo = foo,
        };
        
        await args.WriteAsync(OutputProtocol, cancellationToken);
        await OutputProtocol.WriteMessageEndAsync(cancellationToken);
        await OutputProtocol.Transport.FlushAsync(cancellationToken);
        
        var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);
        if (msg.Type == TMessageType.Exception)
        {
          var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);
          await InputProtocol.ReadMessageEndAsync(cancellationToken);
          throw x;
        }

        var result = new InternalStructs.ClientResult();
        await result.ReadAsync(InputProtocol, cancellationToken);
        await InputProtocol.ReadMessageEndAsync(cancellationToken);
        if (result.__isset.success)
        {
          return result.Success;
        }
        throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "Client failed: unknown result");
      }

      public async global::System.Threading.Tasks.Task<global::Thrift5253.IAsync> IAsyncAsync(global::Thrift5253.IAsync foo, CancellationToken cancellationToken = default)
      {
        await OutputProtocol.WriteMessageBeginAsync(new TMessage("IAsyncAsync", TMessageType.Call, SeqId), cancellationToken);
        
        var args = new InternalStructs.IAsyncArgs() {
          Foo = foo,
        };
        
        await args.WriteAsync(OutputProtocol, cancellationToken);
        await OutputProtocol.WriteMessageEndAsync(cancellationToken);
        await OutputProtocol.Transport.FlushAsync(cancellationToken);
        
        var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);
        if (msg.Type == TMessageType.Exception)
        {
          var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);
          await InputProtocol.ReadMessageEndAsync(cancellationToken);
          throw x;
        }

        var result = new InternalStructs.IAsyncResult();
        await result.ReadAsync(InputProtocol, cancellationToken);
        await InputProtocol.ReadMessageEndAsync(cancellationToken);
        if (result.__isset.success)
        {
          return result.Success;
        }
        throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "IAsyncAsync failed: unknown result");
      }

    }

    public class AsyncProcessor : ITAsyncProcessor
    {
      private readonly IAsync _iAsync;
      private readonly ILogger<AsyncProcessor> _logger;

      public AsyncProcessor(IAsync iAsync, ILogger<AsyncProcessor> logger = default)
      {
        _iAsync = iAsync ?? throw new ArgumentNullException(nameof(iAsync));
        _logger = logger;
        processMap_["Broken"] = Broken_ProcessAsync;
        processMap_["Works"] = Works_ProcessAsync;
        processMap_["InternalStructs"] = InternalStructs_ProcessAsync;
        processMap_["AsyncProcessorAsync"] = AsyncProcessor_ProcessAsync;
        processMap_["Client"] = Client_ProcessAsync;
        processMap_["IAsyncAsync"] = IAsync_ProcessAsync;
      }

      protected delegate global::System.Threading.Tasks.Task ProcessFunction(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken);
      protected Dictionary<string, ProcessFunction> processMap_ = new Dictionary<string, ProcessFunction>();

      public async Task<bool> ProcessAsync(TProtocol iprot, TProtocol oprot)
      {
        return await ProcessAsync(iprot, oprot, CancellationToken.None);
      }

      public async Task<bool> ProcessAsync(TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
      {
        try
        {
          var msg = await iprot.ReadMessageBeginAsync(cancellationToken);

          processMap_.TryGetValue(msg.Name, out ProcessFunction fn);

          if (fn == null)
          {
            await TProtocolUtil.SkipAsync(iprot, TType.Struct, cancellationToken);
            await iprot.ReadMessageEndAsync(cancellationToken);
            var x = new TApplicationException (TApplicationException.ExceptionType.UnknownMethod, "Invalid method name: '" + msg.Name + "'");
            await oprot.WriteMessageBeginAsync(new TMessage(msg.Name, TMessageType.Exception, msg.SeqID), cancellationToken);
            await x.WriteAsync(oprot, cancellationToken);
            await oprot.WriteMessageEndAsync(cancellationToken);
            await oprot.Transport.FlushAsync(cancellationToken);
            return true;
          }

          await fn(msg.SeqID, iprot, oprot, cancellationToken);

        }
        catch (IOException)
        {
          return false;
        }

        return true;
      }

      public async global::System.Threading.Tasks.Task Broken_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
      {
        var args = new InternalStructs.BrokenArgs();
        await args.ReadAsync(iprot, cancellationToken);
        await iprot.ReadMessageEndAsync(cancellationToken);
        var result = new InternalStructs.BrokenResult();
        try
        {
          result.Success = await _iAsync.BrokenAsync(args.Foo, cancellationToken);
          await oprot.WriteMessageBeginAsync(new TMessage("Broken", TMessageType.Reply, seqid), cancellationToken); 
          await result.WriteAsync(oprot, cancellationToken);
        }
        catch (TTransportException)
        {
          throw;
        }
        catch (Exception ex)
        {
          var sErr = $"Error occurred in {GetType().FullName}: {ex.Message}";
          if(_logger != null)
            _logger.LogError(ex, sErr);
          else
            Console.Error.WriteLine(sErr);
          var x = new TApplicationException(TApplicationException.ExceptionType.InternalError," Internal error.");
          await oprot.WriteMessageBeginAsync(new TMessage("Broken", TMessageType.Exception, seqid), cancellationToken);
          await x.WriteAsync(oprot, cancellationToken);
        }
        await oprot.WriteMessageEndAsync(cancellationToken);
        await oprot.Transport.FlushAsync(cancellationToken);
      }

      public async global::System.Threading.Tasks.Task Works_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
      {
        var args = new InternalStructs.WorksArgs();
        await args.ReadAsync(iprot, cancellationToken);
        await iprot.ReadMessageEndAsync(cancellationToken);
        var result = new InternalStructs.WorksResult();
        try
        {
          result.Success = await _iAsync.WorksAsync(args.Foo, cancellationToken);
          await oprot.WriteMessageBeginAsync(new TMessage("Works", TMessageType.Reply, seqid), cancellationToken); 
          await result.WriteAsync(oprot, cancellationToken);
        }
        catch (TTransportException)
        {
          throw;
        }
        catch (Exception ex)
        {
          var sErr = $"Error occurred in {GetType().FullName}: {ex.Message}";
          if(_logger != null)
            _logger.LogError(ex, sErr);
          else
            Console.Error.WriteLine(sErr);
          var x = new TApplicationException(TApplicationException.ExceptionType.InternalError," Internal error.");
          await oprot.WriteMessageBeginAsync(new TMessage("Works", TMessageType.Exception, seqid), cancellationToken);
          await x.WriteAsync(oprot, cancellationToken);
        }
        await oprot.WriteMessageEndAsync(cancellationToken);
        await oprot.Transport.FlushAsync(cancellationToken);
      }

      public async global::System.Threading.Tasks.Task InternalStructs_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
      {
        var args = new InternalStructs.InternalStructsArgs();
        await args.ReadAsync(iprot, cancellationToken);
        await iprot.ReadMessageEndAsync(cancellationToken);
        var result = new InternalStructs.InternalStructsResult();
        try
        {
          result.Success = await _iAsync.InternalStructsAsync(args.Foo, cancellationToken);
          await oprot.WriteMessageBeginAsync(new TMessage("InternalStructs", TMessageType.Reply, seqid), cancellationToken); 
          await result.WriteAsync(oprot, cancellationToken);
        }
        catch (TTransportException)
        {
          throw;
        }
        catch (Exception ex)
        {
          var sErr = $"Error occurred in {GetType().FullName}: {ex.Message}";
          if(_logger != null)
            _logger.LogError(ex, sErr);
          else
            Console.Error.WriteLine(sErr);
          var x = new TApplicationException(TApplicationException.ExceptionType.InternalError," Internal error.");
          await oprot.WriteMessageBeginAsync(new TMessage("InternalStructs", TMessageType.Exception, seqid), cancellationToken);
          await x.WriteAsync(oprot, cancellationToken);
        }
        await oprot.WriteMessageEndAsync(cancellationToken);
        await oprot.Transport.FlushAsync(cancellationToken);
      }

      public async global::System.Threading.Tasks.Task AsyncProcessor_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
      {
        var args = new InternalStructs.AsyncProcessorArgs();
        await args.ReadAsync(iprot, cancellationToken);
        await iprot.ReadMessageEndAsync(cancellationToken);
        var result = new InternalStructs.AsyncProcessorResult();
        try
        {
          result.Success = await _iAsync.AsyncProcessorAsync(args.Foo, cancellationToken);
          await oprot.WriteMessageBeginAsync(new TMessage("AsyncProcessorAsync", TMessageType.Reply, seqid), cancellationToken); 
          await result.WriteAsync(oprot, cancellationToken);
        }
        catch (TTransportException)
        {
          throw;
        }
        catch (Exception ex)
        {
          var sErr = $"Error occurred in {GetType().FullName}: {ex.Message}";
          if(_logger != null)
            _logger.LogError(ex, sErr);
          else
            Console.Error.WriteLine(sErr);
          var x = new TApplicationException(TApplicationException.ExceptionType.InternalError," Internal error.");
          await oprot.WriteMessageBeginAsync(new TMessage("AsyncProcessorAsync", TMessageType.Exception, seqid), cancellationToken);
          await x.WriteAsync(oprot, cancellationToken);
        }
        await oprot.WriteMessageEndAsync(cancellationToken);
        await oprot.Transport.FlushAsync(cancellationToken);
      }

      public async global::System.Threading.Tasks.Task Client_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
      {
        var args = new InternalStructs.ClientArgs();
        await args.ReadAsync(iprot, cancellationToken);
        await iprot.ReadMessageEndAsync(cancellationToken);
        var result = new InternalStructs.ClientResult();
        try
        {
          result.Success = await _iAsync.ClientAsync(args.Foo, cancellationToken);
          await oprot.WriteMessageBeginAsync(new TMessage("Client", TMessageType.Reply, seqid), cancellationToken); 
          await result.WriteAsync(oprot, cancellationToken);
        }
        catch (TTransportException)
        {
          throw;
        }
        catch (Exception ex)
        {
          var sErr = $"Error occurred in {GetType().FullName}: {ex.Message}";
          if(_logger != null)
            _logger.LogError(ex, sErr);
          else
            Console.Error.WriteLine(sErr);
          var x = new TApplicationException(TApplicationException.ExceptionType.InternalError," Internal error.");
          await oprot.WriteMessageBeginAsync(new TMessage("Client", TMessageType.Exception, seqid), cancellationToken);
          await x.WriteAsync(oprot, cancellationToken);
        }
        await oprot.WriteMessageEndAsync(cancellationToken);
        await oprot.Transport.FlushAsync(cancellationToken);
      }

      public async global::System.Threading.Tasks.Task IAsync_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
      {
        var args = new InternalStructs.IAsyncArgs();
        await args.ReadAsync(iprot, cancellationToken);
        await iprot.ReadMessageEndAsync(cancellationToken);
        var result = new InternalStructs.IAsyncResult();
        try
        {
          result.Success = await _iAsync.IAsyncAsync(args.Foo, cancellationToken);
          await oprot.WriteMessageBeginAsync(new TMessage("IAsyncAsync", TMessageType.Reply, seqid), cancellationToken); 
          await result.WriteAsync(oprot, cancellationToken);
        }
        catch (TTransportException)
        {
          throw;
        }
        catch (Exception ex)
        {
          var sErr = $"Error occurred in {GetType().FullName}: {ex.Message}";
          if(_logger != null)
            _logger.LogError(ex, sErr);
          else
            Console.Error.WriteLine(sErr);
          var x = new TApplicationException(TApplicationException.ExceptionType.InternalError," Internal error.");
          await oprot.WriteMessageBeginAsync(new TMessage("IAsyncAsync", TMessageType.Exception, seqid), cancellationToken);
          await x.WriteAsync(oprot, cancellationToken);
        }
        await oprot.WriteMessageEndAsync(cancellationToken);
        await oprot.Transport.FlushAsync(cancellationToken);
      }

    }

    public class InternalStructs
    {

      [DataContract(Namespace="")]
      public partial class BrokenArgs : TBase
      {
        private global::Thrift5253.BrokenArgs _foo;

        [DataMember(Order = 0)]
        public global::Thrift5253.BrokenArgs Foo
        {
          get
          {
            return _foo;
          }
          set
          {
            __isset.foo = true;
            this._foo = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool foo;
        }

        #region XmlSerializer support

        public bool ShouldSerializeFoo()
        {
          return __isset.foo;
        }

        #endregion XmlSerializer support

        public BrokenArgs()
        {
        }

        public BrokenArgs DeepCopy()
        {
          var tmp18 = new BrokenArgs();
          if((Foo != null) && __isset.foo)
          {
            tmp18.Foo = (global::Thrift5253.BrokenArgs)this.Foo.DeepCopy();
          }
          tmp18.__isset.foo = this.__isset.foo;
          return tmp18;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 1:
                  if (field.Type == TType.Struct)
                  {
                    Foo = new global::Thrift5253.BrokenArgs();
                    await Foo.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("Broken_args");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();
            if((Foo != null) && __isset.foo)
            {
              field.Name = "foo";
              field.Type = TType.Struct;
              field.ID = 1;
              await oprot.WriteFieldBeginAsync(field, cancellationToken);
              await Foo.WriteAsync(oprot, cancellationToken);
              await oprot.WriteFieldEndAsync(cancellationToken);
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is BrokenArgs other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.foo == other.__isset.foo) && ((!__isset.foo) || (System.Object.Equals(Foo, other.Foo))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Foo != null) && __isset.foo)
            {
              hashcode = (hashcode * 397) + Foo.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("Broken_args(");
          int tmp19 = 0;
          if((Foo != null) && __isset.foo)
          {
            if(0 < tmp19++) { sb.Append(", "); }
            sb.Append("Foo: ");
            Foo.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class BrokenResult : TBase
      {
        private global::Thrift5253.BrokenResult _success;

        [DataMember(Order = 0)]
        public global::Thrift5253.BrokenResult Success
        {
          get
          {
            return _success;
          }
          set
          {
            __isset.success = true;
            this._success = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool success;
        }

        #region XmlSerializer support

        public bool ShouldSerializeSuccess()
        {
          return __isset.success;
        }

        #endregion XmlSerializer support

        public BrokenResult()
        {
        }

        public BrokenResult DeepCopy()
        {
          var tmp20 = new BrokenResult();
          if((Success != null) && __isset.success)
          {
            tmp20.Success = (global::Thrift5253.BrokenResult)this.Success.DeepCopy();
          }
          tmp20.__isset.success = this.__isset.success;
          return tmp20;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 0:
                  if (field.Type == TType.Struct)
                  {
                    Success = new global::Thrift5253.BrokenResult();
                    await Success.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("Broken_result");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();

            if(this.__isset.success)
            {
              if (Success != null)
              {
                field.Name = "Success";
                field.Type = TType.Struct;
                field.ID = 0;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);
                await Success.WriteAsync(oprot, cancellationToken);
                await oprot.WriteFieldEndAsync(cancellationToken);
              }
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is BrokenResult other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.success == other.__isset.success) && ((!__isset.success) || (System.Object.Equals(Success, other.Success))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Success != null) && __isset.success)
            {
              hashcode = (hashcode * 397) + Success.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("Broken_result(");
          int tmp21 = 0;
          if((Success != null) && __isset.success)
          {
            if(0 < tmp21++) { sb.Append(", "); }
            sb.Append("Success: ");
            Success.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class WorksArgs : TBase
      {
        private global::Thrift5253.WorksArrrgs _foo;

        [DataMember(Order = 0)]
        public global::Thrift5253.WorksArrrgs Foo
        {
          get
          {
            return _foo;
          }
          set
          {
            __isset.foo = true;
            this._foo = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool foo;
        }

        #region XmlSerializer support

        public bool ShouldSerializeFoo()
        {
          return __isset.foo;
        }

        #endregion XmlSerializer support

        public WorksArgs()
        {
        }

        public WorksArgs DeepCopy()
        {
          var tmp22 = new WorksArgs();
          if((Foo != null) && __isset.foo)
          {
            tmp22.Foo = (global::Thrift5253.WorksArrrgs)this.Foo.DeepCopy();
          }
          tmp22.__isset.foo = this.__isset.foo;
          return tmp22;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 1:
                  if (field.Type == TType.Struct)
                  {
                    Foo = new global::Thrift5253.WorksArrrgs();
                    await Foo.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("Works_args");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();
            if((Foo != null) && __isset.foo)
            {
              field.Name = "foo";
              field.Type = TType.Struct;
              field.ID = 1;
              await oprot.WriteFieldBeginAsync(field, cancellationToken);
              await Foo.WriteAsync(oprot, cancellationToken);
              await oprot.WriteFieldEndAsync(cancellationToken);
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is WorksArgs other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.foo == other.__isset.foo) && ((!__isset.foo) || (System.Object.Equals(Foo, other.Foo))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Foo != null) && __isset.foo)
            {
              hashcode = (hashcode * 397) + Foo.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("Works_args(");
          int tmp23 = 0;
          if((Foo != null) && __isset.foo)
          {
            if(0 < tmp23++) { sb.Append(", "); }
            sb.Append("Foo: ");
            Foo.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class WorksResult : TBase
      {
        private global::Thrift5253.WorksRslt _success;

        [DataMember(Order = 0)]
        public global::Thrift5253.WorksRslt Success
        {
          get
          {
            return _success;
          }
          set
          {
            __isset.success = true;
            this._success = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool success;
        }

        #region XmlSerializer support

        public bool ShouldSerializeSuccess()
        {
          return __isset.success;
        }

        #endregion XmlSerializer support

        public WorksResult()
        {
        }

        public WorksResult DeepCopy()
        {
          var tmp24 = new WorksResult();
          if((Success != null) && __isset.success)
          {
            tmp24.Success = (global::Thrift5253.WorksRslt)this.Success.DeepCopy();
          }
          tmp24.__isset.success = this.__isset.success;
          return tmp24;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 0:
                  if (field.Type == TType.Struct)
                  {
                    Success = new global::Thrift5253.WorksRslt();
                    await Success.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("Works_result");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();

            if(this.__isset.success)
            {
              if (Success != null)
              {
                field.Name = "Success";
                field.Type = TType.Struct;
                field.ID = 0;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);
                await Success.WriteAsync(oprot, cancellationToken);
                await oprot.WriteFieldEndAsync(cancellationToken);
              }
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is WorksResult other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.success == other.__isset.success) && ((!__isset.success) || (System.Object.Equals(Success, other.Success))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Success != null) && __isset.success)
            {
              hashcode = (hashcode * 397) + Success.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("Works_result(");
          int tmp25 = 0;
          if((Success != null) && __isset.success)
          {
            if(0 < tmp25++) { sb.Append(", "); }
            sb.Append("Success: ");
            Success.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class InternalStructsArgs : TBase
      {
        private global::Thrift5253.InternalStructs _foo;

        [DataMember(Order = 0)]
        public global::Thrift5253.InternalStructs Foo
        {
          get
          {
            return _foo;
          }
          set
          {
            __isset.foo = true;
            this._foo = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool foo;
        }

        #region XmlSerializer support

        public bool ShouldSerializeFoo()
        {
          return __isset.foo;
        }

        #endregion XmlSerializer support

        public InternalStructsArgs()
        {
        }

        public InternalStructsArgs DeepCopy()
        {
          var tmp26 = new InternalStructsArgs();
          if((Foo != null) && __isset.foo)
          {
            tmp26.Foo = (global::Thrift5253.InternalStructs)this.Foo.DeepCopy();
          }
          tmp26.__isset.foo = this.__isset.foo;
          return tmp26;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 1:
                  if (field.Type == TType.Struct)
                  {
                    Foo = new global::Thrift5253.InternalStructs();
                    await Foo.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("InternalStructs_args");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();
            if((Foo != null) && __isset.foo)
            {
              field.Name = "foo";
              field.Type = TType.Struct;
              field.ID = 1;
              await oprot.WriteFieldBeginAsync(field, cancellationToken);
              await Foo.WriteAsync(oprot, cancellationToken);
              await oprot.WriteFieldEndAsync(cancellationToken);
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is InternalStructsArgs other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.foo == other.__isset.foo) && ((!__isset.foo) || (System.Object.Equals(Foo, other.Foo))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Foo != null) && __isset.foo)
            {
              hashcode = (hashcode * 397) + Foo.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("InternalStructs_args(");
          int tmp27 = 0;
          if((Foo != null) && __isset.foo)
          {
            if(0 < tmp27++) { sb.Append(", "); }
            sb.Append("Foo: ");
            Foo.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class InternalStructsResult : TBase
      {
        private global::Thrift5253.InternalStructs _success;

        [DataMember(Order = 0)]
        public global::Thrift5253.InternalStructs Success
        {
          get
          {
            return _success;
          }
          set
          {
            __isset.success = true;
            this._success = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool success;
        }

        #region XmlSerializer support

        public bool ShouldSerializeSuccess()
        {
          return __isset.success;
        }

        #endregion XmlSerializer support

        public InternalStructsResult()
        {
        }

        public InternalStructsResult DeepCopy()
        {
          var tmp28 = new InternalStructsResult();
          if((Success != null) && __isset.success)
          {
            tmp28.Success = (global::Thrift5253.InternalStructs)this.Success.DeepCopy();
          }
          tmp28.__isset.success = this.__isset.success;
          return tmp28;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 0:
                  if (field.Type == TType.Struct)
                  {
                    Success = new global::Thrift5253.InternalStructs();
                    await Success.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("InternalStructs_result");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();

            if(this.__isset.success)
            {
              if (Success != null)
              {
                field.Name = "Success";
                field.Type = TType.Struct;
                field.ID = 0;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);
                await Success.WriteAsync(oprot, cancellationToken);
                await oprot.WriteFieldEndAsync(cancellationToken);
              }
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is InternalStructsResult other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.success == other.__isset.success) && ((!__isset.success) || (System.Object.Equals(Success, other.Success))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Success != null) && __isset.success)
            {
              hashcode = (hashcode * 397) + Success.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("InternalStructs_result(");
          int tmp29 = 0;
          if((Success != null) && __isset.success)
          {
            if(0 < tmp29++) { sb.Append(", "); }
            sb.Append("Success: ");
            Success.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class AsyncProcessorArgs : TBase
      {
        private global::Thrift5253.AsyncProcessor _foo;

        [DataMember(Order = 0)]
        public global::Thrift5253.AsyncProcessor Foo
        {
          get
          {
            return _foo;
          }
          set
          {
            __isset.foo = true;
            this._foo = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool foo;
        }

        #region XmlSerializer support

        public bool ShouldSerializeFoo()
        {
          return __isset.foo;
        }

        #endregion XmlSerializer support

        public AsyncProcessorArgs()
        {
        }

        public AsyncProcessorArgs DeepCopy()
        {
          var tmp30 = new AsyncProcessorArgs();
          if((Foo != null) && __isset.foo)
          {
            tmp30.Foo = (global::Thrift5253.AsyncProcessor)this.Foo.DeepCopy();
          }
          tmp30.__isset.foo = this.__isset.foo;
          return tmp30;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 1:
                  if (field.Type == TType.Struct)
                  {
                    Foo = new global::Thrift5253.AsyncProcessor();
                    await Foo.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("AsyncProcessor_args");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();
            if((Foo != null) && __isset.foo)
            {
              field.Name = "foo";
              field.Type = TType.Struct;
              field.ID = 1;
              await oprot.WriteFieldBeginAsync(field, cancellationToken);
              await Foo.WriteAsync(oprot, cancellationToken);
              await oprot.WriteFieldEndAsync(cancellationToken);
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is AsyncProcessorArgs other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.foo == other.__isset.foo) && ((!__isset.foo) || (System.Object.Equals(Foo, other.Foo))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Foo != null) && __isset.foo)
            {
              hashcode = (hashcode * 397) + Foo.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("AsyncProcessor_args(");
          int tmp31 = 0;
          if((Foo != null) && __isset.foo)
          {
            if(0 < tmp31++) { sb.Append(", "); }
            sb.Append("Foo: ");
            Foo.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class AsyncProcessorResult : TBase
      {
        private global::Thrift5253.AsyncProcessor _success;

        [DataMember(Order = 0)]
        public global::Thrift5253.AsyncProcessor Success
        {
          get
          {
            return _success;
          }
          set
          {
            __isset.success = true;
            this._success = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool success;
        }

        #region XmlSerializer support

        public bool ShouldSerializeSuccess()
        {
          return __isset.success;
        }

        #endregion XmlSerializer support

        public AsyncProcessorResult()
        {
        }

        public AsyncProcessorResult DeepCopy()
        {
          var tmp32 = new AsyncProcessorResult();
          if((Success != null) && __isset.success)
          {
            tmp32.Success = (global::Thrift5253.AsyncProcessor)this.Success.DeepCopy();
          }
          tmp32.__isset.success = this.__isset.success;
          return tmp32;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 0:
                  if (field.Type == TType.Struct)
                  {
                    Success = new global::Thrift5253.AsyncProcessor();
                    await Success.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("AsyncProcessor_result");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();

            if(this.__isset.success)
            {
              if (Success != null)
              {
                field.Name = "Success";
                field.Type = TType.Struct;
                field.ID = 0;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);
                await Success.WriteAsync(oprot, cancellationToken);
                await oprot.WriteFieldEndAsync(cancellationToken);
              }
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is AsyncProcessorResult other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.success == other.__isset.success) && ((!__isset.success) || (System.Object.Equals(Success, other.Success))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Success != null) && __isset.success)
            {
              hashcode = (hashcode * 397) + Success.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("AsyncProcessor_result(");
          int tmp33 = 0;
          if((Success != null) && __isset.success)
          {
            if(0 < tmp33++) { sb.Append(", "); }
            sb.Append("Success: ");
            Success.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class ClientArgs : TBase
      {
        private global::Thrift5253.Client _foo;

        [DataMember(Order = 0)]
        public global::Thrift5253.Client Foo
        {
          get
          {
            return _foo;
          }
          set
          {
            __isset.foo = true;
            this._foo = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool foo;
        }

        #region XmlSerializer support

        public bool ShouldSerializeFoo()
        {
          return __isset.foo;
        }

        #endregion XmlSerializer support

        public ClientArgs()
        {
        }

        public ClientArgs DeepCopy()
        {
          var tmp34 = new ClientArgs();
          if((Foo != null) && __isset.foo)
          {
            tmp34.Foo = (global::Thrift5253.Client)this.Foo.DeepCopy();
          }
          tmp34.__isset.foo = this.__isset.foo;
          return tmp34;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 1:
                  if (field.Type == TType.Struct)
                  {
                    Foo = new global::Thrift5253.Client();
                    await Foo.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("Client_args");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();
            if((Foo != null) && __isset.foo)
            {
              field.Name = "foo";
              field.Type = TType.Struct;
              field.ID = 1;
              await oprot.WriteFieldBeginAsync(field, cancellationToken);
              await Foo.WriteAsync(oprot, cancellationToken);
              await oprot.WriteFieldEndAsync(cancellationToken);
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is ClientArgs other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.foo == other.__isset.foo) && ((!__isset.foo) || (System.Object.Equals(Foo, other.Foo))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Foo != null) && __isset.foo)
            {
              hashcode = (hashcode * 397) + Foo.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("Client_args(");
          int tmp35 = 0;
          if((Foo != null) && __isset.foo)
          {
            if(0 < tmp35++) { sb.Append(", "); }
            sb.Append("Foo: ");
            Foo.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class ClientResult : TBase
      {
        private global::Thrift5253.Client _success;

        [DataMember(Order = 0)]
        public global::Thrift5253.Client Success
        {
          get
          {
            return _success;
          }
          set
          {
            __isset.success = true;
            this._success = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool success;
        }

        #region XmlSerializer support

        public bool ShouldSerializeSuccess()
        {
          return __isset.success;
        }

        #endregion XmlSerializer support

        public ClientResult()
        {
        }

        public ClientResult DeepCopy()
        {
          var tmp36 = new ClientResult();
          if((Success != null) && __isset.success)
          {
            tmp36.Success = (global::Thrift5253.Client)this.Success.DeepCopy();
          }
          tmp36.__isset.success = this.__isset.success;
          return tmp36;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 0:
                  if (field.Type == TType.Struct)
                  {
                    Success = new global::Thrift5253.Client();
                    await Success.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("Client_result");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();

            if(this.__isset.success)
            {
              if (Success != null)
              {
                field.Name = "Success";
                field.Type = TType.Struct;
                field.ID = 0;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);
                await Success.WriteAsync(oprot, cancellationToken);
                await oprot.WriteFieldEndAsync(cancellationToken);
              }
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is ClientResult other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.success == other.__isset.success) && ((!__isset.success) || (System.Object.Equals(Success, other.Success))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Success != null) && __isset.success)
            {
              hashcode = (hashcode * 397) + Success.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("Client_result(");
          int tmp37 = 0;
          if((Success != null) && __isset.success)
          {
            if(0 < tmp37++) { sb.Append(", "); }
            sb.Append("Success: ");
            Success.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class IAsyncArgs : TBase
      {
        private global::Thrift5253.IAsync _foo;

        [DataMember(Order = 0)]
        public global::Thrift5253.IAsync Foo
        {
          get
          {
            return _foo;
          }
          set
          {
            __isset.foo = true;
            this._foo = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool foo;
        }

        #region XmlSerializer support

        public bool ShouldSerializeFoo()
        {
          return __isset.foo;
        }

        #endregion XmlSerializer support

        public IAsyncArgs()
        {
        }

        public IAsyncArgs DeepCopy()
        {
          var tmp38 = new IAsyncArgs();
          if((Foo != null) && __isset.foo)
          {
            tmp38.Foo = (global::Thrift5253.IAsync)this.Foo.DeepCopy();
          }
          tmp38.__isset.foo = this.__isset.foo;
          return tmp38;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 1:
                  if (field.Type == TType.Struct)
                  {
                    Foo = new global::Thrift5253.IAsync();
                    await Foo.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("IAsync_args");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();
            if((Foo != null) && __isset.foo)
            {
              field.Name = "foo";
              field.Type = TType.Struct;
              field.ID = 1;
              await oprot.WriteFieldBeginAsync(field, cancellationToken);
              await Foo.WriteAsync(oprot, cancellationToken);
              await oprot.WriteFieldEndAsync(cancellationToken);
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is IAsyncArgs other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.foo == other.__isset.foo) && ((!__isset.foo) || (System.Object.Equals(Foo, other.Foo))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Foo != null) && __isset.foo)
            {
              hashcode = (hashcode * 397) + Foo.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("IAsync_args(");
          int tmp39 = 0;
          if((Foo != null) && __isset.foo)
          {
            if(0 < tmp39++) { sb.Append(", "); }
            sb.Append("Foo: ");
            Foo.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }


      [DataContract(Namespace="")]
      public partial class IAsyncResult : TBase
      {
        private global::Thrift5253.IAsync _success;

        [DataMember(Order = 0)]
        public global::Thrift5253.IAsync Success
        {
          get
          {
            return _success;
          }
          set
          {
            __isset.success = true;
            this._success = value;
          }
        }


        [DataMember(Order = 1)]
        public Isset __isset;
        [DataContract]
        public struct Isset
        {
          [DataMember]
          public bool success;
        }

        #region XmlSerializer support

        public bool ShouldSerializeSuccess()
        {
          return __isset.success;
        }

        #endregion XmlSerializer support

        public IAsyncResult()
        {
        }

        public IAsyncResult DeepCopy()
        {
          var tmp40 = new IAsyncResult();
          if((Success != null) && __isset.success)
          {
            tmp40.Success = (global::Thrift5253.IAsync)this.Success.DeepCopy();
          }
          tmp40.__isset.success = this.__isset.success;
          return tmp40;
        }

        public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
        {
          iprot.IncrementRecursionDepth();
          try
          {
            TField field;
            await iprot.ReadStructBeginAsync(cancellationToken);
            while (true)
            {
              field = await iprot.ReadFieldBeginAsync(cancellationToken);
              if (field.Type == TType.Stop)
              {
                break;
              }

              switch (field.ID)
              {
                case 0:
                  if (field.Type == TType.Struct)
                  {
                    Success = new global::Thrift5253.IAsync();
                    await Success.ReadAsync(iprot, cancellationToken);
                  }
                  else
                  {
                    await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  }
                  break;
                default: 
                  await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
                  break;
              }

              await iprot.ReadFieldEndAsync(cancellationToken);
            }

            await iprot.ReadStructEndAsync(cancellationToken);
          }
          finally
          {
            iprot.DecrementRecursionDepth();
          }
        }

        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
          oprot.IncrementRecursionDepth();
          try
          {
            var struc = new TStruct("IAsync_result");
            await oprot.WriteStructBeginAsync(struc, cancellationToken);
            var field = new TField();

            if(this.__isset.success)
            {
              if (Success != null)
              {
                field.Name = "Success";
                field.Type = TType.Struct;
                field.ID = 0;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);
                await Success.WriteAsync(oprot, cancellationToken);
                await oprot.WriteFieldEndAsync(cancellationToken);
              }
            }
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
          }
          finally
          {
            oprot.DecrementRecursionDepth();
          }
        }

        public override bool Equals(object that)
        {
          if (!(that is IAsyncResult other)) return false;
          if (ReferenceEquals(this, other)) return true;
          return ((__isset.success == other.__isset.success) && ((!__isset.success) || (System.Object.Equals(Success, other.Success))));
        }

        public override int GetHashCode() {
          int hashcode = 157;
          unchecked {
            if((Success != null) && __isset.success)
            {
              hashcode = (hashcode * 397) + Success.GetHashCode();
            }
          }
          return hashcode;
        }

        public override string ToString()
        {
          var sb = new StringBuilder("IAsync_result(");
          int tmp41 = 0;
          if((Success != null) && __isset.success)
          {
            if(0 < tmp41++) { sb.Append(", "); }
            sb.Append("Success: ");
            Success.ToString(sb);
          }
          sb.Append(')');
          return sb.ToString();
        }
      }

    }

  }
}
