/** * @file include/ActivMiddleware/ActivBase/Compress/ICompressor.h * * @brief Interface for various compression algorithms. */ #if (!defined ACTIV_BASE_COMPRESS_ICOMPRESSOR_H) #define ACTIV_BASE_COMPRESS_ICOMPRESSOR_H #include "ActivMiddleware/ActivBase/External.h" //! Activ namespace. namespace Activ { /** * @brief Calculate size of destination buffer needed to compress a buffer of length sourceLength. * * To support Zlib, destination buffer must be at least 0.1% + 12 bytes the size of the source buffer. * To support lz4, destination buffer must be at least 0.4% + 16 bytes the size of the source buffer. * * @param sourceLength length of the source buffer. * * @return size of destination buffer needed. */ #define ACTIV_COMPRESS_GET_DESTINATION_BUFFER_LENGTH(sourceLength) \ (static_cast(((static_cast((sourceLength)) * UINT64_C(1004)) / UINT64_C(1000)) + 16)) // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Abstract base block compression and decompression class. */ class ICompressor : private Boost::noncopyable { public: /** * @brief Destructor. */ ACTIV_BASE_API virtual ~ICompressor() = 0; /** * @brief Compress a buffer. * * @param pDestination the resultant compressed buffer. * @param destinationLength the length of the destination buffer. * @param pSource the buffer to be compressed. * @param sourceLength length of the source buffer. * @param compressedLength the number of bytes used in the destination buffer. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_FAILURE * @retval STATUS_CODE_INVALID_FORMAT * @retval STATUS_CODE_HEAP_EMPTY */ virtual StatusCode Compress(void *pDestination, const size_t destinationLength, const void *pSource, const size_t sourceLength, size_t &compressedLength) = 0; /** * @brief Decompress a buffer. * * @param pDestination the resultant decompressed buffer. * @param destinationLength the length of the destination buffer. * @param pSource the buffer to be decompressed. * @param sourceLength length of the source buffer. * @param decompressedLength the number of bytes used in the destination buffer. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_FAILURE * @retval STATUS_CODE_INVALID_FORMAT * @retval STATUS_CODE_HEAP_EMPTY */ virtual StatusCode Decompress(void *pDestination, const size_t destinationLength, const void *pSource, const size_t sourceLength, size_t &decompressedLength) = 0; /** * @brief Get compress statistics. * * @param apiCount total number of API calls made. * @param inputBytes total number of input bytes. * @param outputBytes total number of output bytes. */ ACTIV_BASE_API void GetCompressStats(uint64_t &apiCount, uint64_t &inputBytes, uint64_t &outputBytes) const; /** * @brief Get decompress statistics. * * @param apiCount total number of API calls made. * @param inputBytes total number of input bytes. * @param outputBytes total number of output bytes. */ ACTIV_BASE_API void GetDecompressStats(uint64_t &apiCount, uint64_t &inputBytes, uint64_t &outputBytes) const; /** * @brief Clear compress statistics. */ ACTIV_BASE_API void ClearCompressStats(); /** * @brief Clear decompress statistics. */ ACTIV_BASE_API void ClearDecompressStats(); protected: /** * @brief Compression and decompression statistics class. */ class Stats { public: /** * @brief Constructor. */ ACTIV_BASE_API Stats(); /** * @brief Update compression or decompression statistics. * * @param inputBytes number of input bytes. * @param outputBytes number of output bytes. */ ACTIV_BASE_API void UpdateStats(uint64_t inputBytes, uint64_t outputBytes); /** * @brief Get compression or decompression statistics. * * @param apiCount total number of API calls made. * @param inputBytes total number of input bytes. * @param outputBytes total number of output bytes. */ ACTIV_BASE_API void GetStats(uint64_t &apiCount, uint64_t &inputBytes, uint64_t &outputBytes) const; /** * @brief Clear compression or decompression statistics. */ ACTIV_BASE_API void ClearStats(); private: uint64_t m_apiCount; ///< number of API calls made. uint64_t m_inputBytes; ///< total number of input bytes. uint64_t m_outputBytes; ///< total number of output bytes. }; Stats m_compressStats; ///< compression statistics. Stats m_decompressStats; ///< decompression statistics. }; } // namespace Activ #endif // (!defined ACTIV_BASE_COMPRESS_ICOMPRESSOR_H)