presto-main/src/main/java/io/prestosql/operator/aggregation/state/DigestAndPercentileArrayStateSerializer.java/DigestAndPercentileArrayStateSerializer/serialize
class DigestAndPercentileArrayStateSerializer:    @Override
    public void serialize(DigestAndPercentileArrayState state, BlockBuilder out)
    {
        if (state.getDigest() == null) {
            out.appendNull();
        }
        else {
            Slice digest = state.getDigest().serialize();

            SliceOutput output = Slices.allocate(
                    SIZE_OF_INT + // number of percentiles
                            state.getPercentiles().size() * SIZE_OF_DOUBLE + // percentiles
                            SIZE_OF_INT + // digest length
                            digest.length()) // digest
                    .getOutput();

            // write percentiles
            List<Double> percentiles = state.getPercentiles();
            output.appendInt(percentiles.size());
            for (double percentile : percentiles) {
                output.appendDouble(percentile);
            }

            output.appendInt(digest.length());
            output.appendBytes(digest);

            VARBINARY.writeSlice(out, output.slice());
        }
    }