@Override
 protected void doReadFrom(StreamInput in) throws IOException {
   valueFormatter = ValueFormatterStreams.readOptional(in);
   keys = new double[in.readInt()];
   for (int i = 0; i < keys.length; ++i) {
     keys[i] = in.readDouble();
   }
   long minBarForHighestToLowestValueRatio = in.readLong();
   ByteBuffer stateBuffer = ByteBuffer.wrap(in.readByteArray());
   try {
     state =
         DoubleHistogram.decodeFromCompressedByteBuffer(
             stateBuffer, minBarForHighestToLowestValueRatio);
   } catch (DataFormatException e) {
     throw new IOException("Failed to decode DoubleHistogram for aggregation [" + name + "]", e);
   }
   keyed = in.readBoolean();
 }
 /** Read from a stream. */
 public WrapperQueryBuilder(StreamInput in) throws IOException {
   super(in);
   source = in.readByteArray();
 }