/**
  * @return array|int|null|string
  * @throws UnknownTypeException
  * @throws EmptyResponseException
  */
 protected function read()
 {
     if (!($line = $this->Connection->readLine())) {
         throw new EmptyResponseException('Empty response. Please, check connection timeout.');
     }
     $type = $line[0];
     $data = substr($line, 1, -2);
     if ($type === self::TYPE_BULK_STRINGS) {
         $length = (int) $data;
         if ($length === -1) {
             return null;
         }
         return substr($this->Connection->read($length + 2), 0, -2);
     }
     if ($type === self::TYPE_SIMPLE_STRINGS) {
         if ($data === 'OK') {
             return true;
         }
         return $data;
     }
     if ($type === self::TYPE_INTEGERS) {
         return (int) $data;
     }
     if ($type === self::TYPE_ARRAYS) {
         $count = (int) $data;
         if ($count === -1) {
             return null;
         }
         $array = [];
         for ($i = 0; $i < $count; ++$i) {
             $array[] = $this->read();
         }
         return $array;
     }
     if ($type === self::TYPE_ERRORS) {
         return new ErrorResponseException($data);
     }
     throw new UnknownTypeException('Unknown protocol type ' . $type);
 }