presto-main/src/main/java/io/prestosql/operator/aggregation/NumericHistogram.java/NumericHistogram/serialize
class NumericHistogram:    public Slice serialize()
    {
        compact();

        int requiredBytes = SizeOf.SIZE_OF_BYTE + // format
                SizeOf.SIZE_OF_INT + // max buckets
                SizeOf.SIZE_OF_INT + // entry count
                SizeOf.SIZE_OF_DOUBLE * nextIndex + // values
                SizeOf.SIZE_OF_DOUBLE * nextIndex; // weights

        return Slices.allocate(requiredBytes)
                .getOutput()
                .appendByte(FORMAT_TAG)
                .appendInt(maxBuckets)
                .appendInt(nextIndex)
                .appendBytes(Slices.wrappedDoubleArray(values, 0, nextIndex))
                .appendBytes(Slices.wrappedDoubleArray(weights, 0, nextIndex))
                .getUnderlyingSlice();
    }