def read
      buffer = new_buffer
      if !@io.read(HEADER_SIZE, buffer)
        return nil
      end
      while buffer.size < HEADER_SIZE
        tmp = @io.read(HEADER_SIZE - buffer.size)
        if tmp.empty?
          return nil
        else
          buffer << tmp
        end
      end

      chunk_size = buffer.unpack(UINT16_PACK_FORMAT)[0]
      if !@io.read(chunk_size, buffer)
        return nil
      end
      while buffer.size < chunk_size
        tmp = @io.read(chunk_size - buffer.size)
        if tmp.empty?
          return nil
        else
          buffer << tmp
        end
      end

      message = []
      offset = 0
      delimiter_pos = buffer.index(DELIMITER, offset)
      while !delimiter_pos.nil?
        if delimiter_pos == 0
          message << ''
        else
          message << buffer[offset..delimiter_pos - 1]
        end
        offset = delimiter_pos + 1
        delimiter_pos = buffer.index(DELIMITER, offset)
      end
      message
    rescue Errno::ECONNRESET
      nil
    end
def read
      buffer = new_buffer
      if !@io.read(HEADER_SIZE, buffer)
        return nil
      end
      while buffer.size < HEADER_SIZE
        tmp = @io.read(HEADER_SIZE - buffer.size)
        if tmp.empty?
          return nil
        else
          buffer << tmp
        end
      end

      chunk_size = buffer.unpack(UINT16_PACK_FORMAT)[0]
      if !@io.read(chunk_size, buffer)
        return nil
      end
      while buffer.size < chunk_size
        tmp = @io.read(chunk_size - buffer.size)
        if tmp.empty?
          return nil
        else
          buffer << tmp
        end
      end

      message = []
      offset = 0
      delimiter_pos = buffer.index(DELIMITER, offset)
      while !delimiter_pos.nil?
        if delimiter_pos == 0
          message << ''
        else
          message << buffer[offset..delimiter_pos - 1]
        end
        offset = delimiter_pos + 1
        delimiter_pos = buffer.index(DELIMITER, offset)
      end
      message
    rescue Errno::ECONNRESET
      nil
    end
Create a new MessageChannel by wrapping the given IO object.
 rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
 rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
 Read an array message from the underlying file descriptor.
 Returns the array message as an array, or nil when end-of-stream has
 been reached.

 Might raise SystemCallError, IOError or SocketError when something
 goes wrong.