File indexing completed on 2025-08-03 08:20:45
0001 #include "lzobuffer.h"
0002 #include "lzo/lzoutil.h"
0003 #include "oncsBuffer.h"
0004
0005 int lzobuffer::lzo_initialized = 0;
0006
0007
0008
0009 lzobuffer::lzobuffer (PHDWORD *array , const int length )
0010
0011 {
0012
0013 if ( ! lzo_initialized )
0014 {
0015 if (lzo_init() != LZO_E_OK)
0016 {
0017 COUT << "Could not initialize LZO" << std::endl;
0018 _broken = 1;
0019 }
0020
0021 lzo_initialized = 1;
0022 }
0023
0024
0025 is_good =1;
0026 bufferarray=0;
0027 theBuffer=0;
0028
0029 lzo_uint bytes;
0030 lzo_uint outputlength_in_bytes;
0031 if (array[1] == LZO1XBUFFERMARKER ||
0032 array[1] == LZO1CBUFFERMARKER ||
0033 array[1] == LZO2ABUFFERMARKER )
0034 {
0035 bytes = array[0]-4*BUFFERHEADERLENGTH;
0036 outputlength_in_bytes = array[3];
0037 }
0038 else if ( u4swap(array[1]) == LZO1XBUFFERMARKER
0039 || u4swap(array[1]) == LZO1CBUFFERMARKER
0040 || u4swap(array[1]) == LZO2ABUFFERMARKER)
0041 {
0042 bytes = i4swap(array[0])-16;
0043 outputlength_in_bytes = i4swap(array[3]);
0044 }
0045
0046 else
0047 {
0048 COUT << __FILE__ << " " << __LINE__ << " wrong buffer marker = " << std::hex << array[1] << std::dec << std::endl;
0049 is_good = 0;
0050 return;
0051 }
0052
0053
0054 int outputlength = (outputlength_in_bytes+3)/4;
0055 bufferarray = new PHDWORD[outputlength];
0056 lzo_uint olen;
0057
0058
0059 olen = outputlength_in_bytes;
0060
0061 if (array[1] == LZO1XBUFFERMARKER || u4swap(array[1]) == LZO1XBUFFERMARKER )
0062 {
0063 lzo1x_decompress_safe ( (lzo_byte *) &array[4], bytes,
0064 (lzo_byte *) bufferarray, &olen, NULL );
0065 }
0066 else if (array[1] == LZO1CBUFFERMARKER || u4swap(array[1]) == LZO1CBUFFERMARKER )
0067 {
0068
0069 lzo1c_decompress_safe ( (lzo_byte *) &array[4], bytes,
0070 (lzo_byte *) bufferarray, &olen, NULL );
0071
0072 }
0073 else
0074 {
0075
0076 lzo2a_decompress_safe ( (lzo_byte *) &array[4], bytes,
0077 (lzo_byte *) bufferarray, &olen, NULL );
0078
0079 }
0080
0081
0082
0083 if ( olen != outputlength_in_bytes)
0084 {
0085 COUT << __FILE__ << " " << __LINE__ << " wrong-sized buffer: " << olen << " should be " << outputlength_in_bytes << std::endl;
0086 is_good = 0;
0087
0088
0089
0090 }
0091 if ( bufferarray[1]== BUFFERMARKER || buffer::u4swap(bufferarray[1])== BUFFERMARKER )
0092 {
0093 theBuffer = new prdfBuffer(bufferarray, outputlength);
0094 }
0095 else if ( bufferarray[1]== ONCSBUFFERMARKER || buffer::u4swap(bufferarray[1])== ONCSBUFFERMARKER )
0096 {
0097 theBuffer = new oncsBuffer(bufferarray, outputlength);
0098 }
0099 else
0100 {
0101 theBuffer = 0;
0102 }
0103 }
0104
0105
0106 Event * lzobuffer::getEvent()
0107 {
0108 if ( theBuffer) return theBuffer->getEvent();
0109 return 0;
0110 }
0111
0112
0113 int lzobuffer::getBufferSequence() const
0114 {
0115 if ( !theBuffer) return 0;
0116 return theBuffer->getBufferSequence();
0117 }
0118
0119
0120
0121 lzobuffer::~lzobuffer()
0122 {
0123 if ( theBuffer) delete theBuffer;
0124 if ( bufferarray) delete [] bufferarray;
0125 }
0126
0127