static DataInputStream getSerializedStream(StoreFindToken token, short version) {
    byte[] bytes;
    FindTokenType type = token.getType();
    byte[] sessionIdBytes = token.getSessionIdInBytes();
    byte[] storeKeyInBytes = token.getStoreKeyInBytes();
    switch (version) {
      case StoreFindToken.VERSION_0:
        // version size + sessionId length size + session id size + log offset size + index segment start offset size
        // + store key size
        int size = 2 + 4 + sessionIdBytes.length + 8 + 8 + storeKeyInBytes.length;
        bytes = new byte[size];
        ByteBuffer bufWrap = ByteBuffer.wrap(bytes);
        // add version
        bufWrap.putShort(StoreFindToken.VERSION_0);
        // add sessionId
        bufWrap.putInt(sessionIdBytes.length);
        bufWrap.put(sessionIdBytes);
        long logOffset = -1;
        long indexStartOffset = -1;
        if (type.equals(FindTokenType.JournalBased)) {
          logOffset = token.getOffset().getOffset();
        } else if (type.equals(FindTokenType.IndexBased)) {
          indexStartOffset = token.getOffset().getOffset();
        }
        // add offset
        bufWrap.putLong(logOffset);
        // add index start offset
        bufWrap.putLong(indexStartOffset);
        // add storeKey
        if (storeKeyInBytes.length > 0) {
          bufWrap.put(storeKeyInBytes);
        }
        break;
      case StoreFindToken.VERSION_1:
        byte[] offsetBytes = token.getOffsetInBytes();
        // version size + sessionId length size + session id size + type + log offset / index segment start offset size
        // + store key size
        size = 2 + 4 + sessionIdBytes.length + 2 + offsetBytes.length + storeKeyInBytes.length;
        bytes = new byte[size];
        bufWrap = ByteBuffer.wrap(bytes);
        // add version
        bufWrap.putShort(StoreFindToken.VERSION_1);
        // add sessionId
        bufWrap.putInt(sessionIdBytes.length);
        bufWrap.put(sessionIdBytes);
        // add type
        bufWrap.putShort((byte) type.ordinal());
        bufWrap.put(offsetBytes);
        if (storeKeyInBytes.length > 0) {
          bufWrap.put(storeKeyInBytes);
        }
        break;
      case VERSION_2:
        offsetBytes = token.getOffsetInBytes();
        byte[] incarnationIdBytes = token.getIncarnationIdInBytes();
        size = VERSION_SIZE + TYPE_SIZE;
        if (type != FindTokenType.Uninitialized) {
          size +=
              INCARNATION_ID_LENGTH_SIZE + incarnationIdBytes.length + SESSION_ID_LENGTH_SIZE + sessionIdBytes.length
                  + offsetBytes.length;
          if (type == FindTokenType.JournalBased) {
            size += INCLUSIVE_BYTE_SIZE;
          } else if (type == FindTokenType.IndexBased) {
            size += storeKeyInBytes.length;
          }
        }
        bytes = new byte[size];
        bufWrap = ByteBuffer.wrap(bytes);
        // add version
        bufWrap.putShort(VERSION_2);
        // add type
        bufWrap.putShort((short) type.ordinal());
        if (type != FindTokenType.Uninitialized) {
          // add incarnationId
          bufWrap.putInt(incarnationIdBytes.length);
          bufWrap.put(incarnationIdBytes);
          // add sessionId
          bufWrap.putInt(sessionIdBytes.length);
          bufWrap.put(sessionIdBytes);
          // add offset
          bufWrap.put(offsetBytes);
          if (type == FindTokenType.JournalBased) {
            bufWrap.put(token.getInclusive() ? (byte) 1 : (byte) 0);
          } else if (type == FindTokenType.IndexBased) {
            bufWrap.put(storeKeyInBytes);
          }
        }
        break;
      case StoreFindToken.CURRENT_VERSION:
        bytes = token.toBytes();
        break;
      default:
        throw new IllegalArgumentException("Version " + version + " of StoreFindToken does not exist");
    }
    return new DataInputStream(new ByteBufferInputStream(ByteBuffer.wrap(bytes)));
  }
Gets a serialized format of {@code token} in the version {@code version}.
@param token the {@link StoreFindToken} to serialize.
@param version the version to serialize it in.
@return a serialized format of {@code token} in the version {@code version}.
ambry-store/src/test/java/com/github/ambry/store/StoreFindTokenTest.java