<?php

 
 
 
 
 
 






namespace Google\Protobuf\Internal;





class MapFieldIter implements \Iterator
{

    


    private $container;

    


    private $key_type;

    






    public function __construct($container, $key_type)
    {
        $this->container = $container;
        $this->key_type = $key_type;
    }

    





    #[\ReturnTypeWillChange]
    public function rewind()
    {
        reset($this->container);
    }

    





    #[\ReturnTypeWillChange]
    public function current()
    {
        return current($this->container);
    }

    





    #[\ReturnTypeWillChange]
    public function key()
    {
        $key = key($this->container);
        switch ($this->key_type) {
            case GPBType::INT64:
            case GPBType::UINT64:
            case GPBType::FIXED64:
            case GPBType::SFIXED64:
            case GPBType::SINT64:
                if (PHP_INT_SIZE === 8) {
                    return $key;
                }
                 
            case GPBType::STRING:
                 
                return strval($key);
            case GPBType::BOOL:
                 
                return boolval($key);
            default:
                return $key;
        }
    }

    





    #[\ReturnTypeWillChange]
    public function next()
    {
        next($this->container);
    }

    




    public function valid(): bool
    {
        return key($this->container) !== null;
    }
}
