<?php
// automatically generated by the FlatBuffers compiler, do not modify

namespace flatbuffers\goldens;

use \Google\FlatBuffers\Struct;
use \Google\FlatBuffers\Table;
use \Google\FlatBuffers\ByteBuffer;
use \Google\FlatBuffers\FlatBufferBuilder;

class Universe extends Table
{
    /**
     * @param ByteBuffer $bb
     * @return Universe
     */
    public static function getRootAsUniverse(ByteBuffer $bb)
    {
        $obj = new Universe();
        return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
    }

    /**
     * @param int $_i offset
     * @param ByteBuffer $_bb
     * @return Universe
     **/
    public function init($_i, ByteBuffer $_bb)
    {
        $this->bb_pos = $_i;
        $this->bb = $_bb;
        return $this;
    }

    /**
     * @return double
     */
    public function getAge()
    {
        $o = $this->__offset(4);
        return $o != 0 ? $this->bb->getDouble($o + $this->bb_pos) : 0.0;
    }

    /**
     * @returnVectorOffset
     */
    public function getGalaxies($j)
    {
        $o = $this->__offset(6);
        $obj = new Galaxy();
        return $o != 0 ? $obj->init($this->__indirect($this->__vector($o) + $j * 4), $this->bb) : null;
    }

    /**
     * @return int
     */
    public function getGalaxiesLength()
    {
        $o = $this->__offset(6);
        return $o != 0 ? $this->__vector_len($o) : 0;
    }

    /**
     * @param FlatBufferBuilder $builder
     * @return void
     */
    public static function startUniverse(FlatBufferBuilder $builder)
    {
        $builder->StartObject(2);
    }

    /**
     * @param FlatBufferBuilder $builder
     * @return Universe
     */
    public static function createUniverse(FlatBufferBuilder $builder, $age, $galaxies)
    {
        $builder->startObject(2);
        self::addAge($builder, $age);
        self::addGalaxies($builder, $galaxies);
        $o = $builder->endObject();
        return $o;
    }

    /**
     * @param FlatBufferBuilder $builder
     * @param double
     * @return void
     */
    public static function addAge(FlatBufferBuilder $builder, $age)
    {
        $builder->addDoubleX(0, $age, 0.0);
    }

    /**
     * @param FlatBufferBuilder $builder
     * @param VectorOffset
     * @return void
     */
    public static function addGalaxies(FlatBufferBuilder $builder, $galaxies)
    {
        $builder->addOffsetX(1, $galaxies, 0);
    }

    /**
     * @param FlatBufferBuilder $builder
     * @param array offset array
     * @return int vector offset
     */
    public static function createGalaxiesVector(FlatBufferBuilder $builder, array $data)
    {
        $builder->startVector(4, count($data), 4);
        for ($i = count($data) - 1; $i >= 0; $i--) {
            $builder->putOffset($data[$i]);
        }
        return $builder->endVector();
    }

    /**
     * @param FlatBufferBuilder $builder
     * @param int $numElems
     * @return void
     */
    public static function startGalaxiesVector(FlatBufferBuilder $builder, $numElems)
    {
        $builder->startVector(4, $numElems, 4);
    }

    /**
     * @param FlatBufferBuilder $builder
     * @return int table offset
     */
    public static function endUniverse(FlatBufferBuilder $builder)
    {
        $o = $builder->endObject();
        return $o;
    }

    public static function finishUniverseBuffer(FlatBufferBuilder $builder, $offset)
    {
        $builder->finish($offset);
    }
}
