public byte [ ] asBytes ( ) { byte [ ] className = tdigest . getClass ( ) . getName ( ) . getBytes ( Charsets . UTF_8 ) ; int vlen = exactValues == null ? 0 : numExactValues ; ByteBuffer buf = ByteBuffer . allocate ( 4 + 8 * 5 + 4 + 4 + 8 * vlen + 4 + className . length + tdigest . byteSize ( ) + 4 ) ; buf . putInt ( MAGIC_CODE ) ; // for sanity checks // write basic descriptive stats buf . putLong ( count ) ; buf . putDouble ( min ) ; buf . putDouble ( max ) ; buf . putDouble ( sum ) ; buf . putDouble ( sumOfSquares ) ; // write exact values, if any buf . putInt ( exactQuantilesThreshold ) ; buf . putInt ( exactValues == null ? - 1 : numExactValues ) ; if ( exactValues != null ) { for ( int i = 0 ; i < numExactValues ; i ++ ) { buf . putDouble ( exactValues [ i ] ) ; } } // write tdigest buf . putInt ( className . length ) ; buf . put ( className ) ; tdigest . asBytes ( buf ) ; buf . putInt ( MAGIC_CODE ) ; // for sanity checks Preconditions . checkArgument ( buf . position ( ) == buf . capacity ( ) ) ; return buf . array ( ) ; }
Serializes the data structure into a byte array