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

    static public $_TSPEC = array(
        1 => array(
            'var' => 'userPrivileges',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::LST,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::LST,
                'etype' => TType::STRUCT,
                'elem' => array(
                    'type' => TType::STRUCT,
                    'class' => '\metastore\PrivilegeGrantInfo',
                    ),
                ),
        ),
        2 => array(
            'var' => 'groupPrivileges',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::LST,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::LST,
                'etype' => TType::STRUCT,
                'elem' => array(
                    'type' => TType::STRUCT,
                    'class' => '\metastore\PrivilegeGrantInfo',
                    ),
                ),
        ),
        3 => array(
            'var' => 'rolePrivileges',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::LST,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::LST,
                'etype' => TType::STRUCT,
                'elem' => array(
                    'type' => TType::STRUCT,
                    'class' => '\metastore\PrivilegeGrantInfo',
                    ),
                ),
        ),
    );

    /**
     * @var array
     */
    public $userPrivileges = null;
    /**
     * @var array
     */
    public $groupPrivileges = null;
    /**
     * @var array
     */
    public $rolePrivileges = null;

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

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


    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::MAP) {
                        $this->userPrivileges = array();
                        $_size106 = 0;
                        $_ktype107 = 0;
                        $_vtype108 = 0;
                        $xfer += $input->readMapBegin($_ktype107, $_vtype108, $_size106);
                        for ($_i110 = 0; $_i110 < $_size106; ++$_i110) {
                            $key111 = '';
                            $val112 = array();
                            $xfer += $input->readString($key111);
                            $val112 = array();
                            $_size113 = 0;
                            $_etype116 = 0;
                            $xfer += $input->readListBegin($_etype116, $_size113);
                            for ($_i117 = 0; $_i117 < $_size113; ++$_i117) {
                                $elem118 = null;
                                $elem118 = new \metastore\PrivilegeGrantInfo();
                                $xfer += $elem118->read($input);
                                $val112 []= $elem118;
                            }
                            $xfer += $input->readListEnd();
                            $this->userPrivileges[$key111] = $val112;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::MAP) {
                        $this->groupPrivileges = array();
                        $_size119 = 0;
                        $_ktype120 = 0;
                        $_vtype121 = 0;
                        $xfer += $input->readMapBegin($_ktype120, $_vtype121, $_size119);
                        for ($_i123 = 0; $_i123 < $_size119; ++$_i123) {
                            $key124 = '';
                            $val125 = array();
                            $xfer += $input->readString($key124);
                            $val125 = array();
                            $_size126 = 0;
                            $_etype129 = 0;
                            $xfer += $input->readListBegin($_etype129, $_size126);
                            for ($_i130 = 0; $_i130 < $_size126; ++$_i130) {
                                $elem131 = null;
                                $elem131 = new \metastore\PrivilegeGrantInfo();
                                $xfer += $elem131->read($input);
                                $val125 []= $elem131;
                            }
                            $xfer += $input->readListEnd();
                            $this->groupPrivileges[$key124] = $val125;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::MAP) {
                        $this->rolePrivileges = array();
                        $_size132 = 0;
                        $_ktype133 = 0;
                        $_vtype134 = 0;
                        $xfer += $input->readMapBegin($_ktype133, $_vtype134, $_size132);
                        for ($_i136 = 0; $_i136 < $_size132; ++$_i136) {
                            $key137 = '';
                            $val138 = array();
                            $xfer += $input->readString($key137);
                            $val138 = array();
                            $_size139 = 0;
                            $_etype142 = 0;
                            $xfer += $input->readListBegin($_etype142, $_size139);
                            for ($_i143 = 0; $_i143 < $_size139; ++$_i143) {
                                $elem144 = null;
                                $elem144 = new \metastore\PrivilegeGrantInfo();
                                $xfer += $elem144->read($input);
                                $val138 []= $elem144;
                            }
                            $xfer += $input->readListEnd();
                            $this->rolePrivileges[$key137] = $val138;
                        }
                        $xfer += $input->readMapEnd();
                    } 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('PrincipalPrivilegeSet');
        if ($this->userPrivileges !== null) {
            if (!is_array($this->userPrivileges)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('userPrivileges', TType::MAP, 1);
            $output->writeMapBegin(TType::STRING, TType::LST, count($this->userPrivileges));
            foreach ($this->userPrivileges as $kiter145 => $viter146) {
                $xfer += $output->writeString($kiter145);
                $output->writeListBegin(TType::STRUCT, count($viter146));
                foreach ($viter146 as $iter147) {
                    $xfer += $iter147->write($output);
                }
                $output->writeListEnd();
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->groupPrivileges !== null) {
            if (!is_array($this->groupPrivileges)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('groupPrivileges', TType::MAP, 2);
            $output->writeMapBegin(TType::STRING, TType::LST, count($this->groupPrivileges));
            foreach ($this->groupPrivileges as $kiter148 => $viter149) {
                $xfer += $output->writeString($kiter148);
                $output->writeListBegin(TType::STRUCT, count($viter149));
                foreach ($viter149 as $iter150) {
                    $xfer += $iter150->write($output);
                }
                $output->writeListEnd();
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->rolePrivileges !== null) {
            if (!is_array($this->rolePrivileges)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('rolePrivileges', TType::MAP, 3);
            $output->writeMapBegin(TType::STRING, TType::LST, count($this->rolePrivileges));
            foreach ($this->rolePrivileges as $kiter151 => $viter152) {
                $xfer += $output->writeString($kiter151);
                $output->writeListBegin(TType::STRUCT, count($viter152));
                foreach ($viter152 as $iter153) {
                    $xfer += $iter153->write($output);
                }
                $output->writeListEnd();
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
