<?php
namespace metastore;

/**
 * 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 GetOpenTxnsInfoResponse
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'txn_high_water_mark',
            'isRequired' => true,
            'type' => TType::I64,
        ),
        2 => array(
            'var' => 'open_txns',
            'isRequired' => true,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\metastore\TxnInfo',
                ),
        ),
    );

    /**
     * @var int
     */
    public $txn_high_water_mark = null;
    /**
     * @var \metastore\TxnInfo[]
     */
    public $open_txns = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['txn_high_water_mark'])) {
                $this->txn_high_water_mark = $vals['txn_high_water_mark'];
            }
            if (isset($vals['open_txns'])) {
                $this->open_txns = $vals['open_txns'];
            }
        }
    }

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


    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::I64) {
                        $xfer += $input->readI64($this->txn_high_water_mark);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::LST) {
                        $this->open_txns = array();
                        $_size488 = 0;
                        $_etype491 = 0;
                        $xfer += $input->readListBegin($_etype491, $_size488);
                        for ($_i492 = 0; $_i492 < $_size488; ++$_i492) {
                            $elem493 = null;
                            $elem493 = new \metastore\TxnInfo();
                            $xfer += $elem493->read($input);
                            $this->open_txns []= $elem493;
                        }
                        $xfer += $input->readListEnd();
                    } 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('GetOpenTxnsInfoResponse');
        if ($this->txn_high_water_mark !== null) {
            $xfer += $output->writeFieldBegin('txn_high_water_mark', TType::I64, 1);
            $xfer += $output->writeI64($this->txn_high_water_mark);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->open_txns !== null) {
            if (!is_array($this->open_txns)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('open_txns', TType::LST, 2);
            $output->writeListBegin(TType::STRUCT, count($this->open_txns));
            foreach ($this->open_txns as $iter494) {
                $xfer += $iter494->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
