src/Protocol/Fetch.php
protected function decodeMessageSetArray(string $data, int $messageSetSize): array
    {
        $offset = 0;
        $result = [];

        while ($offset < strlen($data)) {
            $value = substr($data, $offset);
            $ret   = $this->decodeMessageSet($value);

            if ($ret === null) {
                break;
            }

            if (! isset($ret['length'], $ret['data'])) {
                throw new ProtocolException('Decode array failed, given function return format is invalid');
            }

            if ((int) $ret['length'] === 0) {
                continue;
            }

            $offset += $ret['length'];

            if (($ret['data']['message']['attr'] & Produce::COMPRESSION_CODEC_MASK) === Produce::COMPRESSION_NONE) {
                $result[] = $ret['data'];
                continue;
            }

            $innerMessages = $this->decodeMessageSetArray($ret['data']['message']['value'], $ret['length']);
            $result        = array_merge($result, $innerMessages['data']);
        }

        if ($offset < $messageSetSize) {
            $offset = $messageSetSize;
        }

        return ['length' => $offset, 'data' => $result];
    }
protected function decodeMessageSetArray(string $data, int $messageSetSize): array
    {
        $offset = 0;
        $result = [];

        while ($offset < strlen($data)) {
            $value = substr($data, $offset);
            $ret   = $this->decodeMessageSet($value);

            if ($ret === null) {
                break;
            }

            if (! isset($ret['length'], $ret['data'])) {
                throw new ProtocolException('Decode array failed, given function return format is invalid');
            }

            if ((int) $ret['length'] === 0) {
                continue;
            }

            $offset += $ret['length'];

            if (($ret['data']['message']['attr'] & Produce::COMPRESSION_CODEC_MASK) === Produce::COMPRESSION_NONE) {
                $result[] = $ret['data'];
                continue;
            }

            $innerMessages = $this->decodeMessageSetArray($ret['data']['message']['value'], $ret['length']);
            $result        = array_merge($result, $innerMessages['data']);
        }

        if ($offset < $messageSetSize) {
            $offset = $messageSetSize;
        }

        return ['length' => $offset, 'data' => $result];
    }
@return mixed[]

@throws ProtocolException