<?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;

class PageLocation
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'offset',
            'isRequired' => true,
            'type' => TType::I64,
        ),
        2 => array(
            'var' => 'compressed_page_size',
            'isRequired' => true,
            'type' => TType::I32,
        ),
        3 => array(
            'var' => 'first_row_index',
            'isRequired' => true,
            'type' => TType::I64,
        ),
    );

    /**
     * Offset of the page in the file *
     * 
     * @var int
     */
    public $offset = null;
    /**
     * Size of the page, including header. Sum of compressed_page_size and header
     * length
     * 
     * @var int
     */
    public $compressed_page_size = null;
    /**
     * Index within the RowGroup of the first row of the page; this means pages
     * change on record boundaries (r = 0).
     * 
     * @var int
     */
    public $first_row_index = null;

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

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


    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->offset);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->compressed_page_size);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::I64) {
                        $xfer += $input->readI64($this->first_row_index);
                    } 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('PageLocation');
        if ($this->offset !== null) {
            $xfer += $output->writeFieldBegin('offset', TType::I64, 1);
            $xfer += $output->writeI64($this->offset);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->compressed_page_size !== null) {
            $xfer += $output->writeFieldBegin('compressed_page_size', TType::I32, 2);
            $xfer += $output->writeI32($this->compressed_page_size);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->first_row_index !== null) {
            $xfer += $output->writeFieldBegin('first_row_index', TType::I64, 3);
            $xfer += $output->writeI64($this->first_row_index);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
