EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Deflate.h File Reference
#include "utils/Buffer.h"
Include dependency graph for Deflate.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool IsDeflated (const Buffer &data)
 Checks whether given data is deflated. More...
 
bool DeflateData (Buffer &data)
 Deflates given data. More...
 
bool DeflateData (const Buffer &input, Buffer &output)
 Deflates given data. More...
 
bool InflateData (Buffer &data)
 Inflates given data. More...
 
bool InflateData (const Buffer &input, Buffer &output)
 Inflates given data. More...
 

Variables

const uint8 DeflateHeaderByte
 

Function Documentation

bool DeflateData ( Buffer data)

Deflates given data.

Parameters
[in,out]dataData to be deflated, overwritten by result.
Return values
trueDeflation ran successfully.
falseError occurred during deflation.

Definition at line 37 of file Deflate.cpp.

References DeflateData().

Referenced by DeflateData(), MarshalDeflate(), and MailDB::SendMail().

38 {
39  Buffer dataDeflated;
40  if( !DeflateData( data, dataDeflated ) )
41  return false;
42 
43  data = dataDeflated;
44  return true;
45 }
Generic class for buffers.
Definition: Buffer.h:40
bool DeflateData(Buffer &data)
Deflates given data.
Definition: Deflate.cpp:37

Here is the call graph for this function:

Here is the caller graph for this function:

bool DeflateData ( const Buffer input,
Buffer output 
)

Deflates given data.

Parameters
[in]inputData to be deflated.
[out]outputDestination of deflated data.
Return values
trueDeflation ran successfully.
falseError occurred during deflation.

Definition at line 47 of file Deflate.cpp.

References Buffer::end(), Buffer::ResizeAt(), and Buffer::size().

48 {
49  const Buffer::iterator<uint8> out = output.end<uint8>();
50 
51  size_t outputSize = compressBound( input.size() );
52  output.ResizeAt( out, outputSize );
53 
54  int res = compress( &*out, (uLongf*)&outputSize, &input[0], input.size() );
55 
56  if( Z_OK == res )
57  {
58  output.ResizeAt( out, outputSize );
59  return true;
60  }
61  else
62  {
63  output.ResizeAt( out, 0 );
64  return false;
65  }
66 }
void ResizeAt(const_iterator< T > index, size_type requiredCount, const uint8 &fill=0)
Resizes buffer.
Definition: Buffer.h:688
unsigned __int8 uint8
Definition: eve-compat.h:46
size_type size() const
Definition: Buffer.h:610
Buffer's iterator.
Definition: Buffer.h:232
iterator< T > end()
Definition: Buffer.h:387

Here is the call graph for this function:

bool InflateData ( Buffer data)

Inflates given data.

Parameters
[in,out]dataData to be inflated, overwritten by result.
Return values
trueInflation ran successfully.
falseFailed to inflate data.

Definition at line 68 of file Deflate.cpp.

References InflateData().

Referenced by InflateData(), and InflateUnmarshal().

69 {
70  Buffer dataInflated;
71  if( !InflateData( data, dataInflated ) )
72  return false;
73 
74  data = dataInflated;
75  return true;
76 }
Generic class for buffers.
Definition: Buffer.h:40
bool InflateData(Buffer &data)
Inflates given data.
Definition: Deflate.cpp:68

Here is the call graph for this function:

Here is the caller graph for this function:

bool InflateData ( const Buffer input,
Buffer output 
)

Inflates given data.

One of the key things of the ZLIB stuff is that we 'sometimes' don't know the size of the uncompressed data. My idea is to fix this regarding the first phase of the parsing of the data (the parser) is to go trough a couple of output buffer size.

The first buffer size would be 2x the initial buffer size, implying that the compression ratio is about 50%. The second buffer size would be 4x the initial buffer size, implying that the compression ratio is about 75%. The third buffer size would be 8x the initial buffer size implying that the compression ratio is about 87.5%.

We would go on in this progress until we find buffer size big enough to hold uncompressed data.

This theory is really stupid because there is no way to actually know.

Parameters
[in]inputData to be inflated.
[out]outputDestination for inflated data.
Return values
trueInflation ran successfully.
falseFailed to inflate data.

Definition at line 78 of file Deflate.cpp.

References Buffer::end(), Buffer::ResizeAt(), and Buffer::size().

79 {
80  const Buffer::iterator<uint8> out = output.end<uint8>();
81 
82  size_t outputSize = 0;
83  size_t sizeMultiplier = 0;
84 
85  int res = 0;
86  do
87  {
88  outputSize = ( input.size() << ++sizeMultiplier );
89  output.ResizeAt( out, outputSize );
90 
91  res = uncompress( &*out, (uLongf*)&outputSize, &input[0], input.size() );
92  } while( Z_BUF_ERROR == res );
93 
94  if( Z_OK == res )
95  {
96  output.ResizeAt( out, outputSize );
97  return true;
98  }
99  else
100  {
101  output.ResizeAt( out, 0 );
102  return false;
103  }
104 }
void ResizeAt(const_iterator< T > index, size_type requiredCount, const uint8 &fill=0)
Resizes buffer.
Definition: Buffer.h:688
unsigned __int8 uint8
Definition: eve-compat.h:46
size_type size() const
Definition: Buffer.h:610
Buffer's iterator.
Definition: Buffer.h:232
iterator< T > end()
Definition: Buffer.h:387

Here is the call graph for this function:

bool IsDeflated ( const Buffer data)

Checks whether given data is deflated.

Parameters
[in]dataData to be checked.
Return values
trueData is deflated.
falseData is not deflated.

Definition at line 32 of file Deflate.cpp.

References DeflateHeaderByte.

Referenced by InflateUnmarshal().

33 {
34  return ( DeflateHeaderByte == data[0] );
35 }
const uint8 DeflateHeaderByte
Definition: Deflate.cpp:30

Here is the caller graph for this function:

Variable Documentation

const uint8 DeflateHeaderByte

Definition at line 30 of file Deflate.cpp.

Referenced by IsDeflated().