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::BitStream Class Reference

`#include <slikenet/BitStream.h>`

## Public Member Functions

| BitStream ()
| Default Constructor.
| BitStream (const unsigned int initialBytesToAllocate)
| Create the bitstream, with some number of bytes to immediately allocate.
| BitStream (unsigned char *_data, const unsigned int lengthInBytes, bool _copyData)
| Initialize the BitStream, immediately setting the data it contains to a predefined pointer.
| ~BitStream ()
void | Reset (void)
| Resets the bitstream for reuse.
template<class templateType >
bool | Serialize (bool writeToBitstream, templateType &inOutTemplateVar)
| Bidirectional serialize/deserialize any integral type to/from a bitstream.
template<class templateType >
bool | SerializeDelta (bool writeToBitstream, templateType &inOutCurrentValue, const templateType &lastValue)
| Bidirectional serialize/deserialize any integral type to/from a bitstream.
template<class templateType >
bool | SerializeDelta (bool writeToBitstream, templateType &inOutCurrentValue)
| Bidirectional version of SerializeDelta when you don't know what the last value is, or there is no last value.
template<class templateType >
bool | SerializeCompressed (bool writeToBitstream, templateType &inOutTemplateVar)
| Bidirectional serialize/deserialize any integral type to/from a bitstream.
template<class templateType >
bool | SerializeCompressedDelta (bool writeToBitstream, templateType &inOutCurrentValue, const templateType &lastValue)
| Bidirectional serialize/deserialize any integral type to/from a bitstream.
template<class templateType >
bool | SerializeCompressedDelta (bool writeToBitstream, templateType &inOutTemplateVar)
| Save as SerializeCompressedDelta(templateType &currentValue, const templateType &lastValue) when we have an unknown second parameter.
bool | Serialize (bool writeToBitstream, char *inOutByteArray, const unsigned int numberOfBytes)
| Bidirectional serialize/deserialize an array or casted stream or raw data. This does NOT do endian swapping.
bool | SerializeFloat16 (bool writeToBitstream, float &inOutFloat, float floatMin, float floatMax)
| Serialize a float into 2 bytes, spanning the range between floatMin and floatMax.
template<class serializationType , class sourceType >
bool | SerializeCasted (bool writeToBitstream, sourceType &value)
template<class templateType >
bool | SerializeBitsFromIntegerRange (bool writeToBitstream, templateType &value, const templateType minimum, const templateType maximum, bool allowOutsideRange=false)
template<class templateType >
bool | SerializeBitsFromIntegerRange (bool writeToBitstream, templateType &value, const templateType minimum, const templateType maximum, const int requiredBits, bool allowOutsideRange=false)
template<class templateType >
bool | SerializeNormVector (bool writeToBitstream, templateType &x, templateType &y, templateType &z)
| Bidirectional serialize/deserialize a normalized 3D vector, using (at most) 4 bytes + 3 bits instead of 12-24 bytes.
template<class templateType >
bool | SerializeVector (bool writeToBitstream, templateType &x, templateType &y, templateType &z)
| Bidirectional serialize/deserialize a vector, using 10 bytes instead of 12.
template<class templateType >
bool | SerializeNormQuat (bool writeToBitstream, templateType &w, templateType &x, templateType &y, templateType &z)
| Bidirectional serialize/deserialize a normalized quaternion in 6 bytes + 4 bits instead of 16 bytes. Slightly lossy.
template<class templateType >
bool | SerializeOrthMatrix (bool writeToBitstream, templateType &m00, templateType &m01, templateType &m02, templateType &m10, templateType &m11, templateType &m12, templateType &m20, templateType &m21, templateType &m22)
| Bidirectional serialize/deserialize an orthogonal matrix by creating a quaternion, and writing 3 components of the quaternion in 2 bytes each.
bool | SerializeBits (bool writeToBitstream, unsigned char *inOutByteArray, const BitSize_t numberOfBitsToSerialize, const bool rightAlignedBits=true)
| Bidirectional serialize/deserialize numberToSerialize bits to/from the input.
template<class templateType >
void | Write (const templateType &inTemplateVar)
| Write any integral type to a bitstream.
template<class templateType >
void | WritePtr (templateType *inTemplateVar)
| Write the dereferenced pointer to any integral type to a bitstream.
template<class templateType >
void | WriteDelta (const templateType &currentValue, const templateType &lastValue)
| Write any integral type to a bitstream.
template<class templateType >
void | WriteDelta (const templateType &currentValue)
| WriteDelta when you don't know what the last value is, or there is no last value.
template<class templateType >
void | WriteCompressed (const templateType &inTemplateVar)
| Write any integral type to a bitstream.
template<class templateType >
void | WriteCompressedDelta (const templateType &currentValue, const templateType &lastValue)
| Write any integral type to a bitstream.
template<class templateType >
void | WriteCompressedDelta (const templateType &currentValue)
| Save as WriteCompressedDelta(const templateType &currentValue, const templateType &lastValue) when we have an unknown second parameter.
template<class templateType >
bool | Read (templateType &outTemplateVar)
| Read any integral type from a bitstream.
bool | Read (wchar_t *&varString)
| Read a wchar from a bitstream.
bool | Read (wchar_t *&varString, size_t varStringLength)
template<class templateType >
bool | ReadDelta (templateType &outTemplateVar)
| Read any integral type from a bitstream.
template<class templateType >
bool | ReadCompressed (templateType &outTemplateVar)
| Read any integral type from a bitstream.
bool | ReadCompressed (wchar_t *&varString)
| Read a wchar from a bitstream.
bool | ReadCompressed (wchar_t *&varString, size_t varStringLength)
template<class templateType >
bool | ReadCompressedDelta (templateType &outTemplateVar)
| Read any integral type from a bitstream.
bool | Read (BitStream *bitStream, BitSize_t numberOfBits)
| Read one bitstream to another.
bool | Read (BitStream *bitStream)
bool | Read (BitStream &bitStream, BitSize_t numberOfBits)
bool | Read (BitStream &bitStream)
void | Write (const char *inputByteArray, const unsigned int numberOfBytes)
| Write an array or casted stream or raw data. This does NOT do endian swapping.
void | Write (BitStream *bitStream, BitSize_t numberOfBits)
| Write one bitstream to another.
void | Write (BitStream *bitStream)
void | Write (BitStream &bitStream, BitSize_t numberOfBits)
void | Write (BitStream &bitStream)
void | WriteFloat16 (float x, float floatMin, float floatMax)
| Write a float into 2 bytes, spanning the range between floatMin and floatMax.
template<class serializationType , class sourceType >
void | WriteCasted (const sourceType &value)
template<class templateType >
void | WriteBitsFromIntegerRange (const templateType value, const templateType minimum, const templateType maximum, bool allowOutsideRange=false)
template<class templateType >
void | WriteBitsFromIntegerRange (const templateType value, const templateType minimum, const templateType maximum, const int requiredBits, bool allowOutsideRange=false)
template<class templateType >
void | WriteNormVector (templateType x, templateType y, templateType z)
| Write a normalized 3D vector, using (at most) 4 bytes + 3 bits instead of 12-24 bytes.
template<class templateType >
void | WriteVector (templateType x, templateType y, templateType z)
| Write a vector, using 10 bytes instead of 12.
template<class templateType >
void | WriteNormQuat (templateType w, templateType x, templateType y, templateType z)
| Write a normalized quaternion in 6 bytes + 4 bits instead of 16 bytes. Slightly lossy.
template<class templateType >
void | WriteOrthMatrix (templateType m00, templateType m01, templateType m02, templateType m10, templateType m11, templateType m12, templateType m20, templateType m21, templateType m22)
| Write an orthogonal matrix by creating a quaternion, and writing 3 components of the quaternion in 2 bytes each.
bool | Read (char *output, const unsigned int numberOfBytes)
| Read an array or casted stream of byte.
bool | ReadFloat16 (float &outFloat, float floatMin, float floatMax)
| Read a float into 2 bytes, spanning the range between floatMin and floatMax.
template<class serializationType , class sourceType >
bool | ReadCasted (sourceType &value)
template<class templateType >
bool | ReadBitsFromIntegerRange (templateType &value, const templateType minimum, const templateType maximum, bool allowOutsideRange=false)
template<class templateType >
bool | ReadBitsFromIntegerRange (templateType &value, const templateType minimum, const templateType maximum, const int requiredBits, bool allowOutsideRange=false)
template<class templateType >
bool | ReadNormVector (templateType &x, templateType &y, templateType &z)
| Read a normalized 3D vector, using (at most) 4 bytes + 3 bits instead of 12-24 bytes.
template<class templateType >
bool | ReadVector (templateType &x, templateType &y, templateType &z)
| Read 3 floats or doubles, using 10 bytes, where those float or doubles comprise a vector.
template<class templateType >
bool | ReadNormQuat (templateType &w, templateType &x, templateType &y, templateType &z)
| Read a normalized quaternion in 6 bytes + 4 bits instead of 16 bytes.
template<class templateType >
bool | ReadOrthMatrix (templateType &m00, templateType &m01, templateType &m02, templateType &m10, templateType &m11, templateType &m12, templateType &m20, templateType &m21, templateType &m22)
| Read an orthogonal matrix from a quaternion, reading 3 components of the quaternion in 2 bytes each and extrapolatig the 4th.
void | ResetReadPointer (void)
| Sets the read pointer back to the beginning of your data.
void | ResetWritePointer (void)
| Sets the write pointer back to the beginning of your data.
void | AssertStreamEmpty (void)
| This is good to call when you are done with the stream to make sure you didn't leave any data left over void.
void | PrintBits (char *out) const
| RAKNET_DEBUG_PRINTF the bits in the stream. Great for debugging.
void | PrintBits (char *out, size_t outLength) const
void | PrintBits (void) const
void | PrintHex (char *out) const
void | PrintHex (char *out, size_t outLength) const
void | PrintHex (void) const
void | IgnoreBits (const BitSize_t numberOfBits)
| Ignore data we don't intend to read.
void | IgnoreBytes (const unsigned int numberOfBytes)
| Ignore data we don't intend to read.
void | SetWriteOffset (const BitSize_t offset)
| Move the write pointer to a position on the array.
BitSize_t | GetNumberOfBitsUsed (void) const
| Returns the length in bits of the stream.
BitSize_t | GetWriteOffset (void) const
BitSize_t | GetNumberOfBytesUsed (void) const
| Returns the length in bytes of the stream.
BitSize_t | GetReadOffset (void) const
| Returns the number of bits into the stream that we have read.
void | SetReadOffset (const BitSize_t newReadOffset)
| Sets the read bit index.
BitSize_t | GetNumberOfUnreadBits (void) const
| Returns the number of bits left in the stream that haven't been read.
BitSize_t | CopyData (unsigned char **_data) const
| Makes a copy of the internal data for you _data will point to the stream. Partial bytes are left aligned.
void | SetData (unsigned char *inByteArray)
unsigned char * | GetData (void) const
void | WriteBits (const unsigned char *inByteArray, BitSize_t numberOfBitsToWrite, const bool rightAlignedBits=true)
| Write numberToWrite bits from the input source.
void | WriteAlignedBytes (const unsigned char *inByteArray, const unsigned int numberOfBytesToWrite)
| Align the bitstream to the byte boundary and then write the specified number of bits.
void | EndianSwapBytes (int byteOffset, int length)
void | WriteAlignedBytesSafe (const char *inByteArray, const unsigned int inputLength, const unsigned int maxBytesToWrite)
| Aligns the bitstream, writes inputLength, and writes input. Won't write beyond maxBytesToWrite.
bool | ReadAlignedBytes (unsigned char *inOutByteArray, const unsigned int numberOfBytesToRead)
| Read bits, starting at the next aligned bits.
bool | ReadAlignedBytesSafe (char *inOutByteArray, int &inputLength, const int maxBytesToRead)
| Reads what was written by WriteAlignedBytesSafe.
bool | ReadAlignedBytesSafe (char *inOutByteArray, unsigned int &inputLength, const unsigned int maxBytesToRead)
bool | ReadAlignedBytesSafeAlloc (char **outByteArray, int &inputLength, const unsigned int maxBytesToRead)
| Same as ReadAlignedBytesSafe() but allocates the memory for you using new, rather than assuming it is safe to write to.
bool | ReadAlignedBytesSafeAlloc (char **outByteArray, unsigned int &inputLength, const unsigned int maxBytesToRead)
void | AlignWriteToByteBoundary (void)
| Align the next write and/or read to a byte boundary.
void | AlignReadToByteBoundary (void)
| Align the next write and/or read to a byte boundary.
bool | ReadBits (unsigned char *inOutByteArray, BitSize_t numberOfBitsToRead, const bool alignBitsToRight=true)
| Read numberOfBitsToRead bits to the output source.
void | Write0 (void)
| Write a 0.
void | Write1 (void)
| Write a 1.
bool | ReadBit (void)
| Reads 1 bit and returns true if that bit is 1 and false if it is 0.
void | AssertCopyData (void)
| If we used the constructor version with copy data off, this *makes sure it is set to on and the data pointed to is copied.
void | SetNumberOfBitsAllocated (const BitSize_t lengthInBits)
| Use this if you pass a pointer copy to the constructor *(_copyData==false) and want to overallocate to prevent reallocation.
void | AddBitsAndReallocate (const BitSize_t numberOfBitsToWrite)
| Reallocates (if necessary) in preparation of writing numberOfBitsToWrite.
BitSize_t | GetNumberOfBitsAllocated (void) const
bool | Read (char *varString)
| Read strings, non reference.
bool | Read (unsigned char *varString)
void | PadWithZeroToByteLength (unsigned int bytes)
| Write zeros until the bitstream is filled up to bytes.
void | WriteAlignedVar8 (const char *inByteArray)
bool | ReadAlignedVar8 (char *inOutByteArray)
void | WriteAlignedVar16 (const char *inByteArray)
bool | ReadAlignedVar16 (char *inOutByteArray)
void | WriteAlignedVar32 (const char *inByteArray)
bool | ReadAlignedVar32 (char *inOutByteArray)
void | Write (const char *const inStringVar)
void | Write (const wchar_t *const inStringVar)
void | Write (const unsigned char *const inTemplateVar)
void | Write (char *const inTemplateVar)
void | Write (unsigned char *const inTemplateVar)
void | WriteCompressed (const char *const inStringVar)
void | WriteCompressed (const wchar_t *const inStringVar)
void | WriteCompressed (const unsigned char *const inTemplateVar)
void | WriteCompressed (char *const inTemplateVar)
void | WriteCompressed (unsigned char *const inTemplateVar)
template<>
void | Write (const bool &inTemplateVar)
| Write a bool to a bitstream.
template<>
void | Write (const SystemAddress &inTemplateVar)
| Write a systemAddress to a bitstream.
template<>
void | Write (const uint24_t &inTemplateVar)
template<>
void | Write (const RakNetGUID &inTemplateVar)
template<>
void | Write (const RakString &inTemplateVar)
| Write a string to a bitstream.
template<>
void | Write (const RakWString &inTemplateVar)
template<>
void | Write (const char *const &inStringVar)
template<>
void | Write (const wchar_t *const &inStringVar)
template<>
void | Write (const unsigned char *const &inTemplateVar)
template<>
void | Write (char *const &inTemplateVar)
template<>
void | Write (unsigned char *const &inTemplateVar)
template<>
void | WriteDelta (const bool &currentValue, const bool &lastValue)
| Write a bool delta. Same thing as just calling Write.
template<>
void | WriteCompressed (const SystemAddress &inTemplateVar)
template<>
void | WriteCompressed (const RakNetGUID &inTemplateVar)
template<>
void | WriteCompressed (const uint24_t &var)
template<>
void | WriteCompressed (const bool &inTemplateVar)
template<>
void | WriteCompressed (const float &inTemplateVar)
| For values between -1 and 1.
template<>
void | WriteCompressed (const double &inTemplateVar)
| For values between -1 and 1.
template<>
void | WriteCompressed (const RakString &inTemplateVar)
| Compress the string.
template<>
void | WriteCompressed (const RakWString &inTemplateVar)
template<>
void | WriteCompressed (const char *const &inStringVar)
template<>
void | WriteCompressed (const wchar_t *const &inStringVar)
template<>
void | WriteCompressed (const unsigned char *const &inTemplateVar)
template<>
void | WriteCompressed (char *const &inTemplateVar)
template<>
void | WriteCompressed (unsigned char *const &inTemplateVar)
template<>
void | WriteCompressedDelta (const bool &currentValue, const bool &lastValue)
| Write a bool delta. Same thing as just calling Write.
template<>
void | WriteCompressedDelta (const bool &currentValue)
| Save as WriteCompressedDelta(bool currentValue, const templateType &lastValue) when we have an unknown second bool.
template<>
bool | Read (bool &outTemplateVar)
| Read a bool from a bitstream.
template<>
bool | Read (SystemAddress &outTemplateVar)
| Read a systemAddress from a bitstream.
template<>
bool | Read (uint24_t &outTemplateVar)
template<>
bool | Read (RakNetGUID &outTemplateVar)
template<>
bool | Read (RakString &outTemplateVar)
template<>
bool | Read (RakWString &outTemplateVar)
template<>
bool | Read (char *&varString)
template<>
bool | Read (unsigned char *&varString)
template<>
bool | ReadDelta (bool &outTemplateVar)
| Read a bool from a bitstream.
template<>
bool | ReadCompressed (SystemAddress &outTemplateVar)
template<>
bool | ReadCompressed (uint24_t &outTemplateVar)
template<>
bool | ReadCompressed (RakNetGUID &outTemplateVar)
template<>
bool | ReadCompressed (bool &outTemplateVar)
template<>
bool | ReadCompressed (float &outTemplateVar)
| For values between -1 and 1.
template<>
bool | ReadCompressed (double &outTemplateVar)
| For values between -1 and 1.
template<>
bool | ReadCompressed (RakString &outTemplateVar)
| For strings.
template<>
bool | ReadCompressed (RakWString &outTemplateVar)
template<>
bool | ReadCompressed (char *&outTemplateVar)
template<>
bool | ReadCompressed (unsigned char *&outTemplateVar)
template<>
bool | ReadCompressedDelta (bool &outTemplateVar)
| Read a bool from a bitstream.

## Static Public Member Functions

static int | NumberOfLeadingZeroes (uint8_t x)
static int | NumberOfLeadingZeroes (uint16_t x)
static int | NumberOfLeadingZeroes (uint32_t x)
static int | NumberOfLeadingZeroes (uint64_t x)
static int | NumberOfLeadingZeroes (int8_t x)
static int | NumberOfLeadingZeroes (int16_t x)
static int | NumberOfLeadingZeroes (int32_t x)
static int | NumberOfLeadingZeroes (int64_t x)
static bool | DoEndianSwap (void)
| -— Member function template specialization declarations -—
static bool | IsBigEndian (void)
static bool | IsNetworkOrder (void)
static bool | IsNetworkOrderInternal (void)
static void | ReverseBytes (unsigned char *inByteArray, unsigned char *inOutByteArray, const unsigned int length)
static void | ReverseBytesInPlace (unsigned char *inOutData, const unsigned int length)

## Detailed Description

This class allows you to write and read native types as a string of bits. BitStream is used extensively throughout RakNet and is designed to be used by users as well.

See Also
  BitStreamSample.txt

Definition at line 47 of file BitStream.h.

## Constructor & Destructor Documentation

BitStream::BitStream | ( |  | ) |

Default Constructor.

Definition at line 60 of file BitStream.cpp.

References BITSTREAM_STACK_ALLOCATION_SIZE.

BitStream::BitStream | ( | const unsigned int | initialBytesToAllocate | ) |

Create the bitstream, with some number of bytes to immediately allocate.

There is no benefit to calling this, unless you know exactly how many bytes you need and it is greater than BITSTREAM_STACK_ALLOCATION_SIZE. In that case all it does is save you one or more realloc calls.

Parameters

  [in] | initialBytesToAllocate | the number of bytes to pre-allocate.

Definition at line 76 of file BitStream.cpp.

References _FILE_AND_LINE_, BITSTREAM_STACK_ALLOCATION_SIZE, RakAssert, and rakMalloc_Ex.

BitStream::BitStream | ( | unsigned char * | _data,
|  | const unsigned int | lengthInBytes,
|  | bool | _copyData
| ) |  |

Initialize the BitStream, immediately setting the data it contains to a predefined pointer.

Set _copyData to true if you want to make an internal copy of the data you are passing. Set it to false to just save a pointer to the data. You shouldn't call Write functions with _copyData as false, as this will write to unallocated memory 99% of the time you will use this function to cast Packet::data to a bitstream for reading, in which case you should write something as follows:

SLNet::BitStream bs(packet->data, packet->length, false);

Parameters

  [in] | _data | An array of bytes.
  [in] | lengthInBytes | Size of the _data.
  [in] | _copyData | true or false to make a copy of _data or not.

Definition at line 97 of file BitStream.cpp.

References _FILE_AND_LINE_, BITSTREAM_STACK_ALLOCATION_SIZE, RakAssert, and rakMalloc_Ex.

BitStream::~BitStream | ( |  | ) |

Definition at line 138 of file BitStream.cpp.

References _FILE_AND_LINE_, BITSTREAM_STACK_ALLOCATION_SIZE, and rakFree_Ex.

## Member Function Documentation

void BitStream::AddBitsAndReallocate | ( | const BitSize_t | numberOfBitsToWrite | ) |

Reallocates (if necessary) in preparation of writing numberOfBitsToWrite.

Cap to 1 meg buffer to save on huge allocations

Definition at line 697 of file BitStream.cpp.

References _FILE_AND_LINE_, BITS_TO_BYTES, BITSTREAM_STACK_ALLOCATION_SIZE, RakAssert, rakMalloc_Ex, and rakRealloc_Ex.

Referenced by PadWithZeroToByteLength(), Write(), Write0(), Write1(), WriteAlignedVar16(), WriteAlignedVar32(), WriteAlignedVar8(), and WriteBits().

void SLNet::BitStream::AlignReadToByteBoundary | ( | void |  | ) |

inline

Align the next write and/or read to a byte boundary.

This can be used to 'waste' bits to byte align for efficiency reasons It can also be used to force coalesced bitstreams to start on byte boundaries so so WriteAlignedBits and ReadAlignedBits both calculate the same offset when aligning.

Definition at line 614 of file BitStream.h.

Referenced by SLNet::DataCompressor::DecompressAndAllocate(), DataStructures::RangeList< range_type >::Deserialize(), SLNet::RakString::Deserialize(), SLNet::TableSerializer::DeserializeCell(), Read(), and ReadAlignedBytes().

void SLNet::BitStream::AlignWriteToByteBoundary | ( | void |  | ) |

inline

Align the next write and/or read to a byte boundary.

This can be used to 'waste' bits to byte align for efficiency reasons It can also be used to force coalesced bitstreams to start on byte boundaries so so WriteAlignedBits and ReadAlignedBits both calculate the same offset when aligning.

Definition at line 607 of file BitStream.h.

Referenced by PadWithZeroToByteLength(), DataStructures::RangeList< range_type >::Serialize(), Write(), and WriteAlignedBytes().

void BitStream::AssertCopyData | ( | void |  | ) |

If we used the constructor version with copy data off, this *makes sure it is set to on and the data pointed to is copied.

Definition at line 1032 of file BitStream.cpp.

References _FILE_AND_LINE_, BITS_TO_BYTES, RakAssert, and rakMalloc_Ex.

void BitStream::AssertStreamEmpty | ( | void |  | ) |

This is good to call when you are done with the stream to make sure you didn't leave any data left over void.

Definition at line 841 of file BitStream.cpp.

References RakAssert.

BitSize_t BitStream::CopyData | ( | unsigned char ** | _data | ) | const

Makes a copy of the internal data for you _data will point to the stream. Partial bytes are left aligned.

Parameters

  [out] | _data | The allocated copy of GetData()

Returns
  The length in bits of the stream.

Definition at line 959 of file BitStream.cpp.

References _FILE_AND_LINE_, BITS_TO_BYTES, RakAssert, and rakMalloc_Ex.

Referenced by SLNet::HuffmanEncodingTree::GenerateFromFrequencyTable().

static bool SLNet::BitStream::DoEndianSwap | ( | void |  | ) |

inlinestatic

-— Member function template specialization declarations -—

Definition at line 724 of file BitStream.h.

Referenced by EndianSwapBytes(), Read(), ReadAlignedVar16(), ReadAlignedVar32(), ReadCompressed(), Write(), WriteAlignedVar16(), WriteAlignedVar32(), WriteCompressed(), and WritePtr().

void BitStream::EndianSwapBytes | ( | int | byteOffset,
|  | int | length
| ) |  |

Definition at line 351 of file BitStream.cpp.

References DoEndianSwap(), and ReverseBytesInPlace().

unsigned char* SLNet::BitStream::GetData | ( | void |  | ) | const

inline

Gets the data that BitStream is writing to / reading from. Partial bytes are left aligned.

Returns
  A pointer to the internal state

Definition at line 549 of file BitStream.h.

Referenced by SLNet::RakPeer::AdvertiseSystem(), SLNet::TableSerializer::DeserializeCell(), SLNet::StringCompressor::EncodeString(), SLNet::RakPeer::GetOfflinePingResponse(), SLNet::RakPeer::NotifyAndFlagForShutdown(), SLNet::RakPeer::OnConnectionRequest(), SLNet::RakPeer::ParseConnectionRequestPacket(), SLNet::RakPeer::PingInternal(), SLNet::ProcessOfflineNetworkPacket(), SLNet::RakPeer::RunUpdateCycle(), SLNet::RakPeer::Send(), SLNet::RakPeer::SendOutOfBand(), SLNet::PluginInterface2::SendUnified(), Write(), and SLNet::VariableListDeltaTracker::WriteVar().

BitSize_t BitStream::GetNumberOfBitsAllocated | ( | void |  | ) | const

Definition at line 744 of file BitStream.cpp.

BitSize_t SLNet::BitStream::GetNumberOfBitsUsed | ( | void |  | ) | const

inline

Returns the length in bits of the stream.

Definition at line 521 of file BitStream.h.

Referenced by SLNet::HuffmanEncodingTree::EncodeArray(), SLNet::StringCompressor::EncodeString(), SLNet::RakPeer::NotifyAndFlagForShutdown(), SLNet::RakPeer::OnConnectionRequest(), SLNet::RakPeer::PingInternal(), SLNet::ProcessOfflineNetworkPacket(), SLNet::RakPeer::RunUpdateCycle(), SLNet::RakPeer::Send(), SLNet::PluginInterface2::SendUnified(), DataStructures::RangeList< range_type >::Serialize(), and Write().

BitSize_t SLNet::BitStream::GetNumberOfBytesUsed | ( | void |  | ) | const

inline

Returns the length in bytes of the stream.

Definition at line 525 of file BitStream.h.

References BITS_TO_BYTES.

Referenced by SLNet::RakPeer::AdvertiseSystem(), SLNet::RakPeer::GetOfflinePingResponse(), PadWithZeroToByteLength(), SLNet::RakPeer::ParseConnectionRequestPacket(), PrintHex(), SLNet::ProcessOfflineNetworkPacket(), SLNet::RakPeer::RunUpdateCycle(), SLNet::RakPeer::Send(), SLNet::RakPeer::SendOutOfBand(), SLNet::PluginInterface2::SendUnified(), SLNet::ReliabilityLayer::Update(), and SLNet::VariableListDeltaTracker::WriteVar().

BitSize_t SLNet::BitStream::GetNumberOfUnreadBits | ( | void |  | ) | const

inline

Returns the number of bits left in the stream that haven't been read.

Definition at line 534 of file BitStream.h.

Referenced by SLNet::StringCompressor::DecodeString(), SLNet::TableSerializer::DeserializeCell(), Read(), ReadAlignedBytes(), ReadAlignedVar16(), ReadAlignedVar32(), ReadAlignedVar8(), ReadBit(), ReadBits(), and Write().

BitSize_t SLNet::BitStream::GetReadOffset | ( | void |  | ) | const

inline

Returns the number of bits into the stream that we have read.

Definition at line 528 of file BitStream.h.

Referenced by SLNet::TableSerializer::DeserializeCell(), SLNet::RakPeer::ParseConnectionRequestPacket(), and Write().

BitSize_t SLNet::BitStream::GetWriteOffset | ( | void |  | ) | const

inline

Definition at line 522 of file BitStream.h.

Referenced by DataStructures::RangeList< range_type >::Serialize().

void BitStream::IgnoreBits | ( | const BitSize_t | numberOfBits | ) |

Ignore data we don't intend to read.

Parameters

  [in] | numberOfBits | The number of bits to ignore

Definition at line 971 of file BitStream.cpp.

Referenced by SLNet::TableSerializer::DeserializeCell(), SLNet::ReliabilityLayer::HandleSocketReceiveFromConnectedPlayer(), IgnoreBytes(), SLNet::ProcessOfflineNetworkPacket(), and SLNet::RakPeer::RunUpdateCycle().

void BitStream::IgnoreBytes | ( | const unsigned int | numberOfBytes | ) |

Ignore data we don't intend to read.

Parameters

  [in] | numberOfBits | The number of bytes to ignore

Definition at line 976 of file BitStream.cpp.

References BYTES_TO_BITS, and IgnoreBits().

Referenced by SLNet::RakPeer::ParseConnectionRequestPacket(), SLNet::ProcessOfflineNetworkPacket(), and SLNet::RakPeer::RunUpdateCycle().

static bool SLNet::BitStream::IsBigEndian | ( | void |  | ) |

inlinestatic

Definition at line 731 of file BitStream.h.

Referenced by Read(), ReadBitsFromIntegerRange(), Write(), and WriteBitsFromIntegerRange().

static bool SLNet::BitStream::IsNetworkOrder | ( | void |  | ) |

inlinestatic

Definition at line 735 of file BitStream.h.

Referenced by VariadicSQLParser::ExtractArguments().

bool BitStream::IsNetworkOrderInternal | ( | void |  | ) |

static

Definition at line 1054 of file BitStream.cpp.

int BitStream::NumberOfLeadingZeroes | ( | uint8_t | x | ) |

static

Get the number of leading zeros for a number

Parameters

  [in] | x | Number to test

Definition at line 786 of file BitStream.cpp.

Referenced by NumberOfLeadingZeroes(), ReadBitsFromIntegerRange(), SerializeBitsFromIntegerRange(), and WriteBitsFromIntegerRange().

int BitStream::NumberOfLeadingZeroes | ( | uint16_t | x | ) |

static

Definition at line 798 of file BitStream.cpp.

int BitStream::NumberOfLeadingZeroes | ( | uint32_t | x | ) |

static

Definition at line 811 of file BitStream.cpp.

int BitStream::NumberOfLeadingZeroes | ( | uint64_t | x | ) |

static

Definition at line 825 of file BitStream.cpp.

int BitStream::NumberOfLeadingZeroes | ( | int8_t | x | ) |

static

Definition at line 785 of file BitStream.cpp.

References NumberOfLeadingZeroes().

int BitStream::NumberOfLeadingZeroes | ( | int16_t | x | ) |

static

Definition at line 797 of file BitStream.cpp.

References NumberOfLeadingZeroes().

int BitStream::NumberOfLeadingZeroes | ( | int32_t | x | ) |

static

Definition at line 810 of file BitStream.cpp.

References NumberOfLeadingZeroes().

int BitStream::NumberOfLeadingZeroes | ( | int64_t | x | ) |

static

Definition at line 824 of file BitStream.cpp.

References NumberOfLeadingZeroes().

void BitStream::PadWithZeroToByteLength | ( | unsigned int | bytes | ) |

Write zeros until the bitstream is filled up to bytes.

Definition at line 748 of file BitStream.cpp.

References AddBitsAndReallocate(), AlignWriteToByteBoundary(), BITS_TO_BYTES, BYTES_TO_BITS, and GetNumberOfBytesUsed().

Referenced by SLNet::RakPeer::RunUpdateCycle(), and SLNet::ReliabilityLayer::Update().

void BitStream::PrintBits | ( | char * | out | ) | const

RAKNET_DEBUG_PRINTF the bits in the stream. Great for debugging.

Definition at line 846 of file BitStream.cpp.

References BITS_TO_BYTES.

void BitStream::PrintBits | ( | char * | out,
|  | size_t | outLength
| ) |  | const

Definition at line 886 of file BitStream.cpp.

References BITS_TO_BYTES.

void BitStream::PrintBits | ( | void |  | ) | const

Definition at line 922 of file BitStream.cpp.

References RAKNET_DEBUG_PRINTF.

void BitStream::PrintHex | ( | char * | out | ) | const

Definition at line 938 of file BitStream.cpp.

References GetNumberOfBytesUsed().

void BitStream::PrintHex | ( | char * | out,
|  | size_t | outLength
| ) |  | const

Definition at line 929 of file BitStream.cpp.

References GetNumberOfBytesUsed().

void BitStream::PrintHex | ( | void |  | ) | const

Definition at line 950 of file BitStream.cpp.

References RAKNET_DEBUG_PRINTF.

template<class templateType >

bool SLNet::BitStream::Read | ( | templateType & | outTemplateVar | ) |

inline

Read any integral type from a bitstream.

Read any integral type from a bitstream. Define __BITSTREAM_NATIVE_END if you need endian swapping.

Define __BITSTREAM_NATIVE_END if you need endian swapping.

Parameters

  [in] | outTemplateVar | The value to read

Returns
  true on success, false on failure.

Parameters

  [in] | outTemplateVar | The value to read

Definition at line 1279 of file BitStream.h.

References DoEndianSwap(), ReadBits(), and ReverseBytes().

Referenced by SLNet::StringTable::DecodeString(), SLNet::DataCompressor::DecompressAndAllocate(), SLNet::RakNetRandomSync::Deserialize(), DataStructures::RangeList< range_type >::Deserialize(), SLNet::RakWString::Deserialize(), SLNet::RakString::Deserialize(), SLNet::TableSerializer::DeserializeCell(), SLNet::TableSerializer::DeserializeColumns(), SLNet::RakNetRandomSync::DeserializeConstruction(), SLNet::TableSerializer::DeserializeFilterQuery(), SLNet::TableSerializer::DeserializeFilterQueryList(), SLNet::TableSerializer::DeserializeRow(), SLNet::TableSerializer::DeserializeTable(), SLNet::ReliabilityLayer::HandleSocketReceiveFromConnectedPlayer(), operator>>(), SLNet::operator>>(), SLNet::RakPeer::ParseConnectionRequestPacket(), SLNet::ProcessOfflineNetworkPacket(), Read(), ReadBitsFromIntegerRange(), ReadCasted(), ReadCompressed(), ReadCompressedDelta(), ReadDelta(), ReadFloat16(), ReadNormQuat(), SLNet::VariableListDeltaTracker::ReadVarFromBitstream(), ReadVector(), SLNet::RakPeer::RunUpdateCycle(), Serialize(), and SLNet::RakPeer::ShiftIncomingTimestamp().

bool SLNet::BitStream::Read | ( | wchar_t *& | varString | ) |

inline

Read a wchar from a bitstream.

Define __BITSTREAM_NATIVE_END if you need endian swapping.

Parameters

  [in] | varString | The value to read
  [in] | varStringLength | The length of the given varString array (in wchar_t)

Returns
  true on success, false on failure.

Definition at line 1405 of file BitStream.h.

References SLNet::RakWString::Deserialize().

bool SLNet::BitStream::Read | ( | wchar_t *& | varString,
|  | size_t | varStringLength
| ) |  |

inline

Definition at line 1409 of file BitStream.h.

References SLNet::RakWString::Deserialize().

bool BitStream::Read | ( | BitStream * | bitStream,
|  | BitSize_t | numberOfBits
| ) |  |

Read one bitstream to another.

Parameters

  [in] | numberOfBits | bits to read
  | bitStream | the bitstream to read into from

Returns
  true on success, false on failure.

Definition at line 246 of file BitStream.cpp.

References GetNumberOfUnreadBits(), and Write().

bool BitStream::Read | ( | BitStream * | bitStream | ) |

Definition at line 253 of file BitStream.cpp.

References Write().

bool BitStream::Read | ( | BitStream & | bitStream,
|  | BitSize_t | numberOfBits
| ) |  |

Definition at line 258 of file BitStream.cpp.

References GetNumberOfUnreadBits(), and Write().

bool BitStream::Read | ( | BitStream & | bitStream | ) |

Definition at line 265 of file BitStream.cpp.

References Write().

bool BitStream::Read | ( | char * | output,
|  | const unsigned int | numberOfBytes
| ) |  |

Read an array or casted stream of byte.

The array is raw data. There is no automatic endian conversion with this function

Parameters

  [in] | output | The result byte array. It should be larger than numberOfBytes.
  [in] | numberOfBytes | The number of byte to read

Returns
  true on success false if there is some missing bytes.

Definition at line 272 of file BitStream.cpp.

References GetNumberOfUnreadBits(), and ReadBits().

bool BitStream::Read | ( | char * | varString | ) |

Read strings, non reference.

Definition at line 1082 of file BitStream.cpp.

References SLNet::RakString::Deserialize().

bool BitStream::Read | ( | unsigned char * | varString | ) |

Definition at line 1086 of file BitStream.cpp.

References SLNet::RakString::Deserialize().

template<>

bool SLNet::BitStream::Read | ( | bool & | outTemplateVar | ) |

inline

Read a bool from a bitstream.

Parameters

  [in] | outTemplateVar | The value to read

Definition at line 1308 of file BitStream.h.

References GetNumberOfUnreadBits().

template<>

bool SLNet::BitStream::Read | ( | SystemAddress & | outTemplateVar | ) |

inline

Read a systemAddress from a bitstream.

Parameters

  [in] | outTemplateVar | The value to read

Definition at line 1327 of file BitStream.h.

References SLNet::SystemAddress::address, SLNet::SystemAddress::debugPort, Read(), and ReadBits().

template<>

bool SLNet::BitStream::Read | ( | uint24_t & | outTemplateVar | ) |

inline

Definition at line 1357 of file BitStream.h.

References AlignReadToByteBoundary(), GetNumberOfUnreadBits(), IsBigEndian(), and SLNet::uint24_t::val.

template<>

bool SLNet::BitStream::Read | ( | RakNetGUID & | outTemplateVar | ) |

inline

Definition at line 1384 of file BitStream.h.

References SLNet::RakNetGUID::g, and Read().

template<>

bool SLNet::BitStream::Read | ( | RakString & | outTemplateVar | ) |

inline

Definition at line 1391 of file BitStream.h.

References SLNet::RakString::Deserialize().

template<>

bool SLNet::BitStream::Read | ( | RakWString & | outTemplateVar | ) |

inline

Definition at line 1396 of file BitStream.h.

References SLNet::RakWString::Deserialize().

template<>

bool SLNet::BitStream::Read | ( | char *& | varString | ) |

inline

Definition at line 1401 of file BitStream.h.

References SLNet::RakString::Deserialize().

template<>

bool SLNet::BitStream::Read | ( | unsigned char *& | varString | ) |

inline

Definition at line 1414 of file BitStream.h.

References SLNet::RakString::Deserialize().

bool BitStream::ReadAlignedBytes | ( | unsigned char * | inOutByteArray,
|  | const unsigned int | numberOfBytesToRead
| ) |  |

Read bits, starting at the next aligned bits.

Note that the modulus 8 starting offset of the sequence must be the same as was used with WriteBits. This will be a problem with packet coalescence unless you byte align the coalesced packets.

Parameters

  [in] | inOutByteArray | The byte array larger than numberOfBytesToRead
  [in] | numberOfBytesToRead | The number of byte to read from the internal state

Returns
  true if there is enough byte.

Definition at line 373 of file BitStream.cpp.

References AlignReadToByteBoundary(), GetNumberOfUnreadBits(), and RakAssert.

Referenced by SLNet::RakWString::Deserialize(), SLNet::RakString::Deserialize(), SLNet::RakPeer::ParseConnectionRequestPacket(), SLNet::ProcessOfflineNetworkPacket(), ReadAlignedBytesSafe(), and ReadAlignedBytesSafeAlloc().

bool BitStream::ReadAlignedBytesSafe | ( | char * | inOutByteArray,
|  | int & | inputLength,
|  | const int | maxBytesToRead
| ) |  |

Reads what was written by WriteAlignedBytesSafe.

Parameters

  [in] | inOutByteArray | The data
  [in] | maxBytesToRead | Maximum number of bytes to read

Returns
  true on success, false on failure.

Definition at line 395 of file BitStream.cpp.

bool BitStream::ReadAlignedBytesSafe | ( | char * | inOutByteArray,
|  | unsigned int & | inputLength,
|  | const unsigned int | maxBytesToRead
| ) |  |

Definition at line 399 of file BitStream.cpp.

References ReadAlignedBytes(), and ReadCompressed().

bool BitStream::ReadAlignedBytesSafeAlloc | ( | char ** | outByteArray,
|  | int & | inputLength,
|  | const unsigned int | maxBytesToRead
| ) |  |

Same as ReadAlignedBytesSafe() but allocates the memory for you using new, rather than assuming it is safe to write to.

Parameters

  [in] | outByteArray | outByteArray will be deleted if it is not a pointer to 0

Returns
  true on success, false on failure.

Definition at line 409 of file BitStream.cpp.

Referenced by SLNet::TableSerializer::DeserializeFilterQuery().

bool BitStream::ReadAlignedBytesSafeAlloc | ( | char ** | outByteArray,
|  | unsigned int & | inputLength,
|  | const unsigned int | maxBytesToRead
| ) |  |

Definition at line 413 of file BitStream.cpp.

References _FILE_AND_LINE_, rakFree_Ex, rakMalloc_Ex, ReadAlignedBytes(), and ReadCompressed().

bool BitStream::ReadAlignedVar16 | ( | char * | inOutByteArray | ) |

Definition at line 1126 of file BitStream.cpp.

References DoEndianSwap(), GetNumberOfUnreadBits(), and RakAssert.

bool BitStream::ReadAlignedVar32 | ( | char * | inOutByteArray | ) |

Definition at line 1170 of file BitStream.cpp.

References DoEndianSwap(), GetNumberOfUnreadBits(), and RakAssert.

bool BitStream::ReadAlignedVar8 | ( | char * | inOutByteArray | ) |

Definition at line 1097 of file BitStream.cpp.

References GetNumberOfUnreadBits(), and RakAssert.

bool BitStream::ReadBit | ( | void |  | ) |

Reads 1 bit and returns true if that bit is 1 and false if it is 0.

Definition at line 332 of file BitStream.cpp.

References GetNumberOfUnreadBits().

Referenced by SLNet::HuffmanEncodingTree::DecodeArray().

bool BitStream::ReadBits | ( | unsigned char * | inOutByteArray,
|  | BitSize_t | numberOfBitsToRead,
|  | const bool | alignBitsToRight = `true`
| ) |  |

Read numberOfBitsToRead bits to the output source.

alignBitsToRight should be set to true to convert internal bitstream data to userdata. It should be false if you used WriteBits with rightAlignedBits false

Parameters

  [in] | inOutByteArray | The resulting bits array
  [in] | numberOfBitsToRead | The number of bits to read
  [in] | alignBitsToRight | if true bits will be right aligned.

Returns
  true if there is enough bits to read

Definition at line 555 of file BitStream.cpp.

References BITS_TO_BYTES, and GetNumberOfUnreadBits().

Referenced by Read(), ReadBitsFromIntegerRange(), and SerializeBits().

template<class templateType >

bool SLNet::BitStream::ReadBitsFromIntegerRange | ( | templateType & | value,
|  | const templateType | minimum,
|  | const templateType | maximum,
|  | bool | allowOutsideRange = `false`
| ) |  |

Given the minimum and maximum values for an integer type, figure out the minimum number of bits to represent the range Then read only those bits

Note
  A static is used so that the required number of bits for (maximum-minimum) is only calculated once. This does require that minimum and are fixed values for a given line of code for the life of the program

Parameters

  [in] | value | Integer value to read, which should be between minimum and maximum
  [in] | minimum | Minimum value of value
  [in] | maximum | Maximum value of value
  [in] | allowOutsideRange | If true, all sends will take an extra bit, however value can deviate from outside minimum and maximum. If false, will assert if the value deviates. This should match the corresponding value passed to Write().

Definition at line 1714 of file BitStream.h.

References BYTES_TO_BITS, and NumberOfLeadingZeroes().

Referenced by SerializeBitsFromIntegerRange().

template<class templateType >

bool SLNet::BitStream::ReadBitsFromIntegerRange | ( | templateType & | value,
|  | const templateType | minimum,
|  | const templateType | maximum,
|  | const int | requiredBits,
|  | bool | allowOutsideRange = `false`
| ) |  |

Parameters

  [in] | requiredBits | Primarily for internal use, called from above function() after calculating number of bits needed to represent maximum-minimum

Definition at line 1720 of file BitStream.h.

References IsBigEndian(), RakAssert, Read(), ReadBits(), and ReverseBytesInPlace().

template<class serializationType , class sourceType >

bool SLNet::BitStream::ReadCasted | ( | sourceType & | value | ) |

Read one type serialized to another (smaller) type, to save bandwidth serializationType should be uint8_t, uint16_t, uint24_t, or uint32_t Example: int num; ReadCasted<uint8_t>(num); would read 1 bytefrom the stream, and put the value in an integer

Parameters

  [in] | value | The value to write

Definition at line 1705 of file BitStream.h.

References Read().

Referenced by SLNet::RakWString::Deserialize().

template<class templateType >

bool SLNet::BitStream::ReadCompressed | ( | templateType & | outTemplateVar | ) |

inline

Read any integral type from a bitstream.

Undefine __BITSTREAM_NATIVE_END if you need endian swapping. For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte

Parameters

  [in] | outTemplateVar | The value to read

Returns
  true on success, false on failure.

Undefine __BITSTREAM_NATIVE_END if you need endian swapping. For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte

Parameters

  [in] | outTemplateVar | The value to read

Definition at line 1450 of file BitStream.h.

References DoEndianSwap(), and ReverseBytes().

Referenced by SLNet::StringCompressor::DecodeString(), SLNet::DataCompressor::DecompressAndAllocate(), SLNet::RakString::DeserializeCompressed(), SLNet::TableSerializer::DeserializeFilterQuery(), SLNet::TableSerializer::DeserializeFilterQueryList(), ReadAlignedBytesSafe(), ReadAlignedBytesSafeAlloc(), ReadCompressedDelta(), ReadVector(), and SerializeCompressed().

bool SLNet::BitStream::ReadCompressed | ( | wchar_t *& | varString | ) |

inline

Read a wchar from a bitstream.

Define __BITSTREAM_NATIVE_END if you need endian swapping. This is lossless, but only has benefit if you use less than half the bits of the type If you are not using __BITSTREAM_NATIVE_END the opposite is true

Parameters

  [in] | varString | The value to read
  [in] | varStringLength | The length of the given varString array (in wchar_t)

Returns
  true on success, false on failure.

Definition at line 1542 of file BitStream.h.

References SLNet::RakWString::Deserialize().

bool SLNet::BitStream::ReadCompressed | ( | wchar_t *& | varString,
|  | size_t | varStringLength
| ) |  |

inline

Definition at line 1546 of file BitStream.h.

References SLNet::RakWString::Deserialize().

template<>

bool SLNet::BitStream::ReadCompressed | ( | SystemAddress & | outTemplateVar | ) |

inline

Definition at line 1477 of file BitStream.h.

References Read().

template<>

bool SLNet::BitStream::ReadCompressed | ( | uint24_t & | outTemplateVar | ) |

inline

Definition at line 1483 of file BitStream.h.

References Read().

template<>

bool SLNet::BitStream::ReadCompressed | ( | RakNetGUID & | outTemplateVar | ) |

inline

Definition at line 1489 of file BitStream.h.

References Read().

template<>

bool SLNet::BitStream::ReadCompressed | ( | bool & | outTemplateVar | ) |

inline

Definition at line 1495 of file BitStream.h.

References Read().

template<>

bool SLNet::BitStream::ReadCompressed | ( | float & | outTemplateVar | ) |

inline

For values between -1 and 1.

Definition at line 1502 of file BitStream.h.

References Read().

template<>

bool SLNet::BitStream::ReadCompressed | ( | double & | outTemplateVar | ) |

inline

For values between -1 and 1.

Definition at line 1515 of file BitStream.h.

References Read().

template<>

bool SLNet::BitStream::ReadCompressed | ( | RakString & | outTemplateVar | ) |

inline

For strings.

Definition at line 1528 of file BitStream.h.

References SLNet::RakString::DeserializeCompressed().

template<>

bool SLNet::BitStream::ReadCompressed | ( | RakWString & | outTemplateVar | ) |

inline

Definition at line 1533 of file BitStream.h.

References SLNet::RakWString::Deserialize().

template<>

bool SLNet::BitStream::ReadCompressed | ( | char *& | outTemplateVar | ) |

inline

Definition at line 1538 of file BitStream.h.

References SLNet::RakString::DeserializeCompressed().

template<>

bool SLNet::BitStream::ReadCompressed | ( | unsigned char *& | outTemplateVar | ) |

inline

Definition at line 1551 of file BitStream.h.

References SLNet::RakString::DeserializeCompressed().

template<class templateType >

bool SLNet::BitStream::ReadCompressedDelta | ( | templateType & | outTemplateVar | ) |

inline

Read any integral type from a bitstream.

If the written value differed from the value compared against in the write function, var will be updated. Otherwise it will retain the current value. the current value will be updated. For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte ReadCompressedDelta is only valid from a previous call to WriteDelta

Parameters

  [in] | outTemplateVar | The value to read

Returns
  true on success, false on failure.

If the written value differed from the value compared against in the write function, var will be updated. Otherwise it will retain the current value. the current value will be updated. For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte ReadCompressedDelta is only valid from a previous call to WriteDelta

Parameters

  [in] | outTemplateVar | The value to read

Definition at line 1566 of file BitStream.h.

References Read(), and ReadCompressed().

Referenced by SerializeCompressedDelta().

template<>

bool SLNet::BitStream::ReadCompressedDelta | ( | bool & | outTemplateVar | ) |

inline

Read a bool from a bitstream.

Parameters

  [in] | outTemplateVar | The value to read

Definition at line 1579 of file BitStream.h.

References Read().

template<class templateType >

bool SLNet::BitStream::ReadDelta | ( | templateType & | outTemplateVar | ) |

inline

Read any integral type from a bitstream.

If the written value differed from the value compared against in the write function, var will be updated. Otherwise it will retain the current value. ReadDelta is only valid from a previous call to WriteDelta

Parameters

  [in] | outTemplateVar | The value to read

Returns
  true on success, false on failure.

If the written value differed from the value compared against in the write function, var will be updated. Otherwise it will retain the current value. ReadDelta is only valid from a previous call to WriteDelta

Parameters

  [in] | outTemplateVar | The value to read

Definition at line 1425 of file BitStream.h.

References Read().

Referenced by SerializeDelta().

template<>

bool SLNet::BitStream::ReadDelta | ( | bool & | outTemplateVar | ) |

inline

Read a bool from a bitstream.

Parameters

  [in] | outTemplateVar | The value to read

Definition at line 1438 of file BitStream.h.

References Read().

bool BitStream::ReadFloat16 | ( | float & | outFloat,
|  | float | floatMin,
|  | float | floatMax
| ) |  |

Read a float into 2 bytes, spanning the range between floatMin and floatMax.

Parameters

  [in] | outFloat | The float to read
  [in] | floatMin | Predetermined minimum value of f
  [in] | floatMax | Predetermined maximum value of f

Definition at line 1195 of file BitStream.cpp.

References RakAssert, and Read().

Referenced by ReadNormVector(), and SerializeFloat16().

template<class templateType >

bool SLNet::BitStream::ReadNormQuat | ( | templateType & | w,
|  | templateType & | x,
|  | templateType & | y,
|  | templateType & | z
| ) |  |

Read a normalized quaternion in 6 bytes + 4 bits instead of 16 bytes.

Parameters

  [in] | w | w
  [in] | x | x
  [in] | y | y
  [in] | z | z

Returns
  true on success, false on failure.

Definition at line 1796 of file BitStream.h.

References Read().

Referenced by ReadOrthMatrix(), and SerializeNormQuat().

template<class templateType >

bool SLNet::BitStream::ReadNormVector | ( | templateType & | x,
|  | templateType & | y,
|  | templateType & | z
| ) |  |

Read a normalized 3D vector, using (at most) 4 bytes + 3 bits instead of 12-24 bytes.

Will further compress y or z axis aligned vectors. Accurate to 1/32767.5.

Parameters

  [in] | x | x
  [in] | y | y
  [in] | z | z

Returns
  true on success, false on failure.

Definition at line 1746 of file BitStream.h.

References ReadFloat16().

Referenced by SerializeNormVector().

template<class templateType >

bool SLNet::BitStream::ReadOrthMatrix | ( | templateType & | m00,
|  | templateType & | m01,
|  | templateType & | m02,
|  | templateType & | m10,
|  | templateType & | m11,
|  | templateType & | m12,
|  | templateType & | m20,
|  | templateType & | m21,
|  | templateType & | m22
| ) |  |

Read an orthogonal matrix from a quaternion, reading 3 components of the quaternion in 2 bytes each and extrapolatig the 4th.

Use 6 bytes instead of 36 Lossy, although the result is renormalized

Returns
  true on success, false on failure.

Definition at line 1827 of file BitStream.h.

References ReadNormQuat().

Referenced by SerializeOrthMatrix().

template<class templateType >

bool SLNet::BitStream::ReadVector | ( | templateType & | x,
|  | templateType & | y,
|  | templateType & | z
| ) |  |

Read 3 floats or doubles, using 10 bytes, where those float or doubles comprise a vector.

Loses accuracy to about 3/10ths and only saves 2 bytes, so only use if accuracy is not important.

Parameters

  [in] | x | x
  [in] | y | y
  [in] | z | z

Returns
  true on success, false on failure.

Definition at line 1759 of file BitStream.h.

References Read(), and ReadCompressed().

Referenced by SerializeVector().

void BitStream::Reset | ( | void |  | ) |

Resets the bitstream for reuse.

Definition at line 144 of file BitStream.cpp.

Referenced by SLNet::VariableDeltaSerializer::EndSerialize(), SLNet::HuffmanEncodingTree::GenerateFromFrequencyTable(), SLNet::RakPeer::SetOfflinePingResponse(), and SLNet::ReliabilityLayer::Update().

void BitStream::ResetReadPointer | ( | void |  | ) |

Sets the read pointer back to the beginning of your data.

Definition at line 293 of file BitStream.cpp.

Referenced by SLNet::VariableDeltaSerializer::EndSerialize().

void BitStream::ResetWritePointer | ( | void |  | ) |

Sets the write pointer back to the beginning of your data.

Definition at line 299 of file BitStream.cpp.

Referenced by SLNet::ProcessOfflineNetworkPacket().

void BitStream::ReverseBytes | ( | unsigned char * | inByteArray,
|  | unsigned char * | inOutByteArray,
|  | const unsigned int | length
| ) |  |

static

Definition at line 1065 of file BitStream.cpp.

Referenced by Read(), ReadCompressed(), Write(), WriteBitsFromIntegerRange(), WriteCompressed(), and WritePtr().

void BitStream::ReverseBytesInPlace | ( | unsigned char * | inOutData,
|  | const unsigned int | length
| ) |  |

static

Definition at line 1070 of file BitStream.cpp.

Referenced by EndianSwapBytes(), VariadicSQLParser::ExtractArguments(), and ReadBitsFromIntegerRange().

template<class templateType >

bool SLNet::BitStream::Serialize | ( | bool | writeToBitstream,
|  | templateType & | inOutTemplateVar
| ) |  |

inline

Bidirectional serialize/deserialize any integral type to/from a bitstream.

Undefine __BITSTREAM_NATIVE_END if you need endian swapping.

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | inOutTemplateVar | The value to write

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 778 of file BitStream.h.

References Read(), and Write().

bool SLNet::BitStream::Serialize | ( | bool | writeToBitstream,
|  | char * | inOutByteArray,
|  | const unsigned int | numberOfBytes
| ) |  |

inline

Bidirectional serialize/deserialize an array or casted stream or raw data. This does NOT do endian swapping.

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | inOutByteArray | a byte buffer
  [in] | numberOfBytes | the size of input in bytes

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 837 of file BitStream.h.

References Read(), and Write().

bool SLNet::BitStream::SerializeBits | ( | bool | writeToBitstream,
|  | unsigned char * | inOutByteArray,
|  | const BitSize_t | numberOfBitsToSerialize,
|  | const bool | rightAlignedBits = `true`
| ) |  |

inline

Bidirectional serialize/deserialize numberToSerialize bits to/from the input.

Right aligned data means in the case of a partial byte, the bits are aligned from the right (bit 0) rather than the left (as in the normal internal representation) You would set this to true when writing user data, and false when copying bitstream data, such as writing one bitstream to another

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | inOutByteArray | The data
  [in] | numberOfBitsToSerialize | The number of bits to write
  [in] | rightAlignedBits | if true data will be right aligned

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 912 of file BitStream.h.

References ReadBits(), and WriteBits().

template<class templateType >

bool SLNet::BitStream::SerializeBitsFromIntegerRange | ( | bool | writeToBitstream,
|  | templateType & | value,
|  | const templateType | minimum,
|  | const templateType | maximum,
|  | bool | allowOutsideRange = `false`
| ) |  |

Given the minimum and maximum values for an integer type, figure out the minimum number of bits to represent the range Then serialize only those bits

Note
  A static is used so that the required number of bits for (maximum-minimum) is only calculated once. This does require that minimum and are fixed values for a given line of code for the life of the program

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | value | Integer value to write, which should be between minimum and maximum
  [in] | minimum | Minimum value of value
  [in] | maximum | Maximum value of value
  [in] | allowOutsideRange | If true, all sends will take an extra bit, however value can deviate from outside minimum and maximum. If false, will assert if the value deviates

Definition at line 855 of file BitStream.h.

References BYTES_TO_BITS, and NumberOfLeadingZeroes().

template<class templateType >

bool SLNet::BitStream::SerializeBitsFromIntegerRange | ( | bool | writeToBitstream,
|  | templateType & | value,
|  | const templateType | minimum,
|  | const templateType | maximum,
|  | const int | requiredBits,
|  | bool | allowOutsideRange = `false`
| ) |  |

Parameters

  [in] | requiredBits | Primarily for internal use, called from above function() after calculating number of bits needed to represent maximum-minimum

Definition at line 861 of file BitStream.h.

References ReadBitsFromIntegerRange(), and WriteBitsFromIntegerRange().

template<class serializationType , class sourceType >

bool SLNet::BitStream::SerializeCasted | ( | bool | writeToBitstream,
|  | sourceType & | value
| ) |  |

Serialize one type casted to another (smaller) type, to save bandwidth serializationType should be uint8_t, uint16_t, uint24_t, or uint32_t Example: int num=53; SerializeCasted<uint8_t>(true, num); would use 1 byte to write what would otherwise be an integer (4 or 8 bytes)

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | value | The value to serialize

Definition at line 847 of file BitStream.h.

template<class templateType >

bool SLNet::BitStream::SerializeCompressed | ( | bool | writeToBitstream,
|  | templateType & | inOutTemplateVar
| ) |  |

inline

Bidirectional serialize/deserialize any integral type to/from a bitstream.

Undefine __BITSTREAM_NATIVE_END if you need endian swapping. If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | inOutTemplateVar | The value to write

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 808 of file BitStream.h.

References ReadCompressed(), and WriteCompressed().

template<class templateType >

bool SLNet::BitStream::SerializeCompressedDelta | ( | bool | writeToBitstream,
|  | templateType & | inOutCurrentValue,
|  | const templateType & | lastValue
| ) |  |

inline

Bidirectional serialize/deserialize any integral type to/from a bitstream.

If the current value is different from the last value the current value will be written. Otherwise, a single bit will be written For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | inOutCurrentValue | The current value to write
  [in] | lastValue | The last value to compare against. Only used if writeToBitstream is true.

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 818 of file BitStream.h.

References ReadCompressedDelta(), and WriteCompressedDelta().

template<class templateType >

bool SLNet::BitStream::SerializeCompressedDelta | ( | bool | writeToBitstream,
|  | templateType & | inOutTemplateVar
| ) |  |

inline

Save as SerializeCompressedDelta(templateType &currentValue, const templateType &lastValue) when we have an unknown second parameter.

Returns
  true on data read. False on insufficient data in bitstream

Definition at line 828 of file BitStream.h.

References ReadCompressedDelta(), and WriteCompressedDelta().

template<class templateType >

bool SLNet::BitStream::SerializeDelta | ( | bool | writeToBitstream,
|  | templateType & | inOutCurrentValue,
|  | const templateType & | lastValue
| ) |  |

inline

Bidirectional serialize/deserialize any integral type to/from a bitstream.

If the current value is different from the last value the current value will be written. Otherwise, a single bit will be written

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | inOutCurrentValue | The current value to write
  [in] | lastValue | The last value to compare against. Only used if writeToBitstream is true.

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 788 of file BitStream.h.

References ReadDelta(), and WriteDelta().

template<class templateType >

bool SLNet::BitStream::SerializeDelta | ( | bool | writeToBitstream,
|  | templateType & | inOutCurrentValue
| ) |  |

inline

Bidirectional version of SerializeDelta when you don't know what the last value is, or there is no last value.

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | inOutCurrentValue | The current value to write

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 798 of file BitStream.h.

References ReadDelta(), and WriteDelta().

bool BitStream::SerializeFloat16 | ( | bool | writeToBitstream,
|  | float & | inOutFloat,
|  | float | floatMin,
|  | float | floatMax
| ) |  |

Serialize a float into 2 bytes, spanning the range between floatMin and floatMax.

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | inOutFloat | The float to write
  [in] | floatMin | Predetermined minimum value of f
  [in] | floatMax | Predetermined maximum value of f

Definition at line 1210 of file BitStream.cpp.

References ReadFloat16(), and WriteFloat16().

template<class templateType >

bool SLNet::BitStream::SerializeNormQuat | ( | bool | writeToBitstream,
|  | templateType & | w,
|  | templateType & | x,
|  | templateType & | y,
|  | templateType & | z
| ) |  |

inline

Bidirectional serialize/deserialize a normalized quaternion in 6 bytes + 4 bits instead of 16 bytes. Slightly lossy.

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | w | w
  [in] | x | x
  [in] | y | y
  [in] | z | z

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 889 of file BitStream.h.

References ReadNormQuat(), and WriteNormQuat().

template<class templateType >

bool SLNet::BitStream::SerializeNormVector | ( | bool | writeToBitstream,
|  | templateType & | x,
|  | templateType & | y,
|  | templateType & | z
| ) |  |

inline

Bidirectional serialize/deserialize a normalized 3D vector, using (at most) 4 bytes + 3 bits instead of 12-24 bytes.

Will further compress y or z axis aligned vectors. Accurate to 1/32767.5.

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | x | x
  [in] | y | y
  [in] | z | z

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 869 of file BitStream.h.

References ReadNormVector(), and WriteNormVector().

template<class templateType >

bool SLNet::BitStream::SerializeOrthMatrix | ( | bool | writeToBitstream,
|  | templateType & | m00,
|  | templateType & | m01,
|  | templateType & | m02,
|  | templateType & | m10,
|  | templateType & | m11,
|  | templateType & | m12,
|  | templateType & | m20,
|  | templateType & | m21,
|  | templateType & | m22
| ) |  |

inline

Bidirectional serialize/deserialize an orthogonal matrix by creating a quaternion, and writing 3 components of the quaternion in 2 bytes each.

Use 6 bytes instead of 36 Lossy, although the result is renormalized

Returns
  true on success, false on failure.

Definition at line 899 of file BitStream.h.

References ReadOrthMatrix(), and WriteOrthMatrix().

template<class templateType >

bool SLNet::BitStream::SerializeVector | ( | bool | writeToBitstream,
|  | templateType & | x,
|  | templateType & | y,
|  | templateType & | z
| ) |  |

inline

Bidirectional serialize/deserialize a vector, using 10 bytes instead of 12.

Loses accuracy to about 3/10ths and only saves 2 bytes, so only use if accuracy is not important.

Parameters

  [in] | writeToBitstream | true to write from your data to this bitstream. False to read from this bitstream and write to your data
  [in] | x | x
  [in] | y | y
  [in] | z | z

Returns
  true if writeToBitstream is true. true if writeToBitstream is false and the read was successful. false if writeToBitstream is false and the read was not successful.

Definition at line 879 of file BitStream.h.

References ReadVector(), and WriteVector().

void BitStream::SetData | ( | unsigned char * | inByteArray | ) |

Definition at line 486 of file BitStream.cpp.

void BitStream::SetNumberOfBitsAllocated | ( | const BitSize_t | lengthInBits | ) |

Use this if you pass a pointer copy to the constructor *(_copyData==false) and want to overallocate to prevent reallocation.

Definition at line 130 of file BitStream.cpp.

References RakAssert.

void SLNet::BitStream::SetReadOffset | ( | const BitSize_t | newReadOffset | ) |

inline

Sets the read bit index.

Definition at line 531 of file BitStream.h.

Referenced by Write().

void BitStream::SetWriteOffset | ( | const BitSize_t | offset | ) |

Move the write pointer to a position on the array.

Parameters

  [in] | offset | the offset from the start of the array.

Attention

Dangerous if you don't know what you are doing! For efficiency reasons you can only write mid-stream if your data is byte aligned.

Definition at line 983 of file BitStream.cpp.

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

template<class templateType >

void SLNet::BitStream::Write | ( | const templateType & | inTemplateVar | ) |

inline

Write any integral type to a bitstream.

Undefine __BITSTREAM_NATIVE_END if you need endian swapping.

Parameters

  [in] | inTemplateVar | The value to write

Definition at line 922 of file BitStream.h.

References DoEndianSwap(), ReverseBytes(), and WriteBits().

Referenced by SLNet::RakPeer::AdvertiseSystem(), SLNet::StringTable::EncodeString(), SLNet::VariableDeltaSerializer::EndSerialize(), SLNet::RakPeer::NotifyAndFlagForShutdown(), SLNet::RakPeer::OnConnectionRequest(), operator<<(), SLNet::operator<<(), SLNet::RakPeer::ParseConnectionRequestPacket(), SLNet::RakPeer::PingInternal(), SLNet::ProcessOfflineNetworkPacket(), Read(), SLNet::RakPeer::RunUpdateCycle(), SLNet::RakPeer::SendOutOfBand(), SLNet::RakNetRandomSync::Serialize(), DataStructures::RangeList< range_type >::Serialize(), Serialize(), SLNet::RakWString::Serialize(), SLNet::RakString::Serialize(), SLNet::TableSerializer::SerializeCell(), SLNet::TableSerializer::SerializeColumns(), SLNet::RakNetRandomSync::SerializeConstruction(), SLNet::TableSerializer::SerializeFilterQuery(), SLNet::TableSerializer::SerializeFilterQueryList(), SLNet::TableSerializer::SerializeRow(), SLNet::TableSerializer::SerializeTable(), SLNet::VariableDeltaSerializer::SerializeVariable(), SLNet::RakPeer::SetOfflinePingResponse(), SLNet::RakPeer::ShiftIncomingTimestamp(), Write(), WriteAlignedBytes(), WriteBitsFromIntegerRange(), WriteCasted(), WriteCompressed(), WriteCompressedDelta(), WriteDelta(), WriteFloat16(), WriteNormQuat(), SLNet::RakPeer::WriteOutOfBandHeader(), SLNet::VariableListDeltaTracker::WriteVar(), SLNet::VariableListDeltaTracker::WriteVarToBitstream(), and WriteVector().

void BitStream::Write | ( | const char * | inputByteArray,
|  | const unsigned int | numberOfBytes
| ) |  |

Write an array or casted stream or raw data. This does NOT do endian swapping.

Parameters

  [in] | inputByteArray | a byte buffer
  [in] | numberOfBytes | the size of input in bytes

Definition at line 168 of file BitStream.cpp.

References AddBitsAndReallocate(), BITS_TO_BYTES, BYTES_TO_BITS, and WriteBits().

void BitStream::Write | ( | BitStream * | bitStream,
|  | BitSize_t | numberOfBits
| ) |  |

Write one bitstream to another.

Parameters

  [in] | numberOfBits | bits to write
  | bitStream | the bitstream to copy from

Definition at line 190 of file BitStream.cpp.

References AddBitsAndReallocate(), BYTES_TO_BITS, GetData(), GetNumberOfUnreadBits(), GetReadOffset(), and SetReadOffset().

void BitStream::Write | ( | BitStream * | bitStream | ) |

Definition at line 186 of file BitStream.cpp.

References GetNumberOfBitsUsed(), GetReadOffset(), and Write().

void BitStream::Write | ( | BitStream & | bitStream,
|  | BitSize_t | numberOfBits
| ) |  |

Definition at line 238 of file BitStream.cpp.

References Write().

void BitStream::Write | ( | BitStream & | bitStream | ) |

Definition at line 242 of file BitStream.cpp.

References Write().

void SLNet::BitStream::Write | ( | const char *const | inStringVar | ) |

inline

Definition at line 682 of file BitStream.h.

References SLNet::RakString::Serialize().

void SLNet::BitStream::Write | ( | const wchar_t *const | inStringVar | ) |

inline

Definition at line 686 of file BitStream.h.

References SLNet::RakWString::Serialize().

void SLNet::BitStream::Write | ( | const unsigned char *const | inTemplateVar | ) |

inline

Definition at line 690 of file BitStream.h.

void SLNet::BitStream::Write | ( | char *const | inTemplateVar | ) |

inline

Definition at line 694 of file BitStream.h.

void SLNet::BitStream::Write | ( | unsigned char *const | inTemplateVar | ) |

inline

Definition at line 698 of file BitStream.h.

template<>

void SLNet::BitStream::Write | ( | const bool & | inTemplateVar | ) |

inline

Write a bool to a bitstream.

Parameters

  [in] | inTemplateVar | The value to write

Definition at line 970 of file BitStream.h.

References Write0(), and Write1().

template<>

void SLNet::BitStream::Write | ( | const SystemAddress & | inTemplateVar | ) |

inline

Write a systemAddress to a bitstream.

Parameters

  [in] | inTemplateVar | The value to write

Definition at line 982 of file BitStream.h.

References SLNet::SystemAddress::address, SLNet::SystemAddress::GetIPVersion(), SLNet::SystemAddress::GetPortNetworkOrder(), Write(), and WriteBits().

template<>

void SLNet::BitStream::Write | ( | const uint24_t & | inTemplateVar | ) |

inline

Definition at line 1005 of file BitStream.h.

References AddBitsAndReallocate(), AlignWriteToByteBoundary(), IsBigEndian(), and SLNet::uint24_t::val.

template<>

void SLNet::BitStream::Write | ( | const RakNetGUID & | inTemplateVar | ) |

inline

Definition at line 1027 of file BitStream.h.

References SLNet::RakNetGUID::g, and Write().

template<>

void SLNet::BitStream::Write | ( | const RakString & | inTemplateVar | ) |

inline

Write a string to a bitstream.

Parameters

  [in] | var | The value to write

Definition at line 1035 of file BitStream.h.

References SLNet::RakString::Serialize().

template<>

void SLNet::BitStream::Write | ( | const RakWString & | inTemplateVar | ) |

inline

Definition at line 1040 of file BitStream.h.

References SLNet::RakWString::Serialize().

template<>

void SLNet::BitStream::Write | ( | const char *const & | inStringVar | ) |

inline

Definition at line 1045 of file BitStream.h.

References SLNet::RakString::Serialize().

template<>

void SLNet::BitStream::Write | ( | const wchar_t *const & | inStringVar | ) |

inline

Definition at line 1050 of file BitStream.h.

References SLNet::RakWString::Serialize().

template<>

void SLNet::BitStream::Write | ( | const unsigned char *const & | inTemplateVar | ) |

inline

Definition at line 1055 of file BitStream.h.

References Write().

template<>

void SLNet::BitStream::Write | ( | char *const & | inTemplateVar | ) |

inline

Definition at line 1060 of file BitStream.h.

References Write().

template<>

void SLNet::BitStream::Write | ( | unsigned char *const & | inTemplateVar | ) |

inline

Definition at line 1065 of file BitStream.h.

References Write().

void BitStream::Write0 | ( | void |  | ) |

Write a 0.

Definition at line 305 of file BitStream.cpp.

References AddBitsAndReallocate().

Referenced by SLNet::HuffmanEncodingTree::GenerateFromFrequencyTable(), and Write().

void BitStream::Write1 | ( | void |  | ) |

Write a 1.

Definition at line 317 of file BitStream.cpp.

References AddBitsAndReallocate().

Referenced by SLNet::HuffmanEncodingTree::GenerateFromFrequencyTable(), and Write().

void BitStream::WriteAlignedBytes | ( | const unsigned char * | inByteArray,
|  | const unsigned int | numberOfBytesToWrite
| ) |  |

Align the bitstream to the byte boundary and then write the specified number of bits.

This is faster than WriteBits but wastes the bits to do the alignment and requires you to call ReadAlignedBits at the corresponding read position.

Parameters

  [in] | inByteArray | The data
  [in] | numberOfBytesToWrite | The size of input.

Definition at line 346 of file BitStream.cpp.

References AlignWriteToByteBoundary(), and Write().

Referenced by SLNet::RakPeer::AdvertiseSystem(), SLNet::ProcessOfflineNetworkPacket(), SLNet::RakPeer::RunUpdateCycle(), SLNet::RakWString::Serialize(), SLNet::RakString::Serialize(), SLNet::TableSerializer::SerializeCell(), WriteAlignedBytesSafe(), and SLNet::RakPeer::WriteOutOfBandHeader().

void BitStream::WriteAlignedBytesSafe | ( | const char * | inByteArray,
|  | const unsigned int | inputLength,
|  | const unsigned int | maxBytesToWrite
| ) |  |

Aligns the bitstream, writes inputLength, and writes input. Won't write beyond maxBytesToWrite.

Parameters

  [in] | inByteArray | The data
  [in] | inputLength | The size of input.
  [in] | maxBytesToWrite | Max bytes to write

Definition at line 359 of file BitStream.cpp.

References WriteAlignedBytes(), and WriteCompressed().

Referenced by SLNet::TableSerializer::SerializeFilterQuery().

void BitStream::WriteAlignedVar16 | ( | const char * | inByteArray | ) |

Definition at line 1107 of file BitStream.cpp.

References AddBitsAndReallocate(), DoEndianSwap(), and RakAssert.

void BitStream::WriteAlignedVar32 | ( | const char * | inByteArray | ) |

Definition at line 1147 of file BitStream.cpp.

References AddBitsAndReallocate(), DoEndianSwap(), and RakAssert.

void BitStream::WriteAlignedVar8 | ( | const char * | inByteArray | ) |

Definition at line 1090 of file BitStream.cpp.

References AddBitsAndReallocate(), and RakAssert.

void BitStream::WriteBits | ( | const unsigned char * | inByteArray,
|  | BitSize_t | numberOfBitsToWrite,
|  | const bool | rightAlignedBits = `true`
| ) |  |

Write numberToWrite bits from the input source.

Right aligned data means in the case of a partial byte, the bits are aligned from the right (bit 0) rather than the left (as in the normal internal representation) You would set this to true when writing user data, and false when copying bitstream data, such as writing one bitstream to another.

Parameters

  [in] | inByteArray | The data
  [in] | numberOfBitsToWrite | The number of bits to write
  [in] | rightAlignedBits | if true data will be right aligned

Definition at line 428 of file BitStream.cpp.

References AddBitsAndReallocate().

Referenced by SLNet::HuffmanEncodingTree::DecodeArray(), SLNet::HuffmanEncodingTree::EncodeArray(), SLNet::StringCompressor::EncodeString(), SerializeBits(), Write(), WriteBitsFromIntegerRange(), and WritePtr().

template<class templateType >

void SLNet::BitStream::WriteBitsFromIntegerRange | ( | const templateType | value,
|  | const templateType | minimum,
|  | const templateType | maximum,
|  | bool | allowOutsideRange = `false`
| ) |  |

Given the minimum and maximum values for an integer type, figure out the minimum number of bits to represent the range Then write only those bits

Note
  A static is used so that the required number of bits for (maximum-minimum) is only calculated once. This does require that minimum and are fixed values for a given line of code for the life of the program

Parameters

  [in] | value | Integer value to write, which should be between minimum and maximum
  [in] | minimum | Minimum value of value
  [in] | maximum | Maximum value of value
  [in] | allowOutsideRange | If true, all sends will take an extra bit, however value can deviate from outside minimum and maximum. If false, will assert if the value deviates. This should match the corresponding value passed to Read().

Definition at line 1592 of file BitStream.h.

References BYTES_TO_BITS, and NumberOfLeadingZeroes().

Referenced by SerializeBitsFromIntegerRange().

template<class templateType >

void SLNet::BitStream::WriteBitsFromIntegerRange | ( | const templateType | value,
|  | const templateType | minimum,
|  | const templateType | maximum,
|  | const int | requiredBits,
|  | bool | allowOutsideRange = `false`
| ) |  |

Parameters

  [in] | requiredBits | Primarily for internal use, called from above function() after calculating number of bits needed to represent maximum-minimum

Definition at line 1598 of file BitStream.h.

References IsBigEndian(), RakAssert, ReverseBytes(), Write(), and WriteBits().

template<class destinationType , class sourceType >

void SLNet::BitStream::WriteCasted | ( | const sourceType & | value | ) |

Write one type serialized as another (smaller) type, to save bandwidth serializationType should be uint8_t, uint16_t, uint24_t, or uint32_t Example: int num=53; WriteCasted<uint8_t>(num); would use 1 byte to write what would otherwise be an integer (4 or 8 bytes)

Parameters

  [in] | value | The value to write

Definition at line 1585 of file BitStream.h.

References Write().

Referenced by SLNet::ProcessOfflineNetworkPacket(), and SLNet::RakWString::Serialize().

template<class templateType >

void SLNet::BitStream::WriteCompressed | ( | const templateType & | inTemplateVar | ) |

inline

Write any integral type to a bitstream.

Undefine __BITSTREAM_NATIVE_END if you need endian swapping. If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type

Parameters

  [in] | inTemplateVar | The value to write

Undefine __BITSTREAM_NATIVE_END if you need endian swapping. For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte

Parameters

  [in] | inTemplateVar | The value to write

Definition at line 1116 of file BitStream.h.

References DoEndianSwap(), and ReverseBytes().

Referenced by SLNet::StringCompressor::EncodeString(), SerializeCompressed(), SLNet::RakString::SerializeCompressed(), SLNet::TableSerializer::SerializeFilterQuery(), SLNet::TableSerializer::SerializeFilterQueryList(), WriteAlignedBytesSafe(), WriteCompressed(), WriteCompressedDelta(), and WriteVector().

void SLNet::BitStream::WriteCompressed | ( | const char *const | inStringVar | ) |

inline

Definition at line 702 of file BitStream.h.

References SLNet::RakString::SerializeCompressed().

void SLNet::BitStream::WriteCompressed | ( | const wchar_t *const | inStringVar | ) |

inline

Definition at line 706 of file BitStream.h.

References SLNet::RakWString::Serialize().

void SLNet::BitStream::WriteCompressed | ( | const unsigned char *const | inTemplateVar | ) |

inline

Definition at line 710 of file BitStream.h.

void SLNet::BitStream::WriteCompressed | ( | char *const | inTemplateVar | ) |

inline

Definition at line 714 of file BitStream.h.

void SLNet::BitStream::WriteCompressed | ( | unsigned char *const | inTemplateVar | ) |

inline

Definition at line 718 of file BitStream.h.

template<>

void SLNet::BitStream::WriteCompressed | ( | const SystemAddress & | inTemplateVar | ) |

inline

Definition at line 1139 of file BitStream.h.

References Write().

template<>

void SLNet::BitStream::WriteCompressed | ( | const RakNetGUID & | inTemplateVar | ) |

inline

Definition at line 1145 of file BitStream.h.

References Write().

template<>

void SLNet::BitStream::WriteCompressed | ( | const uint24_t & | var | ) |

inline

Definition at line 1151 of file BitStream.h.

References Write().

template<>

void SLNet::BitStream::WriteCompressed | ( | const bool & | inTemplateVar | ) |

inline

Definition at line 1157 of file BitStream.h.

References Write().

template<>

void SLNet::BitStream::WriteCompressed | ( | const float & | inTemplateVar | ) |

inline

For values between -1 and 1.

Definition at line 1164 of file BitStream.h.

References RakAssert, and Write().

template<>

void SLNet::BitStream::WriteCompressed | ( | const double & | inTemplateVar | ) |

inline

For values between -1 and 1.

Definition at line 1177 of file BitStream.h.

References RakAssert, and Write().

template<>

void SLNet::BitStream::WriteCompressed | ( | const RakString & | inTemplateVar | ) |

inline

Compress the string.

Definition at line 1190 of file BitStream.h.

References SLNet::RakString::SerializeCompressed().

template<>

void SLNet::BitStream::WriteCompressed | ( | const RakWString & | inTemplateVar | ) |

inline

Definition at line 1195 of file BitStream.h.

References SLNet::RakWString::Serialize().

template<>

void SLNet::BitStream::WriteCompressed | ( | const char *const & | inStringVar | ) |

inline

Definition at line 1200 of file BitStream.h.

References SLNet::RakString::SerializeCompressed().

template<>

void SLNet::BitStream::WriteCompressed | ( | const wchar_t *const & | inStringVar | ) |

inline

Definition at line 1205 of file BitStream.h.

References SLNet::RakWString::Serialize().

template<>

void SLNet::BitStream::WriteCompressed | ( | const unsigned char *const & | inTemplateVar | ) |

inline

Definition at line 1210 of file BitStream.h.

References WriteCompressed().

template<>

void SLNet::BitStream::WriteCompressed | ( | char *const & | inTemplateVar | ) |

inline

Definition at line 1215 of file BitStream.h.

References WriteCompressed().

template<>

void SLNet::BitStream::WriteCompressed | ( | unsigned char *const & | inTemplateVar | ) |

inline

Definition at line 1220 of file BitStream.h.

References WriteCompressed().

template<class templateType >

void SLNet::BitStream::WriteCompressedDelta | ( | const templateType & | currentValue,
|  | const templateType & | lastValue
| ) |  |

inline

Write any integral type to a bitstream.

If the current value is different from the last value the current value will be written. Otherwise, a single bit will be written For floating point, this is lossy, using 2 bytes for a float and 4 for a double. The range must be between -1 and +1. For non-floating point, this is lossless, but only has benefit if you use less than half the bits of the type If you are not using __BITSTREAM_NATIVE_END the opposite is true for types larger than 1 byte

Parameters

  [in] | currentValue | The current value to write
  [in] | lastValue | The last value to compare against

Definition at line 1235 of file BitStream.h.

References Write(), and WriteCompressed().

Referenced by SerializeCompressedDelta().

template<class templateType >

void SLNet::BitStream::WriteCompressedDelta | ( | const templateType & | currentValue | ) |

inline

Save as WriteCompressedDelta(const templateType &currentValue, const templateType &lastValue) when we have an unknown second parameter.

Definition at line 1262 of file BitStream.h.

References Write(), and WriteCompressed().

template<>

void SLNet::BitStream::WriteCompressedDelta | ( | const bool & | currentValue,
|  | const bool & | lastValue
| ) |  |

inline

Write a bool delta. Same thing as just calling Write.

Parameters

  [in] | currentValue | The current value to write
  [in] | lastValue | The last value to compare against

Definition at line 1252 of file BitStream.h.

References Write().

template<>

void SLNet::BitStream::WriteCompressedDelta | ( | const bool & | currentValue | ) |

inline

Save as WriteCompressedDelta(bool currentValue, const templateType &lastValue) when we have an unknown second bool.

Definition at line 1271 of file BitStream.h.

References Write().

template<class templateType >

void SLNet::BitStream::WriteDelta | ( | const templateType & | currentValue,
|  | const templateType & | lastValue
| ) |  |

inline

Write any integral type to a bitstream.

If the current value is different from the last value the current value will be written. Otherwise, a single bit will be written

Parameters

  [in] | currentValue | The current value to write
  [in] | lastValue | The last value to compare against

Definition at line 1076 of file BitStream.h.

References Write().

Referenced by SerializeDelta().

template<class templateType >

void SLNet::BitStream::WriteDelta | ( | const templateType & | currentValue | ) |

inline

WriteDelta when you don't know what the last value is, or there is no last value.

Parameters

  [in] | currentValue | The current value to write

Definition at line 1103 of file BitStream.h.

References Write().

template<>

void SLNet::BitStream::WriteDelta | ( | const bool & | currentValue,
|  | const bool & | lastValue
| ) |  |

inline

Write a bool delta. Same thing as just calling Write.

Parameters

  [in] | currentValue | The current value to write
  [in] | lastValue | The last value to compare against

Definition at line 1093 of file BitStream.h.

References Write().

void BitStream::WriteFloat16 | ( | float | x,
|  | float | floatMin,
|  | float | floatMax
| ) |  |

Write a float into 2 bytes, spanning the range between floatMin and floatMax.

Parameters

  [in] | x | The float to write
  [in] | floatMin | Predetermined minimum value of f
  [in] | floatMax | Predetermined maximum value of f

Definition at line 1218 of file BitStream.cpp.

References RakAssert, and Write().

Referenced by SerializeFloat16(), and WriteNormVector().

template<class templateType >

void SLNet::BitStream::WriteNormQuat | ( | templateType | w,
|  | templateType | x,
|  | templateType | y,
|  | templateType | z
| ) |  |

Write a normalized quaternion in 6 bytes + 4 bits instead of 16 bytes. Slightly lossy.

Parameters

  [in] | w | w
  [in] | x | x
  [in] | y | y
  [in] | z | z

Definition at line 1654 of file BitStream.h.

References Write().

Referenced by SerializeNormQuat(), and WriteOrthMatrix().

template<class templateType >

void SLNet::BitStream::WriteNormVector | ( | templateType | x,
|  | templateType | y,
|  | templateType | z
| ) |  |

Write a normalized 3D vector, using (at most) 4 bytes + 3 bits instead of 12-24 bytes.

Will further compress y or z axis aligned vectors. Accurate to 1/32767.5.

Parameters

  [in] | x | x
  [in] | y | y
  [in] | z | z

Definition at line 1626 of file BitStream.h.

References RakAssert, and WriteFloat16().

Referenced by SerializeNormVector().

template<class templateType >

void SLNet::BitStream::WriteOrthMatrix | ( | templateType | m00,
|  | templateType | m01,
|  | templateType | m02,
|  | templateType | m10,
|  | templateType | m11,
|  | templateType | m12,
|  | templateType | m20,
|  | templateType | m21,
|  | templateType | m22
| ) |  |

Write an orthogonal matrix by creating a quaternion, and writing 3 components of the quaternion in 2 bytes each.

Use 6 bytes instead of 36 Lossy, although the result is renormalized

Definition at line 1667 of file BitStream.h.

References _copysign, and WriteNormQuat().

Referenced by SerializeOrthMatrix().

template<class templateType >

void SLNet::BitStream::WritePtr | ( | templateType * | inTemplateVar | ) |

inline

Write the dereferenced pointer to any integral type to a bitstream.

Undefine __BITSTREAM_NATIVE_END if you need endian swapping.

Parameters

  [in] | inTemplateVar | The value to write

Definition at line 945 of file BitStream.h.

References DoEndianSwap(), ReverseBytes(), and WriteBits().

template<class templateType >

void SLNet::BitStream::WriteVector | ( | templateType | x,
|  | templateType | y,
|  | templateType | z
| ) |  |

Write a vector, using 10 bytes instead of 12.

Loses accuracy to about 3/10ths and only saves 2 bytes, so only use if accuracy is not important.

Parameters

  [in] | x | x
  [in] | y | y
  [in] | z | z

Definition at line 1638 of file BitStream.h.

References Write(), and WriteCompressed().

Referenced by SerializeVector().

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

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