mirror of
https://github.com/glest/glest-source.git
synced 2025-08-30 11:19:48 +02:00
- add compressed network messages for nmtLaunch and nmtBroadCastSetup (not backward compatible)
This commit is contained in:
@@ -20,6 +20,8 @@ namespace Shared{ namespace CompressionUtil{
|
||||
|
||||
bool compressFileToZIPFile(string inFile, string outFile, int compressionLevel=5);
|
||||
bool extractFileFromZIPFile(string inFile, string outFile);
|
||||
std::pair<unsigned char *,unsigned long> compressMemoryToMemory(unsigned char *input, unsigned long input_len, int compressionLevel=5);
|
||||
std::pair<unsigned char *,unsigned long> extractMemoryToMemory(unsigned char *input, unsigned long input_len, unsigned long max_output_len);
|
||||
|
||||
}};
|
||||
|
||||
|
@@ -324,4 +324,39 @@ bool extractFileFromZIPFile(string inFile, string outFile) {
|
||||
return(result == EXIT_SUCCESS ? true : false);
|
||||
}
|
||||
|
||||
std::pair<unsigned char *,unsigned long> compressMemoryToMemory(unsigned char *input, unsigned long input_len, int compressionLevel) {
|
||||
// Like compress() but with more control, level may range from 0 (storing) to 9 (max. compression)
|
||||
unsigned long compressed_buffer_len = input_len + 100;
|
||||
unsigned char *compressed_buffer = new unsigned char[compressed_buffer_len+1];
|
||||
memset(compressed_buffer,0,compressed_buffer_len+1);
|
||||
|
||||
unsigned char *decompressed_buffer = new unsigned char[input_len+1];
|
||||
memcpy(decompressed_buffer,input,input_len);
|
||||
|
||||
//printf("compress2 start size: %lu\n",input_len);
|
||||
int result = compress2(compressed_buffer, &compressed_buffer_len, decompressed_buffer, input_len, compressionLevel);
|
||||
//printf("compress2 returned: %d start size: %lu end size: %lu\n",result,input_len,compressed_buffer_len);
|
||||
delete [] decompressed_buffer;
|
||||
|
||||
return make_pair(compressed_buffer,compressed_buffer_len);
|
||||
}
|
||||
|
||||
std::pair<unsigned char *,unsigned long> extractMemoryToMemory(unsigned char *input, unsigned long input_len, unsigned long max_output_len) {
|
||||
// Like compress() but with more control, level may range from 0 (storing) to 9 (max. compression)
|
||||
unsigned long decompressed_buffer_len = max_output_len;
|
||||
unsigned char *decompressed_buffer = new unsigned char[decompressed_buffer_len+1];
|
||||
memset(decompressed_buffer,0,decompressed_buffer_len+1);
|
||||
//printf("#1uncompress start size: %lu\n",input_len);
|
||||
|
||||
unsigned char *compressed_buffer = new unsigned char[input_len+1];
|
||||
memcpy(compressed_buffer,input,input_len);
|
||||
|
||||
//printf("#2uncompress start size: %lu\n",input_len);
|
||||
int result = uncompress(decompressed_buffer, &decompressed_buffer_len, compressed_buffer, input_len);
|
||||
//printf("uncompress returned: %d start size: %lu end size: %lu\n",result,input_len,decompressed_buffer_len);
|
||||
delete [] compressed_buffer;
|
||||
|
||||
return make_pair(decompressed_buffer,decompressed_buffer_len);
|
||||
}
|
||||
|
||||
}}
|
||||
|
Reference in New Issue
Block a user