<?php
namespace codename\parquet\format;

/**
 * Autogenerated by Thrift Compiler (0.15.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;

/**
 * The dictionary page must be placed at the first position of the column chunk
 * if it is partly or completely dictionary encoded. At most one dictionary page
 * can be placed in a column chunk.
 * 
 */
class DictionaryPageHeader
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'num_values',
            'isRequired' => true,
            'type' => TType::I32,
        ),
        2 => array(
            'var' => 'encoding',
            'isRequired' => true,
            'type' => TType::I32,
            'class' => '\codename\parquet\format\Encoding',
        ),
        3 => array(
            'var' => 'is_sorted',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
    );

    /**
     * Number of values in the dictionary *
     * 
     * @var int
     */
    public $num_values = null;
    /**
     * Encoding using this dictionary page *
     * 
     * @var int
     */
    public $encoding = null;
    /**
     * If true, the entries in the dictionary are sorted in ascending order *
     * 
     * @var bool
     */
    public $is_sorted = null;

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

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


    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::I32) {
                        $xfer += $input->readI32($this->num_values);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->encoding);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->is_sorted);
                    } 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('DictionaryPageHeader');
        if ($this->num_values !== null) {
            $xfer += $output->writeFieldBegin('num_values', TType::I32, 1);
            $xfer += $output->writeI32($this->num_values);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->encoding !== null) {
            $xfer += $output->writeFieldBegin('encoding', TType::I32, 2);
            $xfer += $output->writeI32($this->encoding);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->is_sorted !== null) {
            $xfer += $output->writeFieldBegin('is_sorted', TType::BOOL, 3);
            $xfer += $output->writeBool($this->is_sorted);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
