@ -10,12 +10,13 @@
# if defined(OS_WIN)
# if defined(OS_WIN)
# include "port/win/xpress_win.h"
# include "port/win/xpress_win.h"
# include <windows.h>
# include <windows.h>
# include <cassert>
# include <cassert>
# include <memory>
# include <limits>
# include <iostream>
# include <iostream>
# include <limits>
# include <memory>
# ifdef XPRESS
# ifdef XPRESS
@ -41,10 +42,9 @@ auto CloseDecompressorFun = [](void* h) {
: : CloseDecompressor ( reinterpret_cast < DECOMPRESSOR_HANDLE > ( h ) ) ;
: : CloseDecompressor ( reinterpret_cast < DECOMPRESSOR_HANDLE > ( h ) ) ;
}
}
} ;
} ;
}
} // namespace
bool Compress ( const char * input , size_t length , std : : string * output ) {
bool Compress ( const char * input , size_t length , std : : string * output ) {
assert ( input ! = nullptr ) ;
assert ( input ! = nullptr ) ;
assert ( output ! = nullptr ) ;
assert ( output ! = nullptr ) ;
@ -57,27 +57,26 @@ bool Compress(const char* input, size_t length, std::string* output) {
COMPRESSOR_HANDLE compressor = NULL ;
COMPRESSOR_HANDLE compressor = NULL ;
BOOL success = CreateCompressor (
BOOL success =
COMPRESS_ALGORITHM_XPRESS , // Compression Algorithm
CreateCompressor ( COMPRESS_ALGORITHM_XPRESS , // Compression Algorithm
allocRoutinesPtr , // Optional allocation routine
allocRoutinesPtr , // Optional allocation routine
& compressor ) ; // Handle
& compressor ) ; // Handle
if ( ! success ) {
if ( ! success ) {
# ifdef _DEBUG
# ifdef _DEBUG
std : : cerr < < " XPRESS: Failed to create Compressor LastError: " < <
std : : cerr < < " XPRESS: Failed to create Compressor LastError: "
GetLastError ( ) < < std : : endl ;
< < GetLastError ( ) < < std : : endl ;
# endif
# endif
return false ;
return false ;
}
}
std : : unique_ptr < void , decltype ( CloseCompressorFun ) >
std : : unique_ptr < void , decltype ( CloseCompressorFun ) > compressorGuard (
compressorGuard ( compressor , CloseCompressorFun ) ;
compressor , CloseCompressorFun ) ;
SIZE_T compressedBufferSize = 0 ;
SIZE_T compressedBufferSize = 0 ;
// Query compressed buffer size.
// Query compressed buffer size.
success = : : Compress (
success = : : Compress ( compressor , // Compressor Handle
compressor , // Compressor Handle
const_cast < char * > ( input ) , // Input buffer
const_cast < char * > ( input ) , // Input buffer
length , // Uncompressed data size
length , // Uncompressed data size
NULL , // Compressed Buffer
NULL , // Compressed Buffer
@ -85,14 +84,13 @@ bool Compress(const char* input, size_t length, std::string* output) {
& compressedBufferSize ) ; // Compressed Data size
& compressedBufferSize ) ; // Compressed Data size
if ( ! success ) {
if ( ! success ) {
auto lastError = GetLastError ( ) ;
auto lastError = GetLastError ( ) ;
if ( lastError ! = ERROR_INSUFFICIENT_BUFFER ) {
if ( lastError ! = ERROR_INSUFFICIENT_BUFFER ) {
# ifdef _DEBUG
# ifdef _DEBUG
std : : cerr < <
std : : cerr
" XPRESS: Failed to estimate compressed buffer size LastError " < <
< < " XPRESS: Failed to estimate compressed buffer size LastError "
lastError < < std : : endl ;
< < lastError < < std : : endl ;
# endif
# endif
return false ;
return false ;
}
}
@ -106,8 +104,7 @@ bool Compress(const char* input, size_t length, std::string* output) {
SIZE_T compressedDataSize = 0 ;
SIZE_T compressedDataSize = 0 ;
// Compress
// Compress
success = : : Compress (
success = : : Compress ( compressor , // Compressor Handle
compressor , // Compressor Handle
const_cast < char * > ( input ) , // Input buffer
const_cast < char * > ( input ) , // Input buffer
length , // Uncompressed data size
length , // Uncompressed data size
& result [ 0 ] , // Compressed Buffer
& result [ 0 ] , // Compressed Buffer
@ -116,8 +113,8 @@ bool Compress(const char* input, size_t length, std::string* output) {
if ( ! success ) {
if ( ! success ) {
# ifdef _DEBUG
# ifdef _DEBUG
std : : cerr < < " XPRESS: Failed to compress LastError " < <
std : : cerr < < " XPRESS: Failed to compress LastError " < < GetLastError ( )
GetLastError ( ) < < std : : endl ;
< < std : : endl ;
# endif
# endif
return false ;
return false ;
}
}
@ -141,12 +138,11 @@ char* Decompress(const char* input_data, size_t input_length,
DECOMPRESSOR_HANDLE decompressor = NULL ;
DECOMPRESSOR_HANDLE decompressor = NULL ;
BOOL success = CreateDecompressor (
BOOL success =
COMPRESS_ALGORITHM_XPRESS , // Compression Algorithm
CreateDecompressor ( COMPRESS_ALGORITHM_XPRESS , // Compression Algorithm
allocRoutinesPtr , // Optional allocation routine
allocRoutinesPtr , // Optional allocation routine
& decompressor ) ; // Handle
& decompressor ) ; // Handle
if ( ! success ) {
if ( ! success ) {
# ifdef _DEBUG
# ifdef _DEBUG
std : : cerr < < " XPRESS: Failed to create Decompressor LastError "
std : : cerr < < " XPRESS: Failed to create Decompressor LastError "
@ -155,13 +151,12 @@ char* Decompress(const char* input_data, size_t input_length,
return nullptr ;
return nullptr ;
}
}
std : : unique_ptr < void , decltype ( CloseDecompressorFun ) >
std : : unique_ptr < void , decltype ( CloseDecompressorFun ) > compressorGuard (
compressorGuard ( decompressor , CloseDecompressorFun ) ;
decompressor , CloseDecompressorFun ) ;
SIZE_T decompressedBufferSize = 0 ;
SIZE_T decompressedBufferSize = 0 ;
success = : : Decompress (
success = : : Decompress ( decompressor , // Compressor Handle
decompressor , // Compressor Handle
const_cast < char * > ( input_data ) , // Compressed data
const_cast < char * > ( input_data ) , // Compressed data
input_length , // Compressed data size
input_length , // Compressed data size
NULL , // Buffer set to NULL
NULL , // Buffer set to NULL
@ -169,7 +164,6 @@ char* Decompress(const char* input_data, size_t input_length,
& decompressedBufferSize ) ; // Decompressed Data size
& decompressedBufferSize ) ; // Decompressed Data size
if ( ! success ) {
if ( ! success ) {
auto lastError = GetLastError ( ) ;
auto lastError = GetLastError ( ) ;
if ( lastError ! = ERROR_INSUFFICIENT_BUFFER ) {
if ( lastError ! = ERROR_INSUFFICIENT_BUFFER ) {
@ -190,19 +184,14 @@ char* Decompress(const char* input_data, size_t input_length,
SIZE_T decompressedDataSize = 0 ;
SIZE_T decompressedDataSize = 0 ;
success = : : Decompress (
success = : : Decompress ( decompressor , const_cast < char * > ( input_data ) ,
decompressor ,
input_length , outputBuffer . get ( ) ,
const_cast < char * > ( input_data ) ,
decompressedBufferSize , & decompressedDataSize ) ;
input_length ,
outputBuffer . get ( ) ,
decompressedBufferSize ,
& decompressedDataSize ) ;
if ( ! success ) {
if ( ! success ) {
# ifdef _DEBUG
# ifdef _DEBUG
std : : cerr < <
std : : cerr < < " XPRESS: Failed to decompress LastError " < < GetLastError ( )
" XPRESS: Failed to decompress LastError " < <
< < std : : endl ;
GetLastError ( ) < < std : : endl ;
# endif
# endif
return nullptr ;
return nullptr ;
}
}
@ -212,8 +201,8 @@ char* Decompress(const char* input_data, size_t input_length,
// Return the raw buffer to the caller supporting the tradition
// Return the raw buffer to the caller supporting the tradition
return outputBuffer . release ( ) ;
return outputBuffer . release ( ) ;
}
}
}
} // namespace xpress
}
} // namespace port
} // namespace ROCKSDB_NAMESPACE
} // namespace ROCKSDB_NAMESPACE
# endif
# endif