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

/**
 * Decimal logical type annotation
 * 
 * To maintain forward-compatibility in v1, implementations using this logical
 * type must also set scale and precision on the annotated SchemaElement.
 * 
 * Allowed for physical types: INT32, INT64, FIXED, and BINARY
 */
class DecimalType
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'scale',
            'isRequired' => true,
            'type' => TType::I32,
        ),
        2 => array(
            'var' => 'precision',
            'isRequired' => true,
            'type' => TType::I32,
        ),
    );

    /**
     * @var int
     */
    public $scale = null;
    /**
     * @var int
     */
    public $precision = null;

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

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


    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->scale);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->precision);
                    } 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('DecimalType');
        if ($this->scale !== null) {
            $xfer += $output->writeFieldBegin('scale', TType::I32, 1);
            $xfer += $output->writeI32($this->scale);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->precision !== null) {
            $xfer += $output->writeFieldBegin('precision', TType::I32, 2);
            $xfer += $output->writeI32($this->precision);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
