The V2DeflateSerializer is used to serialize a Histogram into a compressed binary format. While named 'deflate' to maintain consistency with the Java implementation, it actually uses the zlib wrapper format around plain DEFLATE.
To use it, implement the Serializer trait. The serialize method takes a Histogram and a writer, and returns the number of bytes written.
Error Handling
Serialization can fail with a V2DeflateSerializeError, which wraps:
InternalSerializationError(V2SerializeError): Errors occurring during the underlying V2 serialization process.IoError(io::Error): Standard I/O errors encountered during writing.
use hdrhistogram::Histogram;
use hdrhistogram::serialization::Serializer;
use hdrhistogram::serialization::v2_deflate_serializer::V2DeflateSerializer;
// Assuming 'h' is an existing Histogram and 'writer' is a type implementing std::io::Write
let mut serializer = V2DeflateSerializer::new();
let bytes_written = serializer.serialize(&h, &mut writer)?;