-
Notifications
You must be signed in to change notification settings - Fork 26
/
lzobuffer.cc
127 lines (101 loc) · 3.12 KB
/
lzobuffer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "lzobuffer.h"
#include "lzo/lzoutil.h"
#include "oncsBuffer.h"
int lzobuffer::lzo_initialized = 0;
// the constructor first ----------------
lzobuffer::lzobuffer (PHDWORD *array , const int length )
{
if ( ! lzo_initialized )
{
if (lzo_init() != LZO_E_OK)
{
COUT << "Could not initialize LZO" << std::endl;
_broken = 1;
}
lzo_initialized = 1;
}
is_good =1;
bufferarray=0;
theBuffer=0;
lzo_uint bytes;
lzo_uint outputlength_in_bytes;
if (array[1] == LZO1XBUFFERMARKER ||
array[1] == LZO1CBUFFERMARKER ||
array[1] == LZO2ABUFFERMARKER )
{
bytes = array[0]-4*BUFFERHEADERLENGTH;
outputlength_in_bytes = array[3];
}
else if ( u4swap(array[1]) == LZO1XBUFFERMARKER
|| u4swap(array[1]) == LZO1CBUFFERMARKER
|| u4swap(array[1]) == LZO2ABUFFERMARKER)
{
bytes = i4swap(array[0])-16;
outputlength_in_bytes = i4swap(array[3]);
}
else
{
COUT << __FILE__ << " " << __LINE__ << " wrong buffer marker = " << std::hex << array[1] << std::dec << std::endl;
is_good = 0;
return;
}
int outputlength = (outputlength_in_bytes+3)/4;
bufferarray = new PHDWORD[outputlength];
lzo_uint olen;
// std::cout << __FILE__ << " " << __LINE__ << " safe!!! array length before is " << array[-1] << std::endl;
olen = outputlength_in_bytes;
if (array[1] == LZO1XBUFFERMARKER || u4swap(array[1]) == LZO1XBUFFERMARKER )
{
lzo1x_decompress_safe ( (lzo_byte *) &array[4], bytes,
(lzo_byte *) bufferarray, &olen, NULL );
}
else if (array[1] == LZO1CBUFFERMARKER || u4swap(array[1]) == LZO1CBUFFERMARKER )
{
lzo1c_decompress_safe ( (lzo_byte *) &array[4], bytes,
(lzo_byte *) bufferarray, &olen, NULL );
}
else
{
lzo2a_decompress_safe ( (lzo_byte *) &array[4], bytes,
(lzo_byte *) bufferarray, &olen, NULL );
}
// std::cout << __FILE__ << " " << __LINE__ << " array length after is " << array[-1] << std::endl;
if ( olen != outputlength_in_bytes)
{
COUT << __FILE__ << " " << __LINE__ << " wrong-sized buffer: " << olen << " should be " << outputlength_in_bytes << std::endl;
is_good = 0;
// delete [] bufferarray;
// bufferarray = 0;
// return;
}
if ( bufferarray[1]== BUFFERMARKER || buffer::u4swap(bufferarray[1])== BUFFERMARKER )
{
theBuffer = new prdfBuffer(bufferarray, outputlength);
}
else if ( bufferarray[1]== ONCSBUFFERMARKER || buffer::u4swap(bufferarray[1])== ONCSBUFFERMARKER )
{
theBuffer = new oncsBuffer(bufferarray, outputlength);
}
else
{
theBuffer = 0;
}
}
// ---------------------------------------------------------
Event * lzobuffer::getEvent()
{
if ( theBuffer) return theBuffer->getEvent();
return 0;
}
// ---------------------------------------------------------
int lzobuffer::getBufferSequence() const
{
if ( !theBuffer) return 0;
return theBuffer->getBufferSequence();
}
// ---------------------------------------------------------
lzobuffer::~lzobuffer()
{
if ( theBuffer) delete theBuffer;
if ( bufferarray) delete [] bufferarray;
}