@Override
 protected void doWriteTo(StreamOutput out) throws IOException {
   ValueFormatterStreams.writeOptional(valueFormatter, out);
   out.writeInt(keys.length);
   for (int i = 0; i < keys.length; ++i) {
     out.writeDouble(keys[i]);
   }
   out.writeLong(state.getHighestToLowestValueRatio());
   ByteBuffer stateBuffer = ByteBuffer.allocate(state.getNeededByteBufferCapacity());
   state.encodeIntoCompressedByteBuffer(stateBuffer);
   out.writeByteArray(stateBuffer.array());
   out.writeBoolean(keyed);
 }