I have following code:
framingStatus compressToFrame(char* inputBuffer, size_t inputBufferLength, char* frame, size_t* frameLength)
{
dword crc32 = GetMaskedCrc(inputBuffer,inputBufferLength);
size_t length = snappy_max_compressed_length(inputBufferLength);
char* compressed = (char*)malloc(length);
snappy_status status = snappy_compress(inputBuffer,inputBufferLength,compressed,&length);
if( status!=SNAPPY_OK )
return FS_ERROR;
frame[0] = 0x00; // Typ ramki skompresowany
frame[1] = length&0xff;
frame[2] = (length&0xff00)>>8;
frame[3] = (length&0xff00)>>16;
frame[4] = crc32&0xff;
frame[5] = (crc32&0xff00)>>8;
frame[6] = (crc32&0xff0000)>>16;
frame[7] = (crc32&0xff000000)>>24;
frame[8] = '\0'; // Pomoc dla strcat
strcat(frame,compressed);
*frameLength = length+8;
free(compressed);
return FS_OK;
}
Before calling this function I allocate memory for buffer named frame. All is ok, but assign instructions frame[x] = ...
don't seem to write anything to buffer called frame
and strcat
concatenate compressed
data to empty buffer without header I need.
Why assign instructions frame[x] = ...
etc. don't give any result?
[EDIT:] Can you suggest what function I have to use if I want to concatenate frame header with compressed data?
[EDIT2:] Code presented below works just fine.
framingStatus compressToFrame(char* inputBuffer, size_t inputBufferLength, char* frame, size_t* frameLength)
{
dword crc32 = GetMaskedCrc(inputBuffer,inputBufferLength);
size_t length = snappy_max_compressed_length(inputBufferLength);
char* compressed = (char*)malloc(length);
snappy_status status = snappy_compress(inputBuffer,inputBufferLength,compressed,&length);
if( status!=SNAPPY_OK )
return FS_ERROR;
frame[0] = 0x00; // Typ ramki skompresowany
frame[1] = length;
frame[2] = length >> 8;
frame[3] = length >> 16;
frame[4] = crc32;
frame[5] = crc32 >>8;
frame[6] = crc32 >>16;
frame[7] = crc32 >>24;
memcpy(&frame[8],compressed,length);
*frameLength = length+8;
free(compressed);
return FS_OK;
}