<commit_before><?php

namespace DrSlump\Protobuf;

use DrSlump\Protobuf;

abstract class Message implements \ArrayAccess
{
    /** @var \DrSlump\Protobuf\Descriptor */
    static protected $descriptor;

    /** @var \Closure[] */
    static protected $__extensions = array();

    /** @var array Store data for extension fields */
    protected $_extensions = array();
    /** @var array Store data for unknown values */
    protected $_unknown = array();

    /**
     * @static
     * @abstract
     * @param \DrSlump\Protobuf\Descriptor|null $descriptor
     * @return \DrSlump\Protobuf\Descriptor
     */
    abstract public static function descriptor(\DrSlump\Protobuf\Descriptor $descriptor = null);

    /**
     * Register an extension configuration callback
     *
     * @static
     * @param \Closure $fn
     */
    public static function extension(\Closure $fn)
    {
        static::$__extensions[] = $fn;
    }

    /**
     * @param string $data
     */
    public function __construct($data = null)
    {
        // Assign default values to extensions
        $d = static::descriptor();
        foreach ($d->getFields() as $f) {
           if ($f->isExtension() && $f->hasDefault()) {
               $this->_extensions[$f->getName()] = $f->getDefault();
           }
        }

        if (NULL !== $data) {
            $this->parse($data);
        }
    }

    // Implements ArrayAccess for extensions and unknown fields

    public function offsetExists($offset)
    {
        if (is_numeric($offset)) {
            return $this->_has($offset);
        } else {
            return $this->hasExtension($offset);
        }
    }

    public function offsetSet($offset, $value)
    {
        if (is_numeric($offset)) {
            $this->_set($offset, $value);
        } else {
            $this->setExtension($offset, $value);
        }
    }

    public function offsetGet( $offset )
    {
        if (is_numeric($offset)) {
            return $this->_get($offset);
        } else {
            return $this->getExtension($offset);
        }
    }

    public function offsetUnset( $offset )
    {
        if (is_numeric($offset)) {
            $this->_clear($offset);
        } else {
            $this->clearExtension($offset);
        }
    }

    /**
     * Parse the given data to hydrate the object
     *
     * @param string $data
     * @param CodecInterface|null $codec
     */
    public function parse($data, Protobuf\CodecInterface $codec = null)
    {
        $codec = Protobuf::getCodec($codec);
        $codec->decode($this, $data);
    }

    /**
     * Serialize the current object data
     *
     * @param CodecInterface|null $codec
     * @return string
     */
    public function serialize(Protobuf\CodecInterface $codec = null)
    {
        $codec = Protobuf::getCodec($codec);
        return $codec->encode($this);
    }


    /**
     * Checks if the given tag number is set
     *
     * @param int $tag
     * @return bool
     */
    public function _has($tag)
    {
        $d = static::descriptor();

        if ($d->hasField($tag)) {
            $f = $d->getField($tag);
            $name = $f->getName();

            if ($f->isExtension()) {
                return $f->isRepeated()
                       ? count($this->_extensions[$name]) > 0
                       : $this->_extensions[$name] !== NULL;
            } else {
                return $f->isRepeated()
                       ? count($this->$name) > 0
                       : $this->$name !== NULL;
            }
        }

        return false;
    }

    /**
     * Get the value by tag number
     *
     * @param int $tag
     * @param int|null $idx
     * @return mixed
     */
    public function _get($tag, $idx = null)
    {
        $d = static::descriptor();
        $f = $d->getField($tag);

        if (!$f) {
            return null;
        }

        $name = $f->getName();

        if (!$f->isExtension()) {

            return $idx !== NULL
                   ? $this->$name[$idx]
                   : $this->$name;

        } else {

            return $idx !== NULL
                   ? $this->_extensions[$name][$idx]<commit_msg>Fixed bug in repeated fields adding<commit_after><?php

namespace DrSlump\Protobuf;

use DrSlump\Protobuf;

abstract class Message implements \ArrayAccess
{
    /** @var \DrSlump\Protobuf\Descriptor */
    static protected $descriptor;

    /** @var \Closure[] */
    static protected $__extensions = array();

    /** @var array Store data for extension fields */
    protected $_extensions = array();
    /** @var array Store data for unknown values */
    protected $_unknown = array();

    /**
     * @static
     * @abstract
     * @param \DrSlump\Protobuf\Descriptor|null $descriptor
     * @return \DrSlump\Protobuf\Descriptor
     */
    abstract public static function descriptor(\DrSlump\Protobuf\Descriptor $descriptor = null);

    /**
     * Register an extension configuration callback
     *
     * @static
     * @param \Closure $fn
     */
    public static function extension(\Closure $fn)
    {
        static::$__extensions[] = $fn;
    }

    /**
     * @param string $data
     */
    public function __construct($data = null)
    {
        // Assign default values to extensions
        $d = static::descriptor();
        foreach ($d->getFields() as $f) {
           if ($f->isExtension() && $f->hasDefault()) {
               $this->_extensions[$f->getName()] = $f->getDefault();
           }
        }

        if (NULL !== $data) {
            $this->parse($data);
        }
    }

    // Implements ArrayAccess for extensions and unknown fields

    public function offsetExists($offset)
    {
        if (is_numeric($offset)) {
            return $this->_has($offset);
        } else {
            return $this->hasExtension($offset);
        }
    }

    public function offsetSet($offset, $value)
    {
        if (is_numeric($offset)) {
            $this->_set($offset, $value);
        } else {
            $this->setExtension($offset, $value);
        }
    }

    public function offsetGet( $offset )
    {
        if (is_numeric($offset)) {
            return $this->_get($offset);
        } else {
            return $this->getExtension($offset);
        }
    }

    public function offsetUnset( $offset )
    {
        if (is_numeric($offset)) {
            $this->_clear($offset);
        } else {
            $this->clearExtension($offset);
        }
    }

    /**
     * Parse the given data to hydrate the object
     *
     * @param string $data
     * @param CodecInterface|null $codec
     */
    public function parse($data, Protobuf\CodecInterface $codec = null)
    {
        $codec = Protobuf::getCodec($codec);
        $codec->decode($this, $data);
    }

    /**
     * Serialize the current object data
     *
     * @param CodecInterface|null $codec
     * @return string
     */
    public function serialize(Protobuf\CodecInterface $codec = null)
    {
        $codec = Protobuf::getCodec($codec);
        return $codec->encode($this);
    }


    /**
     * Checks if the given tag number is set
     *
     * @param int $tag
     * @return bool
     */
    public function _has($tag)
    {
        $d = static::descriptor();

        if ($d->hasField($tag)) {
            $f = $d->getField($tag);
            $name = $f->getName();

            if ($f->isExtension()) {
                return $f->isRepeated()
                       ? count($this->_extensions[$name]) > 0
                       : $this->_extensions[$name] !== NULL;
            } else {
                return $f->isRepeated()
                       ? count($this->$name) > 0
                       : $this->$name !== NULL;
            }
        }

        return false;
    }

    /**
     * Get the value by tag number
     *
     * @param int $tag
     * @param int|null $idx
     * @return mixed
     */
    public function _get($tag, $idx = null)
    {
        $d = static::descriptor();
        $f = $d->getField($tag);

        if (!$f) {
            return null;
        }

        $name = $f->getName();

        if (!$f->isExtension()) {

            return $idx !== NULL
                   ? $this->{$name}[$idx]
                   : $this->$name;

        } else {

            return $idx !== NULL
                   ? $this->_extensions[$name][$idx]
{'fraction_non_alphanumeric': 0.14340435719415848, 'fraction_numerical': 0.00047881254488867607, 'mean_word_length': 1.6744558258642765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6596086', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2317, 'n_words': 546}