@Override
  public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeByte(comparatorType.id());
    out.writeVInt(requiredSize);
    out.writeVLong(missing);
    out.writeVLong(total);

    out.writeVInt(entries.size());
    for (LongEntry entry : entries) {
      out.writeLong(entry.term);
      out.writeVInt(entry.getCount());
    }
  }
  @Override
  public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    comparatorType = ComparatorType.fromId(in.readByte());
    requiredSize = in.readVInt();
    missing = in.readVLong();
    total = in.readVLong();

    int size = in.readVInt();
    entries = new ArrayList<LongEntry>(size);
    for (int i = 0; i < size; i++) {
      entries.add(new LongEntry(in.readLong(), in.readVInt()));
    }
  }