/** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        deltas =
            reader.readMap(
                "deltas", MessageCollectionItemType.UUID, MessageCollectionItemType.LONG, false);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 1:
        snapVer = reader.readMessage("snapVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return reader.afterMessageRead(GridClockDeltaSnapshotMessage.class);
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    if (!super.readFrom(buf, reader)) return false;

    switch (reader.state()) {
      case 0:
        fileId = reader.readIgniteUuid("fileId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 1:
        fragmentRanges = reader.readCollection("fragmentRanges", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return true;
  }
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  public <T extends Message> T readMessage(MessageReader reader) {
    if (!msgTypeDone) {
      if (!buf.hasRemaining()) {
        lastFinished = false;

        return null;
      }

      byte type = readByte();

      msg = type == Byte.MIN_VALUE ? null : msgFactory.create(type);

      msgTypeDone = true;
    }

    if (msg != null) {
      try {
        reader.beforeInnerMessageRead();

        reader.setCurrentReadClass(msg.getClass());

        lastFinished = msg.readFrom(buf, reader);
      } finally {
        reader.afterInnerMessageRead(lastFinished);
      }
    } else lastFinished = true;

    if (lastFinished) {
      Message msg0 = msg;

      msgTypeDone = false;
      msg = null;

      return (T) msg0;
    } else return null;
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        val = reader.readMessage("val");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 1:
        ver = reader.readMessage("ver");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return reader.afterMessageRead(CacheVersionedValue.class);
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        bytes = reader.readByteArray("bytes");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return reader.afterMessageRead(CacheEntrySerializablePredicate.class);
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        topVer = reader.readLong("topVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 1:
        ver = reader.readLong("ver");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return true;
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        val = reader.readByteArray("val");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return true;
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        pageSize = reader.readInt("pageSize");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 1:
        qrys = reader.readCollection("qrys", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 2:
        reqId = reader.readLong("reqId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 3:
        space = reader.readString("space");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 4:
        topVer = reader.readMessage("topVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 5:
        extraSpaces = reader.readCollection("extraSpaces", MessageCollectionItemType.STRING);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 6:
        parts = reader.readIntArray("parts");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return reader.afterMessageRead(GridQueryRequest.class);
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        cacheId = reader.readInt("cacheId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 1:
        byte evtTypeOrd;

        evtTypeOrd = reader.readByte("evtType");

        if (!reader.isLastRead()) return false;

        evtType = eventTypeFromOrdinal(evtTypeOrd);

        reader.incrementState();

      case 2:
        filteredEvts = reader.readMessage("filteredEvts");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 3:
        flags = reader.readByte("flags");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 4:
        key = reader.readMessage("key");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 5:
        newVal = reader.readMessage("newVal");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 6:
        oldVal = reader.readMessage("oldVal");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 7:
        part = reader.readInt("part");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 8:
        topVer = reader.readMessage("topVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 9:
        updateCntr = reader.readLong("updateCntr");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return reader.afterMessageRead(CacheContinuousQueryEntry.class);
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    if (!super.readFrom(buf, reader)) return false;

    switch (reader.state()) {
      case 10:
        dhtVer = reader.readMessage("dhtVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 11:
        filterFailedKeys = reader.readCollection("filterFailedKeys", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 12:
        futId = reader.readIgniteUuid("futId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 13:
        invalidParts = reader.readCollection("invalidParts", MessageCollectionItemType.INT);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 14:
        miniId = reader.readIgniteUuid("miniId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 15:
        ownedValKeys = reader.readCollection("ownedValKeys", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 16:
        ownedValVals = reader.readCollection("ownedValVals", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 17:
        pending = reader.readCollection("pending", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 18:
        retVal = reader.readMessage("retVal");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return true;
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        cpSpi = reader.readString("cpSpi");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 1:
        key = reader.readString("key");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 2:
        sesId = reader.readIgniteUuid("sesId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return true;
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    if (!super.readFrom(buf, reader)) return false;

    switch (reader.state()) {
      case 3:
        conflictExpireTimes = reader.readMessage("conflictExpireTimes");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 4:
        conflictTtls = reader.readMessage("conflictTtls");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 5:
        conflictVers = reader.readCollection("conflictVers", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 6:
        entryProcessorsBytes =
            reader.readCollection("entryProcessorsBytes", MessageCollectionItemType.BYTE_ARR);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 7:
        expiryPlcBytes = reader.readByteArray("expiryPlcBytes");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 8:
        fastMap = reader.readBoolean("fastMap");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 9:
        filter =
            reader.readObjectArray(
                "filter", MessageCollectionItemType.MSG, CacheEntryPredicate.class);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 10:
        futVer = reader.readMessage("futVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 11:
        hasPrimary = reader.readBoolean("hasPrimary");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 12:
        invokeArgsBytes =
            reader.readObjectArray(
                "invokeArgsBytes", MessageCollectionItemType.BYTE_ARR, byte[].class);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 13:
        keys = reader.readCollection("keys", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 14:
        byte opOrd;

        opOrd = reader.readByte("op");

        if (!reader.isLastRead()) return false;

        op = GridCacheOperation.fromOrdinal(opOrd);

        reader.incrementState();

      case 15:
        retval = reader.readBoolean("retval");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 16:
        skipStore = reader.readBoolean("skipStore");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 17:
        subjId = reader.readUuid("subjId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 18:
        byte syncModeOrd;

        syncModeOrd = reader.readByte("syncMode");

        if (!reader.isLastRead()) return false;

        syncMode = CacheWriteSynchronizationMode.fromOrdinal(syncModeOrd);

        reader.incrementState();

      case 19:
        taskNameHash = reader.readInt("taskNameHash");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 20:
        topVer = reader.readMessage("topVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 21:
        updateVer = reader.readMessage("updateVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 22:
        vals = reader.readCollection("vals", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return true;
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    if (!super.readFrom(buf, reader)) return false;

    switch (reader.state()) {
      case 8:
        byte concurrencyOrd;

        concurrencyOrd = reader.readByte("concurrency");

        if (!reader.isLastRead()) return false;

        concurrency = TransactionConcurrency.fromOrdinal(concurrencyOrd);

        reader.incrementState();

      case 9:
        dhtVerKeys = reader.readCollection("dhtVerKeys", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 10:
        dhtVerVals = reader.readCollection("dhtVerVals", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 11:
        grpLockKeyBytes = reader.readByteArray("grpLockKeyBytes");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 12:
        invalidate = reader.readBoolean("invalidate");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 13:
        byte isolationOrd;

        isolationOrd = reader.readByte("isolation");

        if (!reader.isLastRead()) return false;

        isolation = TransactionIsolation.fromOrdinal(isolationOrd);

        reader.incrementState();

      case 14:
        onePhaseCommit = reader.readBoolean("onePhaseCommit");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 15:
        partLock = reader.readBoolean("partLock");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 16:
        byte plcOrd;

        plcOrd = reader.readByte("plc");

        if (!reader.isLastRead()) return false;

        plc = GridIoPolicy.fromOrdinal(plcOrd);

        reader.incrementState();

      case 17:
        reads = reader.readCollection("reads", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 18:
        sys = reader.readBoolean("sys");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 19:
        threadId = reader.readLong("threadId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 20:
        timeout = reader.readLong("timeout");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 21:
        txNodesBytes = reader.readByteArray("txNodesBytes");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 22:
        txSize = reader.readInt("txSize");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 23:
        writeVer = reader.readMessage("writeVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 24:
        writes = reader.readCollection("writes", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return true;
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    if (!super.readFrom(buf, reader)) return false;

    switch (reader.state()) {
      case 3:
        ack = reader.readBoolean("ack");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 4:
        infos =
            reader.readMap(
                "infos", MessageCollectionItemType.INT, MessageCollectionItemType.MSG, false);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 5:
        last = reader.readCollection("last", MessageCollectionItemType.INT);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 6:
        missed = reader.readCollection("missed", MessageCollectionItemType.INT);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 7:
        updateSeq = reader.readLong("updateSeq");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 8:
        workerId = reader.readInt("workerId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return reader.afterMessageRead(GridDhtPartitionSupplyMessage.class);
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    switch (reader.state()) {
      case 0:
        clsLdrId = reader.readIgniteUuid("clsLdrId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 1:
        byte depModeOrd;

        depModeOrd = reader.readByte("depMode");

        if (!reader.isLastRead()) return false;

        depMode = DeploymentMode.fromOrdinal(depModeOrd);

        reader.incrementState();

      case 2:
        locDepOwner = reader.readBoolean("locDepOwner");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 3:
        participants =
            reader.readMap(
                "participants",
                MessageCollectionItemType.UUID,
                MessageCollectionItemType.IGNITE_UUID,
                false);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 4:
        userVer = reader.readString("userVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return reader.afterMessageRead(GridDeploymentInfoBean.class);
  }