void toData(DataOutput out, SerializationContext context,
      int startIndex, int numEntries, boolean sendKeys, boolean sendObjects)
      throws IOException {
    int flags = 0;
    boolean hasObjects = false;
    boolean hasTags = false;
    if (sendKeys && hasKeys) {
      flags |= 0x01;
    }
    if (sendObjects && !objects.isEmpty()) {
      flags |= 0x02;
      hasObjects = true;
    }
    if (versionTags.size() > 0) {
      flags |= 0x04;
      hasTags = true;
      for (VersionTag tag : versionTags) {
        if (tag != null) {
          if (tag instanceof DiskVersionTag) {
            flags |= 0x20;
          }
          break;
        }
      }
    }
    if (regionIsVersioned) {
      flags |= 0x08;
    }
    if (serializeValues) {
      flags |= 0x10;
    }
    if (logger.isTraceEnabled(LogMarker.VERSIONED_OBJECT_LIST_VERBOSE)) {
      logger.trace(LogMarker.VERSIONED_OBJECT_LIST_VERBOSE,
          "serializing {} with flags 0x{} startIndex={} numEntries={}", this,
          Integer.toHexString(flags), startIndex, numEntries);
    }
    out.writeByte(flags);
    if (sendKeys && hasKeys) {
      int numToWrite = numEntries;
      if (numToWrite + startIndex > keys.size()) {
        numToWrite = Math.max(0, keys.size() - startIndex);
      }
      InternalDataSerializer.writeUnsignedVL(numToWrite, out);
      int index = startIndex;
      for (int i = 0; i < numToWrite; i++, index++) {
        context.getSerializer().writeObject(keys.get(index), out);
      }
    }
    if (sendObjects && hasObjects) {
      int numToWrite = numEntries;
      if (numToWrite + startIndex > objects.size()) {
        numToWrite = Math.max(0, objects.size() - startIndex);
      }
      InternalDataSerializer.writeUnsignedVL(numToWrite, out);
      int idx = 0;
      int index = startIndex;
      for (int i = 0; i < numToWrite; i++, index++) {
        writeObject(objects.get(index), idx++, out, context);
      }
    }
    if (hasTags) {
      int numToWrite = numEntries;
      if (numToWrite + startIndex > versionTags.size()) {
        numToWrite = Math.max(0, versionTags.size() - startIndex);
      }
      InternalDataSerializer.writeUnsignedVL(numToWrite, out);
      Map<VersionSource, Integer> ids = new HashMap<>(numToWrite);
      int idCount = 0;
      int index = startIndex;
      for (int i = 0; i < numToWrite; i++, index++) {
        VersionTag tag = versionTags.get(index);
        if (tag == null) {
          out.writeByte(FLAG_NULL_TAG);
        } else {
          VersionSource id = tag.getMemberID();
          if (id == null) {
            out.writeByte(FLAG_FULL_TAG);
            InternalDataSerializer.invokeToData(tag, out);
          } else {
            Integer idNumber = ids.get(id);
            if (idNumber == null) {
              out.writeByte(FLAG_TAG_WITH_NEW_ID);
              idNumber = idCount++;
              ids.put(id, idNumber);
              InternalDataSerializer.invokeToData(tag, out);
            } else {
              out.writeByte(FLAG_TAG_WITH_NUMBER_ID);
              tag.toData(out, false);
              tag.setMemberID(id);
              InternalDataSerializer.writeUnsignedVL(idNumber, out);
            }
          }
        }
      }
    }
  }
sets the keys for this partlist
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/VersionedObjectList.java