@Override
  public void toData(DataOutput out,
      SerializationContext context) throws IOException {
    context.getSerializer().writeObject(elementType, out);
    out.writeInt(size());
    writeNumNulls(out);
    // TODO:Asif: Should we actually pass the limit in serialization?
    // For the time being not passing , assuming PR Has parsed
    // it
    // out.writeInt(this.limit);
    int numLeft = size() - numNulls;
    for (Iterator<Entry> itr = map.entrySet().iterator(); itr.hasNext() && numLeft > 0;) {
      Entry entry = itr.next();
      Object key = entry.getKey();
      context.getSerializer().writeObject(key, out);
      int occurrence = entry.getValue();
      if (numLeft < occurrence) {
        occurrence = numLeft;
      }
      out.writeInt(occurrence);
      numLeft -= occurrence;
    }
  }
@param stats the CachePerfStats to track hash collisions. Should be null unless this is used as
       a query execution-time result set.
geode-core/src/main/java/org/apache/geode/cache/query/internal/ResultsBag.java