public void readMsg() {
    if (nUpdateRectsLeft == 0) {

      int type = is.readU8();
      switch (type) {
      case MsgTypes.framebufferUpdate:   readFramebufferUpdate(); break;
      case MsgTypes.setColourMapEntries: readSetColourMapEntries(); break;
      case MsgTypes.bell:                readBell(); break;
      case MsgTypes.serverCutText:       readServerCutText(); break;
      default:
        vlog.error("unknown message type "+type);
        throw new Exception("unknown message type");
      }

    } else {

      int x = is.readU16();
      int y = is.readU16();
      int w = is.readU16();
      int h = is.readU16();
      int encoding = is.readU32();

      switch (encoding) {
      case Encodings.pseudoEncodingDesktopSize:
        handler.setDesktopSize(w, h);
        break;
      case Encodings.pseudoEncodingCursor:
        readSetCursor(x, y, w, h);
        break;
      default:
        readRect(x, y, w, h, encoding);
        break;
      }

      nUpdateRectsLeft--;
      if (nUpdateRectsLeft == 0) handler.framebufferUpdateEnd();
    }
  }