#
# Autogenerated by Thrift Compiler (0.12.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
use 5.10.0;
use strict;
use warnings;
use Thrift::Exception;
use Thrift::MessageType;
use Thrift::Type;

use ThriftTest::Types;


# HELPER FUNCTIONS AND STRUCTURES

package ThriftTest::SecondService_secondtestString_args;
use base qw(Class::Accessor);
ThriftTest::SecondService_secondtestString_args->mk_accessors( qw( thing ) );

sub new {
    my $classname = shift;
    my $self      = {};
    my $vals      = shift || {};
    $self->{thing} = undef;
    if (UNIVERSAL::isa($vals,'HASH')) {
      if (defined $vals->{thing}) {
        $self->{thing} = $vals->{thing};
      }
    }
    return bless ($self, $classname);
}

sub getName {
    return 'SecondService_secondtestString_args';
  }

sub read {
    my ($self, $input) = @_;
    my $xfer  = 0;
    my $fname;
    my $ftype = 0;
    my $fid   = 0;
    $xfer += $input->readStructBegin(\$fname);
    while (1)
    {
      $xfer += $input->readFieldBegin(\$fname, \$ftype, \$fid);
      if ($ftype == Thrift::TType::STOP) {
        last;
      }
      SWITCH: for($fid)
      {
        /^1$/ && do{        if ($ftype == Thrift::TType::STRING) {
          $xfer += $input->readString(\$self->{thing});
        } else {
          $xfer += $input->skip($ftype);
        }
        last; };
          $xfer += $input->skip($ftype);
      }
      $xfer += $input->readFieldEnd();
    }
    $xfer += $input->readStructEnd();
    return $xfer;
  }

sub write {
    my ($self, $output) = @_;
    my $xfer   = 0;
    $xfer += $output->writeStructBegin('SecondService_secondtestString_args');
    if (defined $self->{thing}) {
      $xfer += $output->writeFieldBegin('thing', Thrift::TType::STRING, 1);
      $xfer += $output->writeString($self->{thing});
      $xfer += $output->writeFieldEnd();
    }
    $xfer += $output->writeFieldStop();
    $xfer += $output->writeStructEnd();
    return $xfer;
  }

package ThriftTest::SecondService_secondtestString_result;
use base qw(Class::Accessor);
ThriftTest::SecondService_secondtestString_result->mk_accessors( qw( success ) );

sub new {
    my $classname = shift;
    my $self      = {};
    my $vals      = shift || {};
    $self->{success} = undef;
    if (UNIVERSAL::isa($vals,'HASH')) {
      if (defined $vals->{success}) {
        $self->{success} = $vals->{success};
      }
    }
    return bless ($self, $classname);
}

sub getName {
    return 'SecondService_secondtestString_result';
  }

sub read {
    my ($self, $input) = @_;
    my $xfer  = 0;
    my $fname;
    my $ftype = 0;
    my $fid   = 0;
    $xfer += $input->readStructBegin(\$fname);
    while (1)
    {
      $xfer += $input->readFieldBegin(\$fname, \$ftype, \$fid);
      if ($ftype == Thrift::TType::STOP) {
        last;
      }
      SWITCH: for($fid)
      {
        /^0$/ && do{        if ($ftype == Thrift::TType::STRING) {
          $xfer += $input->readString(\$self->{success});
        } else {
          $xfer += $input->skip($ftype);
        }
        last; };
          $xfer += $input->skip($ftype);
      }
      $xfer += $input->readFieldEnd();
    }
    $xfer += $input->readStructEnd();
    return $xfer;
  }

sub write {
    my ($self, $output) = @_;
    my $xfer   = 0;
    $xfer += $output->writeStructBegin('SecondService_secondtestString_result');
    if (defined $self->{success}) {
      $xfer += $output->writeFieldBegin('success', Thrift::TType::STRING, 0);
      $xfer += $output->writeString($self->{success});
      $xfer += $output->writeFieldEnd();
    }
    $xfer += $output->writeFieldStop();
    $xfer += $output->writeStructEnd();
    return $xfer;
  }

package ThriftTest::SecondServiceIf;

use strict;


sub secondtestString{
  my $self = shift;
  my $thing = shift;

  die 'implement interface';
}

package ThriftTest::SecondServiceRest;

use strict;


sub new {
    my ($classname, $impl) = @_;
    my $self     ={ impl => $impl };

    return bless($self,$classname);
}

sub secondtestString{
    my ($self, $request) = @_;

    my $thing = ($request->{'thing'}) ? $request->{'thing'} : undef;
    return $self->{impl}->secondtestString($thing);
  }

package ThriftTest::SecondServiceClient;


use base qw(ThriftTest::SecondServiceIf);
sub new {
    my ($classname, $input, $output) = @_;
    my $self      = {};
    $self->{input}  = $input;
    $self->{output} = defined $output ? $output : $input;
    $self->{seqid}  = 0;
    return bless($self,$classname);
}

sub secondtestString{
  my $self = shift;
  my $thing = shift;

        $self->send_secondtestString($thing);
    return $self->recv_secondtestString();
}

sub send_secondtestString{
  my $self = shift;
  my $thing = shift;

    $self->{output}->writeMessageBegin('secondtestString', Thrift::TMessageType::CALL, $self->{seqid});
    my $args = ThriftTest::SecondService_secondtestString_args->new();
    $args->{thing} = $thing;
    $args->write($self->{output});
    $self->{output}->writeMessageEnd();
    $self->{output}->getTransport()->flush();
}

sub recv_secondtestString{
  my $self = shift;

    my $rseqid = 0;
    my $fname;
    my $mtype = 0;

    $self->{input}->readMessageBegin(\$fname, \$mtype, \$rseqid);
    if ($mtype == Thrift::TMessageType::EXCEPTION) {
      my $x = Thrift::TApplicationException->new();
      $x->read($self->{input});
      $self->{input}->readMessageEnd();
      die $x;
    }
    my $result = ThriftTest::SecondService_secondtestString_result->new();
    $result->read($self->{input});
    $self->{input}->readMessageEnd();

    if (defined $result->{success} ) {
      return $result->{success};
    }
    die "secondtestString failed: unknown result";
}
package ThriftTest::SecondServiceProcessor;

use strict;


sub new {
      my ($classname, $handler) = @_;
      my $self      = {};
      $self->{handler} = $handler;
      return bless ($self, $classname);
}

sub process {
      my ($self, $input, $output) = @_;
      my $rseqid = 0;
      my $fname  = undef;
      my $mtype  = 0;

      $input->readMessageBegin(\$fname, \$mtype, \$rseqid);
      my $methodname = 'process_'.$fname;
      if (!$self->can($methodname)) {
        $input->skip(Thrift::TType::STRUCT);
        $input->readMessageEnd();
        my $x = Thrift::TApplicationException->new('Function '.$fname.' not implemented.', Thrift::TApplicationException::UNKNOWN_METHOD);
        $output->writeMessageBegin($fname, Thrift::TMessageType::EXCEPTION, $rseqid);
        $x->write($output);
        $output->writeMessageEnd();
        $output->getTransport()->flush();
        return;
      }
      $self->$methodname($rseqid, $input, $output);
      return 1;
}

sub process_secondtestString {
      my ($self, $seqid, $input, $output) = @_;
      my $args = ThriftTest::SecondService_secondtestString_args->new();
      $args->read($input);
      $input->readMessageEnd();
      my $result = ThriftTest::SecondService_secondtestString_result->new();
      $result->{success} = $self->{handler}->secondtestString($args->thing);
      $output->writeMessageBegin('secondtestString', Thrift::TMessageType::REPLY, $seqid);
      $result->write($output);
      $output->writeMessageEnd();
      $output->getTransport()->flush();
}

1;
