private Reply receiveReply(InputStream is)
    throws IOException
  {
    int code = is.read();
    switch (code)
    {
      case StatusReply.MARKER:
      {
        byte[] buf = readStatus(is);

        // optimze 'OK\r\n'
        if (buf == OK)
          return StatusReply.OK;

        // optimze 'PONG\r\n'
        if (buf == PONG)
          return StatusReply.PONG;

        // TODO: handle QUEUED
        if (Arrays.equals(QUEUED, buf))
          return StatusReply.QUEUED;

        return new StatusReply(buf);
      }
      case ErrorReply.MARKER:
      {
        return new ErrorReply(readStatus(is));
      }
      case IntegerReply.MARKER:
      {
        return new IntegerReply(readInteger(is));
      }
      case BulkReply.MARKER:
      {
        return new BulkReply(readBytes(is));
      }
      case MultiBulkReply.MARKER:
      {
        return new MultiBulkReply(readMultiBulk(is));
      }
      default:
      {
        throw new IOException("Unexpected character in stream: " + code);
      }
    }
  }