SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | List of all members
SLNet::StringCompressor Class Reference

Writes and reads strings to and from bitstreams. More...

`#include <slikenet/StringCompressor.h>`

## Public Member Functions

| ~StringCompressor ()
void | GenerateTreeFromStrings (unsigned char *input, unsigned inputLength, uint8_t languageId)
void | EncodeString (const char *input, int maxCharsToWrite, SLNet::BitStream *output, uint8_t languageId=0)
bool | DecodeString (char *output, int maxCharsToWrite, SLNet::BitStream *input, uint8_t languageId=0)
void | EncodeString (const SLNet::RakString *input, int maxCharsToWrite, SLNet::BitStream *output, uint8_t languageId=0)
bool | DecodeString (SLNet::RakString *output, int maxCharsToWrite, SLNet::BitStream *input, uint8_t languageId=0)
| StringCompressor ()

## Static Public Member Functions

static StringCompressor * | Instance (void)
static void | AddReference (void)
| Used so I can allocate and deallocate this singleton at runtime.
static void | RemoveReference (void)
| Used so I can allocate and deallocate this singleton at runtime.

## Detailed Description

Writes and reads strings to and from bitstreams.

Only works with ASCII strings. The default compression is for English. You can call GenerateTreeFromStrings to compress and decompress other languages efficiently as well.

Definition at line 51 of file StringCompressor.h.

## Constructor & Destructor Documentation

StringCompressor::~StringCompressor | ( |  | ) |

Definition at line 365 of file StringCompressor.cpp.

References _FILE_AND_LINE_, SLNet::OP_DELETE(), and DataStructures::Map< key_type, data_type, key_comparison_func >::Size().

StringCompressor::StringCompressor | ( |  | ) |

Definition at line 327 of file StringCompressor.cpp.

References _FILE_AND_LINE_, englishCharacterFrequencies, SLNet::HuffmanEncodingTree::GenerateFromFrequencyTable(), DataStructures::Map< key_type, data_type, key_comparison_func >::IMPLEMENT_DEFAULT_COMPARISON(), and DataStructures::Map< key_type, data_type, key_comparison_func >::Set().

## Member Function Documentation

void StringCompressor::AddReference | ( | void |  | ) |

static

Used so I can allocate and deallocate this singleton at runtime.

Definition at line 41 of file StringCompressor.cpp.

References _FILE_AND_LINE_.

Referenced by SLNet::RakPeer::RakPeer().

bool StringCompressor::DecodeString | ( | char * | output,
|  | int | maxCharsToWrite,
|  | SLNet::BitStream * | input,
|  | uint8_t | languageId = `0`
| ) |  |

Writes input to output, uncompressed. Takes care of the null terminator for you.

Parameters

  [out] | output | A block of bytes to receive the output
  [in] | maxCharsToWrite | Size, in bytes, of output . A NULL terminator will always be appended to the output string. If the maxCharsToWrite is not large enough, the string will be truncated.
  [in] | input | The bitstream containing the compressed string
  [in] | languageID | Which language to use

Definition at line 404 of file StringCompressor.cpp.

References SLNet::HuffmanEncodingTree::DecodeArray(), DataStructures::Map< key_type, data_type, key_comparison_func >::Get(), SLNet::BitStream::GetNumberOfUnreadBits(), DataStructures::Map< key_type, data_type, key_comparison_func >::Has(), and SLNet::BitStream::ReadCompressed().

Referenced by SLNet::StringTable::DecodeString(), DecodeString(), SLNet::TableSerializer::DeserializeColumns(), SLNet::RakString::DeserializeCompressed(), and SLNet::TableSerializer::DeserializeFilterQuery().

bool StringCompressor::DecodeString | ( | SLNet::RakString * | output,
|  | int | maxCharsToWrite,
|  | SLNet::BitStream * | input,
|  | uint8_t | languageId = `0`
| ) |  |

Definition at line 486 of file StringCompressor.cpp.

References _FILE_AND_LINE_, SLNet::RakString::Clear(), DecodeString(), MAX_ALLOCA_STACK_ALLOCATION, rakFree_Ex, and rakMalloc_Ex.

void StringCompressor::EncodeString | ( | const char * | input,
|  | int | maxCharsToWrite,
|  | SLNet::BitStream * | output,
|  | uint8_t | languageId = `0`
| ) |  |

Writes input to output, compressed. Takes care of the null terminator for you.

Parameters

  [in] | input | Pointer to an ASCII string
  [in] | maxCharsToWrite | The max number of bytes to write of input. Use 0 to mean no limit.
  [out] | output | The bitstream to write the compressed string to
  [in] | languageID | Which language to use

Definition at line 371 of file StringCompressor.cpp.

References SLNet::HuffmanEncodingTree::EncodeArray(), DataStructures::Map< key_type, data_type, key_comparison_func >::Get(), SLNet::BitStream::GetData(), SLNet::BitStream::GetNumberOfBitsUsed(), DataStructures::Map< key_type, data_type, key_comparison_func >::Has(), return, SLNet::BitStream::WriteBits(), and SLNet::BitStream::WriteCompressed().

Referenced by SLNet::StringTable::EncodeString(), EncodeString(), SLNet::TableSerializer::SerializeCell(), SLNet::TableSerializer::SerializeColumns(), SLNet::RakString::SerializeCompressed(), and SLNet::TableSerializer::SerializeFilterQuery().

void StringCompressor::EncodeString | ( | const SLNet::RakString * | input,
|  | int | maxCharsToWrite,
|  | SLNet::BitStream * | output,
|  | uint8_t | languageId = `0`
| ) |  |

Definition at line 482 of file StringCompressor.cpp.

References SLNet::RakString::C_String(), and EncodeString().

void StringCompressor::GenerateTreeFromStrings | ( | unsigned char * | input,
|  | unsigned | inputLength,
|  | uint8_t | languageId
| ) |  |

Given an array of strings, such as a chat log, generate the optimal encoding tree for it. This function is optional and if it is not called a default tree will be used instead.

Parameters

  [in] | input | An array of bytes which should point to text.
  [in] | inputLength | Length of input
  [in] | languageID | An identifier for the language / string table to generate the tree for. English is automatically created with ID 0 in the constructor.

Definition at line 337 of file StringCompressor.cpp.

References _FILE_AND_LINE_, SLNet::HuffmanEncodingTree::GenerateFromFrequencyTable(), DataStructures::Map< key_type, data_type, key_comparison_func >::Get(), DataStructures::Map< key_type, data_type, key_comparison_func >::Has(), SLNet::OP_DELETE(), return, and DataStructures::Map< key_type, data_type, key_comparison_func >::Set().

StringCompressor * StringCompressor::Instance | ( | void |  | ) |

static

static function because only static functions can access static members The RakPeer constructor adds a reference to this class, so don't call this until an instance of RakPeer exists, or unless you call AddReference yourself.

Returns
  the unique instance of the StringCompressor

Definition at line 62 of file StringCompressor.cpp.

Referenced by SLNet::StringTable::DecodeString(), SLNet::TableSerializer::DeserializeCell(), SLNet::TableSerializer::DeserializeColumns(), SLNet::RakString::DeserializeCompressed(), SLNet::TableSerializer::DeserializeFilterQuery(), SLNet::StringTable::EncodeString(), SLNet::TableSerializer::SerializeCell(), SLNet::TableSerializer::SerializeColumns(), SLNet::RakString::SerializeCompressed(), and SLNet::TableSerializer::SerializeFilterQuery().

void StringCompressor::RemoveReference | ( | void |  | ) |

static

Used so I can allocate and deallocate this singleton at runtime.

Definition at line 48 of file StringCompressor.cpp.

References _FILE_AND_LINE_, SLNet::OP_DELETE(), and RakAssert.

Referenced by SLNet::RakPeer::~RakPeer().

The documentation for this class was generated from the following files:

- Source/include/slikenet/StringCompressor.h
- Source/src/StringCompressor.cpp