def read_hash
      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

      result = {}
      offset = 0
      delimiter_pos = buffer.index(DELIMITER, offset)
      while !delimiter_pos.nil?
        if delimiter_pos == 0
          name = ""
        else
          name = buffer[offset .. delimiter_pos - 1]
        end

        offset = delimiter_pos + 1
        delimiter_pos = buffer.index(DELIMITER, offset)
        if delimiter_pos.nil?
          raise InvalidHashError
        elsif delimiter_pos == 0
          value = ""
        else
          value = buffer[offset .. delimiter_pos - 1]
        end

        result[name] = value
        offset = delimiter_pos + 1
        delimiter_pos = buffer.index(DELIMITER, offset)
      end
      return result
    rescue Errno::ECONNRESET
      return nil
    end
def read_hash
      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

      result = {}
      offset = 0
      delimiter_pos = buffer.index(DELIMITER, offset)
      while !delimiter_pos.nil?
        if delimiter_pos == 0
          name = ""
        else
          name = buffer[offset .. delimiter_pos - 1]
        end

        offset = delimiter_pos + 1
        delimiter_pos = buffer.index(DELIMITER, offset)
        if delimiter_pos.nil?
          raise InvalidHashError
        elsif delimiter_pos == 0
          value = ""
        else
          value = buffer[offset .. delimiter_pos - 1]
        end

        result[name] = value
        offset = delimiter_pos + 1
        delimiter_pos = buffer.index(DELIMITER, offset)
      end
      return result
    rescue Errno::ECONNRESET
      return nil
    end
Read an array message from the underlying file descriptor and return the
 result as a hash instead of an array. This assumes that the array message
 has an even number of elements.
 Returns nil when end-of-stream has been reached.

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