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

    static public $_TSPEC = array(
        1 => array(
            'var' => 'operatorId',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        2 => array(
            'var' => 'operatorType',
            'isRequired' => false,
            'type' => TType::I32,
            'class' => '\OperatorType',
        ),
        3 => array(
            'var' => 'operatorAttributes',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::STRING,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::STRING,
                ),
        ),
        4 => array(
            'var' => 'operatorCounters',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::I64,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::I64,
                ),
        ),
        5 => array(
            'var' => 'done',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
        6 => array(
            'var' => 'started',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
    );

    /**
     * @var string
     */
    public $operatorId = null;
    /**
     * @var int
     */
    public $operatorType = null;
    /**
     * @var array
     */
    public $operatorAttributes = null;
    /**
     * @var array
     */
    public $operatorCounters = null;
    /**
     * @var bool
     */
    public $done = null;
    /**
     * @var bool
     */
    public $started = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['operatorId'])) {
                $this->operatorId = $vals['operatorId'];
            }
            if (isset($vals['operatorType'])) {
                $this->operatorType = $vals['operatorType'];
            }
            if (isset($vals['operatorAttributes'])) {
                $this->operatorAttributes = $vals['operatorAttributes'];
            }
            if (isset($vals['operatorCounters'])) {
                $this->operatorCounters = $vals['operatorCounters'];
            }
            if (isset($vals['done'])) {
                $this->done = $vals['done'];
            }
            if (isset($vals['started'])) {
                $this->started = $vals['started'];
            }
        }
    }

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


    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->operatorId);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->operatorType);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::MAP) {
                        $this->operatorAttributes = array();
                        $_size21 = 0;
                        $_ktype22 = 0;
                        $_vtype23 = 0;
                        $xfer += $input->readMapBegin($_ktype22, $_vtype23, $_size21);
                        for ($_i25 = 0; $_i25 < $_size21; ++$_i25) {
                            $key26 = '';
                            $val27 = '';
                            $xfer += $input->readString($key26);
                            $xfer += $input->readString($val27);
                            $this->operatorAttributes[$key26] = $val27;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 4:
                    if ($ftype == TType::MAP) {
                        $this->operatorCounters = array();
                        $_size28 = 0;
                        $_ktype29 = 0;
                        $_vtype30 = 0;
                        $xfer += $input->readMapBegin($_ktype29, $_vtype30, $_size28);
                        for ($_i32 = 0; $_i32 < $_size28; ++$_i32) {
                            $key33 = '';
                            $val34 = 0;
                            $xfer += $input->readString($key33);
                            $xfer += $input->readI64($val34);
                            $this->operatorCounters[$key33] = $val34;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 5:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->done);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 6:
                    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('Operator');
        if ($this->operatorId !== null) {
            $xfer += $output->writeFieldBegin('operatorId', TType::STRING, 1);
            $xfer += $output->writeString($this->operatorId);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->operatorType !== null) {
            $xfer += $output->writeFieldBegin('operatorType', TType::I32, 2);
            $xfer += $output->writeI32($this->operatorType);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->operatorAttributes !== null) {
            if (!is_array($this->operatorAttributes)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('operatorAttributes', TType::MAP, 3);
            $output->writeMapBegin(TType::STRING, TType::STRING, count($this->operatorAttributes));
            foreach ($this->operatorAttributes as $kiter35 => $viter36) {
                $xfer += $output->writeString($kiter35);
                $xfer += $output->writeString($viter36);
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->operatorCounters !== null) {
            if (!is_array($this->operatorCounters)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('operatorCounters', TType::MAP, 4);
            $output->writeMapBegin(TType::STRING, TType::I64, count($this->operatorCounters));
            foreach ($this->operatorCounters as $kiter37 => $viter38) {
                $xfer += $output->writeString($kiter37);
                $xfer += $output->writeI64($viter38);
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->done !== null) {
            $xfer += $output->writeFieldBegin('done', TType::BOOL, 5);
            $xfer += $output->writeBool($this->done);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->started !== null) {
            $xfer += $output->writeFieldBegin('started', TType::BOOL, 6);
            $xfer += $output->writeBool($this->started);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
