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

    static public $_TSPEC = array(
        1 => array(
            'var' => 'roleName',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        2 => array(
            'var' => 'principalName',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        3 => array(
            'var' => 'principalType',
            'isRequired' => false,
            'type' => TType::I32,
            'class' => '\metastore\PrincipalType',
        ),
        4 => array(
            'var' => 'grantOption',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
        5 => array(
            'var' => 'grantTime',
            'isRequired' => false,
            'type' => TType::I32,
        ),
        6 => array(
            'var' => 'grantorName',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        7 => array(
            'var' => 'grantorPrincipalType',
            'isRequired' => false,
            'type' => TType::I32,
            'class' => '\metastore\PrincipalType',
        ),
    );

    /**
     * @var string
     */
    public $roleName = null;
    /**
     * @var string
     */
    public $principalName = null;
    /**
     * @var int
     */
    public $principalType = null;
    /**
     * @var bool
     */
    public $grantOption = null;
    /**
     * @var int
     */
    public $grantTime = null;
    /**
     * @var string
     */
    public $grantorName = null;
    /**
     * @var int
     */
    public $grantorPrincipalType = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['roleName'])) {
                $this->roleName = $vals['roleName'];
            }
            if (isset($vals['principalName'])) {
                $this->principalName = $vals['principalName'];
            }
            if (isset($vals['principalType'])) {
                $this->principalType = $vals['principalType'];
            }
            if (isset($vals['grantOption'])) {
                $this->grantOption = $vals['grantOption'];
            }
            if (isset($vals['grantTime'])) {
                $this->grantTime = $vals['grantTime'];
            }
            if (isset($vals['grantorName'])) {
                $this->grantorName = $vals['grantorName'];
            }
            if (isset($vals['grantorPrincipalType'])) {
                $this->grantorPrincipalType = $vals['grantorPrincipalType'];
            }
        }
    }

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


    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->roleName);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->principalName);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->principalType);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 4:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->grantOption);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 5:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->grantTime);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 6:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->grantorName);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 7:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->grantorPrincipalType);
                    } 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('RolePrincipalGrant');
        if ($this->roleName !== null) {
            $xfer += $output->writeFieldBegin('roleName', TType::STRING, 1);
            $xfer += $output->writeString($this->roleName);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->principalName !== null) {
            $xfer += $output->writeFieldBegin('principalName', TType::STRING, 2);
            $xfer += $output->writeString($this->principalName);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->principalType !== null) {
            $xfer += $output->writeFieldBegin('principalType', TType::I32, 3);
            $xfer += $output->writeI32($this->principalType);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->grantOption !== null) {
            $xfer += $output->writeFieldBegin('grantOption', TType::BOOL, 4);
            $xfer += $output->writeBool($this->grantOption);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->grantTime !== null) {
            $xfer += $output->writeFieldBegin('grantTime', TType::I32, 5);
            $xfer += $output->writeI32($this->grantTime);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->grantorName !== null) {
            $xfer += $output->writeFieldBegin('grantorName', TType::STRING, 6);
            $xfer += $output->writeString($this->grantorName);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->grantorPrincipalType !== null) {
            $xfer += $output->writeFieldBegin('grantorPrincipalType', TType::I32, 7);
            $xfer += $output->writeI32($this->grantorPrincipalType);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
