<?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 Task
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'taskId',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        2 => array(
            'var' => 'taskType',
            'isRequired' => false,
            'type' => TType::I32,
            'class' => '\TaskType',
        ),
        3 => array(
            'var' => 'taskAttributes',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::STRING,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::STRING,
                ),
        ),
        4 => array(
            'var' => 'taskCounters',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::I64,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::I64,
                ),
        ),
        5 => array(
            'var' => 'operatorGraph',
            'isRequired' => false,
            'type' => TType::STRUCT,
            'class' => '\Graph',
        ),
        6 => array(
            'var' => 'operatorList',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\Operator',
                ),
        ),
        7 => array(
            'var' => 'done',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
        8 => array(
            'var' => 'started',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
    );

    /**
     * @var string
     */
    public $taskId = null;
    /**
     * @var int
     */
    public $taskType = null;
    /**
     * @var array
     */
    public $taskAttributes = null;
    /**
     * @var array
     */
    public $taskCounters = null;
    /**
     * @var \Graph
     */
    public $operatorGraph = null;
    /**
     * @var \Operator[]
     */
    public $operatorList = null;
    /**
     * @var bool
     */
    public $done = null;
    /**
     * @var bool
     */
    public $started = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['taskId'])) {
                $this->taskId = $vals['taskId'];
            }
            if (isset($vals['taskType'])) {
                $this->taskType = $vals['taskType'];
            }
            if (isset($vals['taskAttributes'])) {
                $this->taskAttributes = $vals['taskAttributes'];
            }
            if (isset($vals['taskCounters'])) {
                $this->taskCounters = $vals['taskCounters'];
            }
            if (isset($vals['operatorGraph'])) {
                $this->operatorGraph = $vals['operatorGraph'];
            }
            if (isset($vals['operatorList'])) {
                $this->operatorList = $vals['operatorList'];
            }
            if (isset($vals['done'])) {
                $this->done = $vals['done'];
            }
            if (isset($vals['started'])) {
                $this->started = $vals['started'];
            }
        }
    }

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


    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::STRING) {
                        $xfer += $input->readString($this->taskId);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->taskType);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::MAP) {
                        $this->taskAttributes = array();
                        $_size39 = 0;
                        $_ktype40 = 0;
                        $_vtype41 = 0;
                        $xfer += $input->readMapBegin($_ktype40, $_vtype41, $_size39);
                        for ($_i43 = 0; $_i43 < $_size39; ++$_i43) {
                            $key44 = '';
                            $val45 = '';
                            $xfer += $input->readString($key44);
                            $xfer += $input->readString($val45);
                            $this->taskAttributes[$key44] = $val45;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 4:
                    if ($ftype == TType::MAP) {
                        $this->taskCounters = array();
                        $_size46 = 0;
                        $_ktype47 = 0;
                        $_vtype48 = 0;
                        $xfer += $input->readMapBegin($_ktype47, $_vtype48, $_size46);
                        for ($_i50 = 0; $_i50 < $_size46; ++$_i50) {
                            $key51 = '';
                            $val52 = 0;
                            $xfer += $input->readString($key51);
                            $xfer += $input->readI64($val52);
                            $this->taskCounters[$key51] = $val52;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 5:
                    if ($ftype == TType::STRUCT) {
                        $this->operatorGraph = new \Graph();
                        $xfer += $this->operatorGraph->read($input);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 6:
                    if ($ftype == TType::LST) {
                        $this->operatorList = array();
                        $_size53 = 0;
                        $_etype56 = 0;
                        $xfer += $input->readListBegin($_etype56, $_size53);
                        for ($_i57 = 0; $_i57 < $_size53; ++$_i57) {
                            $elem58 = null;
                            $elem58 = new \Operator();
                            $xfer += $elem58->read($input);
                            $this->operatorList []= $elem58;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 7:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->done);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 8:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->started);
                    } 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('Task');
        if ($this->taskId !== null) {
            $xfer += $output->writeFieldBegin('taskId', TType::STRING, 1);
            $xfer += $output->writeString($this->taskId);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->taskType !== null) {
            $xfer += $output->writeFieldBegin('taskType', TType::I32, 2);
            $xfer += $output->writeI32($this->taskType);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->taskAttributes !== null) {
            if (!is_array($this->taskAttributes)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('taskAttributes', TType::MAP, 3);
            $output->writeMapBegin(TType::STRING, TType::STRING, count($this->taskAttributes));
            foreach ($this->taskAttributes as $kiter59 => $viter60) {
                $xfer += $output->writeString($kiter59);
                $xfer += $output->writeString($viter60);
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->taskCounters !== null) {
            if (!is_array($this->taskCounters)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('taskCounters', TType::MAP, 4);
            $output->writeMapBegin(TType::STRING, TType::I64, count($this->taskCounters));
            foreach ($this->taskCounters as $kiter61 => $viter62) {
                $xfer += $output->writeString($kiter61);
                $xfer += $output->writeI64($viter62);
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->operatorGraph !== null) {
            if (!is_object($this->operatorGraph)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('operatorGraph', TType::STRUCT, 5);
            $xfer += $this->operatorGraph->write($output);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->operatorList !== null) {
            if (!is_array($this->operatorList)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('operatorList', TType::LST, 6);
            $output->writeListBegin(TType::STRUCT, count($this->operatorList));
            foreach ($this->operatorList as $iter63) {
                $xfer += $iter63->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->done !== null) {
            $xfer += $output->writeFieldBegin('done', TType::BOOL, 7);
            $xfer += $output->writeBool($this->done);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->started !== null) {
            $xfer += $output->writeFieldBegin('started', TType::BOOL, 8);
            $xfer += $output->writeBool($this->started);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
