<?php
/**
 * Autogenerated by Thrift Compiler (0.16.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
use Thrift\Base\TBase;
use Thrift\Type\TType;
use Thrift\Type\TMessageType;
use Thrift\Exception\TException;
use Thrift\Exception\TProtocolException;
use Thrift\Protocol\TProtocol;
use Thrift\Protocol\TBinaryProtocolAccelerated;
use Thrift\Exception\TApplicationException;

class Complex
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'aint',
            'isRequired' => false,
            'type' => TType::I32,
        ),
        2 => array(
            'var' => 'aString',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        3 => array(
            'var' => 'lint',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::I32,
            'elem' => array(
                'type' => TType::I32,
                ),
        ),
        4 => array(
            'var' => 'lString',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRING,
            'elem' => array(
                'type' => TType::STRING,
                ),
        ),
        5 => array(
            'var' => 'lintString',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\IntString',
                ),
        ),
        6 => array(
            'var' => 'mStringString',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::STRING,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::STRING,
                ),
        ),
        7 => array(
            'var' => 'attributes',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::MAP,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::MAP,
                'ktype' => TType::STRING,
                'vtype' => TType::MAP,
                'key' => array(
                    'type' => TType::STRING,
                ),
                'val' => array(
                    'type' => TType::MAP,
                    'ktype' => TType::STRING,
                    'vtype' => TType::STRUCT,
                    'key' => array(
                        'type' => TType::STRING,
                    ),
                    'val' => array(
                        'type' => TType::STRUCT,
                        'class' => '\PropValueUnion',
                        ),
                    ),
                ),
        ),
        8 => array(
            'var' => 'unionField1',
            'isRequired' => false,
            'type' => TType::STRUCT,
            'class' => '\PropValueUnion',
        ),
        9 => array(
            'var' => 'unionField2',
            'isRequired' => false,
            'type' => TType::STRUCT,
            'class' => '\PropValueUnion',
        ),
        10 => array(
            'var' => 'unionField3',
            'isRequired' => false,
            'type' => TType::STRUCT,
            'class' => '\PropValueUnion',
        ),
    );

    /**
     * @var int
     */
    public $aint = null;
    /**
     * @var string
     */
    public $aString = null;
    /**
     * @var int[]
     */
    public $lint = null;
    /**
     * @var string[]
     */
    public $lString = null;
    /**
     * @var \IntString[]
     */
    public $lintString = null;
    /**
     * @var array
     */
    public $mStringString = null;
    /**
     * @var array
     */
    public $attributes = null;
    /**
     * @var \PropValueUnion
     */
    public $unionField1 = null;
    /**
     * @var \PropValueUnion
     */
    public $unionField2 = null;
    /**
     * @var \PropValueUnion
     */
    public $unionField3 = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['aint'])) {
                $this->aint = $vals['aint'];
            }
            if (isset($vals['aString'])) {
                $this->aString = $vals['aString'];
            }
            if (isset($vals['lint'])) {
                $this->lint = $vals['lint'];
            }
            if (isset($vals['lString'])) {
                $this->lString = $vals['lString'];
            }
            if (isset($vals['lintString'])) {
                $this->lintString = $vals['lintString'];
            }
            if (isset($vals['mStringString'])) {
                $this->mStringString = $vals['mStringString'];
            }
            if (isset($vals['attributes'])) {
                $this->attributes = $vals['attributes'];
            }
            if (isset($vals['unionField1'])) {
                $this->unionField1 = $vals['unionField1'];
            }
            if (isset($vals['unionField2'])) {
                $this->unionField2 = $vals['unionField2'];
            }
            if (isset($vals['unionField3'])) {
                $this->unionField3 = $vals['unionField3'];
            }
        }
    }

    public function getName()
    {
        return 'Complex';
    }


    public function read($input)
    {
        $xfer = 0;
        $fname = null;
        $ftype = 0;
        $fid = 0;
        $xfer += $input->readStructBegin($fname);
        while (true) {
            $xfer += $input->readFieldBegin($fname, $ftype, $fid);
            if ($ftype == TType::STOP) {
                break;
            }
            switch ($fid) {
                case 1:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->aint);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->aString);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::LST) {
                        $this->lint = array();
                        $_size16 = 0;
                        $_etype19 = 0;
                        $xfer += $input->readListBegin($_etype19, $_size16);
                        for ($_i20 = 0; $_i20 < $_size16; ++$_i20) {
                            $elem21 = null;
                            $xfer += $input->readI32($elem21);
                            $this->lint []= $elem21;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 4:
                    if ($ftype == TType::LST) {
                        $this->lString = array();
                        $_size22 = 0;
                        $_etype25 = 0;
                        $xfer += $input->readListBegin($_etype25, $_size22);
                        for ($_i26 = 0; $_i26 < $_size22; ++$_i26) {
                            $elem27 = null;
                            $xfer += $input->readString($elem27);
                            $this->lString []= $elem27;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 5:
                    if ($ftype == TType::LST) {
                        $this->lintString = array();
                        $_size28 = 0;
                        $_etype31 = 0;
                        $xfer += $input->readListBegin($_etype31, $_size28);
                        for ($_i32 = 0; $_i32 < $_size28; ++$_i32) {
                            $elem33 = null;
                            $elem33 = new \IntString();
                            $xfer += $elem33->read($input);
                            $this->lintString []= $elem33;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 6:
                    if ($ftype == TType::MAP) {
                        $this->mStringString = array();
                        $_size34 = 0;
                        $_ktype35 = 0;
                        $_vtype36 = 0;
                        $xfer += $input->readMapBegin($_ktype35, $_vtype36, $_size34);
                        for ($_i38 = 0; $_i38 < $_size34; ++$_i38) {
                            $key39 = '';
                            $val40 = '';
                            $xfer += $input->readString($key39);
                            $xfer += $input->readString($val40);
                            $this->mStringString[$key39] = $val40;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 7:
                    if ($ftype == TType::MAP) {
                        $this->attributes = array();
                        $_size41 = 0;
                        $_ktype42 = 0;
                        $_vtype43 = 0;
                        $xfer += $input->readMapBegin($_ktype42, $_vtype43, $_size41);
                        for ($_i45 = 0; $_i45 < $_size41; ++$_i45) {
                            $key46 = '';
                            $val47 = array();
                            $xfer += $input->readString($key46);
                            $val47 = array();
                            $_size48 = 0;
                            $_ktype49 = 0;
                            $_vtype50 = 0;
                            $xfer += $input->readMapBegin($_ktype49, $_vtype50, $_size48);
                            for ($_i52 = 0; $_i52 < $_size48; ++$_i52) {
                                $key53 = '';
                                $val54 = array();
                                $xfer += $input->readString($key53);
                                $val54 = array();
                                $_size55 = 0;
                                $_ktype56 = 0;
                                $_vtype57 = 0;
                                $xfer += $input->readMapBegin($_ktype56, $_vtype57, $_size55);
                                for ($_i59 = 0; $_i59 < $_size55; ++$_i59) {
                                    $key60 = '';
                                    $val61 = new \PropValueUnion();
                                    $xfer += $input->readString($key60);
                                    $val61 = new \PropValueUnion();
                                    $xfer += $val61->read($input);
                                    $val54[$key60] = $val61;
                                }
                                $xfer += $input->readMapEnd();
                                $val47[$key53] = $val54;
                            }
                            $xfer += $input->readMapEnd();
                            $this->attributes[$key46] = $val47;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 8:
                    if ($ftype == TType::STRUCT) {
                        $this->unionField1 = new \PropValueUnion();
                        $xfer += $this->unionField1->read($input);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 9:
                    if ($ftype == TType::STRUCT) {
                        $this->unionField2 = new \PropValueUnion();
                        $xfer += $this->unionField2->read($input);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 10:
                    if ($ftype == TType::STRUCT) {
                        $this->unionField3 = new \PropValueUnion();
                        $xfer += $this->unionField3->read($input);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                default:
                    $xfer += $input->skip($ftype);
                    break;
            }
            $xfer += $input->readFieldEnd();
        }
        $xfer += $input->readStructEnd();
        return $xfer;
    }

    public function write($output)
    {
        $xfer = 0;
        $xfer += $output->writeStructBegin('Complex');
        if ($this->aint !== null) {
            $xfer += $output->writeFieldBegin('aint', TType::I32, 1);
            $xfer += $output->writeI32($this->aint);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->aString !== null) {
            $xfer += $output->writeFieldBegin('aString', TType::STRING, 2);
            $xfer += $output->writeString($this->aString);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->lint !== null) {
            if (!is_array($this->lint)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('lint', TType::LST, 3);
            $output->writeListBegin(TType::I32, count($this->lint));
            foreach ($this->lint as $iter62) {
                $xfer += $output->writeI32($iter62);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->lString !== null) {
            if (!is_array($this->lString)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('lString', TType::LST, 4);
            $output->writeListBegin(TType::STRING, count($this->lString));
            foreach ($this->lString as $iter63) {
                $xfer += $output->writeString($iter63);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->lintString !== null) {
            if (!is_array($this->lintString)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('lintString', TType::LST, 5);
            $output->writeListBegin(TType::STRUCT, count($this->lintString));
            foreach ($this->lintString as $iter64) {
                $xfer += $iter64->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->mStringString !== null) {
            if (!is_array($this->mStringString)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('mStringString', TType::MAP, 6);
            $output->writeMapBegin(TType::STRING, TType::STRING, count($this->mStringString));
            foreach ($this->mStringString as $kiter65 => $viter66) {
                $xfer += $output->writeString($kiter65);
                $xfer += $output->writeString($viter66);
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->attributes !== null) {
            if (!is_array($this->attributes)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('attributes', TType::MAP, 7);
            $output->writeMapBegin(TType::STRING, TType::MAP, count($this->attributes));
            foreach ($this->attributes as $kiter67 => $viter68) {
                $xfer += $output->writeString($kiter67);
                $output->writeMapBegin(TType::STRING, TType::MAP, count($viter68));
                foreach ($viter68 as $kiter69 => $viter70) {
                    $xfer += $output->writeString($kiter69);
                    $output->writeMapBegin(TType::STRING, TType::STRUCT, count($viter70));
                    foreach ($viter70 as $kiter71 => $viter72) {
                        $xfer += $output->writeString($kiter71);
                        $xfer += $viter72->write($output);
                    }
                    $output->writeMapEnd();
                }
                $output->writeMapEnd();
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->unionField1 !== null) {
            if (!is_object($this->unionField1)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('unionField1', TType::STRUCT, 8);
            $xfer += $this->unionField1->write($output);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->unionField2 !== null) {
            if (!is_object($this->unionField2)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('unionField2', TType::STRUCT, 9);
            $xfer += $this->unionField2->write($output);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->unionField3 !== null) {
            if (!is_object($this->unionField3)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('unionField3', TType::STRUCT, 10);
            $xfer += $this->unionField3->write($output);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
