/** * Construct a new DoubleHistogram by decoding it from a compressed form in a ByteBuffer. * @param buffer The buffer to decode from * @param minBarForHighestToLowestValueRatio Force highestTrackableValue to be set at least this high * @return The newly constructed DoubleHistogram * @throws DataFormatException on error parsing/decompressing the buffer */ public static DoubleHistogram decodeFromCompressedByteBuffer( final ByteBuffer buffer, final long minBarForHighestToLowestValueRatio) throws DataFormatException { return decodeFromCompressedByteBuffer(buffer, Histogram.class, minBarForHighestToLowestValueRatio); }
/** * Decode a {@EncodableHistogram} from a compressed byte buffer. Will return either a * {@link org.HdrHistogram.Histogram} or {@link org.HdrHistogram.DoubleHistogram} depending * on the format found in the supplied buffer. * * @param buffer The input buffer to decode from. * @param minBarForHighestTrackableValue A lower bound either on the highestTrackableValue of * the created Histogram, or on the HighestToLowestValueRatio * of the created DoubleHistogram. * @return The decoded {@link org.HdrHistogram.Histogram} or {@link org.HdrHistogram.DoubleHistogram} * @throws DataFormatException on errors in decoding the buffer compression. */ static EncodableHistogram decodeFromCompressedByteBuffer( ByteBuffer buffer, final long minBarForHighestTrackableValue) throws DataFormatException { // Peek iun buffer to see the cookie: int cookie = buffer.getInt(buffer.position()); if (DoubleHistogram.isDoubleHistogramCookie(cookie)) { return DoubleHistogram.decodeFromCompressedByteBuffer(buffer, minBarForHighestTrackableValue); } else { return Histogram.decodeFromCompressedByteBuffer(buffer, minBarForHighestTrackableValue); } } }
/** * Read from a stream. */ protected AbstractInternalHDRPercentiles(StreamInput in) throws IOException { super(in); format = in.readNamedWriteable(DocValueFormat.class); keys = in.readDoubleArray(); long minBarForHighestToLowestValueRatio = in.readLong(); final int serializedLen = in.readVInt(); byte[] bytes = new byte[serializedLen]; in.readBytes(bytes, 0, serializedLen); ByteBuffer stateBuffer = ByteBuffer.wrap(bytes); try { state = DoubleHistogram.decodeFromCompressedByteBuffer(stateBuffer, minBarForHighestToLowestValueRatio); } catch (DataFormatException e) { throw new IOException("Failed to decode DoubleHistogram for aggregation [" + name + "]", e); } keyed = in.readBoolean(); }
/** * Construct a new DoubleHistogram by decoding it from a compressed form in a ByteBuffer. * @param buffer The buffer to decode from * @param minBarForHighestToLowestValueRatio Force highestTrackableValue to be set at least this high * @return The newly constructed DoubleHistogram * @throws DataFormatException on error parsing/decompressing the buffer */ public static DoubleHistogram decodeFromCompressedByteBuffer( final ByteBuffer buffer, final long minBarForHighestToLowestValueRatio) throws DataFormatException { return decodeFromCompressedByteBuffer(buffer, Histogram.class, minBarForHighestToLowestValueRatio); }
@Override public void fromBinary(final byte[] bytes) { final ByteBuffer buffer = super.binaryBuffer(bytes); final int endPosition = buffer.getInt(); try { positiveHistogram = DoubleHistogram.decodeFromCompressedByteBuffer(buffer, LocalInternalHistogram.class, 0); buffer.position(endPosition); positiveHistogram.setAutoResize(true); if (buffer.get() == (byte) 0x01) { negativeHistogram = DoubleHistogram.decodeFromCompressedByteBuffer(buffer, LocalInternalHistogram.class, 0); negativeHistogram.setAutoResize(true); } } catch (final DataFormatException e) { throw new RuntimeException("Cannot decode statistic", e); } }
/** * Decode a {@EncodableHistogram} from a compressed byte buffer. Will return either a * {@link org.HdrHistogram.Histogram} or {@link org.HdrHistogram.DoubleHistogram} depending * on the format found in the supplied buffer. * * @param buffer The input buffer to decode from. * @param minBarForHighestTrackableValue A lower bound either on the highestTrackableValue of * the created Histogram, or on the HighestToLowestValueRatio * of the created DoubleHistogram. * @return The decoded {@link org.HdrHistogram.Histogram} or {@link org.HdrHistogram.DoubleHistogram} * @throws DataFormatException on errors in decoding the buffer compression. */ static EncodableHistogram decodeFromCompressedByteBuffer( ByteBuffer buffer, final long minBarForHighestTrackableValue) throws DataFormatException { // Peek iun buffer to see the cookie: int cookie = buffer.getInt(buffer.position()); if (DoubleHistogram.isDoubleHistogramCookie(cookie)) { return DoubleHistogram.decodeFromCompressedByteBuffer(buffer, minBarForHighestTrackableValue); } else { return Histogram.decodeFromCompressedByteBuffer(buffer, minBarForHighestTrackableValue); } } }
/** * Read from a stream. */ protected AbstractInternalHDRPercentiles(StreamInput in) throws IOException { super(in); format = in.readNamedWriteable(DocValueFormat.class); keys = in.readDoubleArray(); long minBarForHighestToLowestValueRatio = in.readLong(); final int serializedLen = in.readVInt(); byte[] bytes = new byte[serializedLen]; in.readBytes(bytes, 0, serializedLen); ByteBuffer stateBuffer = ByteBuffer.wrap(bytes); 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. */ protected AbstractInternalHDRPercentiles(StreamInput in) throws IOException { super(in); format = in.readNamedWriteable(DocValueFormat.class); keys = in.readDoubleArray(); long minBarForHighestToLowestValueRatio = in.readLong(); final int serializedLen = in.readVInt(); byte[] bytes = new byte[serializedLen]; in.readBytes(bytes, 0, serializedLen); ByteBuffer stateBuffer = ByteBuffer.wrap(bytes); 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. */ protected AbstractInternalHDRPercentiles(StreamInput in) throws IOException { super(in); format = in.readNamedWriteable(DocValueFormat.class); keys = in.readDoubleArray(); long minBarForHighestToLowestValueRatio = in.readLong(); final int serializedLen = in.readVInt(); byte[] bytes = new byte[serializedLen]; in.readBytes(bytes, 0, serializedLen); ByteBuffer stateBuffer = ByteBuffer.wrap(bytes); try { state = DoubleHistogram.decodeFromCompressedByteBuffer(stateBuffer, minBarForHighestToLowestValueRatio); } catch (DataFormatException e) { throw new IOException("Failed to decode DoubleHistogram for aggregation [" + name + "]", e); } keyed = in.readBoolean(); }
@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(); final int serializedLen = in.readVInt(); byte[] bytes = new byte[serializedLen]; in.readBytes(bytes, 0, serializedLen); ByteBuffer stateBuffer = ByteBuffer.wrap(bytes); try { state = DoubleHistogram.decodeFromCompressedByteBuffer(stateBuffer, minBarForHighestToLowestValueRatio); } catch (DataFormatException e) { throw new IOException("Failed to decode DoubleHistogram for aggregation [" + name + "]", e); } keyed = in.readBoolean(); }