Skip to content

Commit

Permalink
- move BitStream::SetReadOffset() and ::AlignReadToByteBoundary() def…
Browse files Browse the repository at this point in the history
…initions to cpp (facebookarchive#130)
  • Loading branch information
Luke1410 committed Sep 3, 2019
1 parent e67c8fd commit 2a5ecab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Source/include/slikenet/BitStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*
* Modified work: Copyright (c) 2016-2018, SLikeSoft UG (haftungsbeschränkt)
* Modified work: Copyright (c) 2016-2019, SLikeSoft UG (haftungsbeschränkt)
*
* This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
* license found in the license.txt file in the root directory of this source tree.
Expand Down Expand Up @@ -528,7 +528,7 @@ namespace SLNet
inline BitSize_t GetReadOffset( void ) const {return readOffset;}

/// \brief Sets the read bit index
void SetReadOffset( const BitSize_t newReadOffset ) {readOffset=newReadOffset;}
void SetReadOffset(const BitSize_t newReadOffset);

/// \brief Returns the number of bits left in the stream that haven't been read
inline BitSize_t GetNumberOfUnreadBits( void ) const {return numberOfBitsUsed - readOffset;}
Expand Down Expand Up @@ -611,7 +611,7 @@ namespace SLNet
/// 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.
inline void AlignReadToByteBoundary( void ) {readOffset += 8 - ( (( readOffset - 1 ) & 7 ) + 1 );}
inline void AlignReadToByteBoundary(void);

/// \brief Read \a numberOfBitsToRead bits to the output source.
/// \details alignBitsToRight should be set to true to convert internal
Expand Down
18 changes: 13 additions & 5 deletions Source/src/BitStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*
* Modified work: Copyright (c) 2016-2018, SLikeSoft UG (haftungsbeschränkt)
* Modified work: Copyright (c) 2016-2019, SLikeSoft UG (haftungsbeschränkt)
*
* This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
* license found in the license.txt file in the root directory of this source tree.
Expand Down Expand Up @@ -272,10 +272,8 @@ bool BitStream::Read( char* outByteArray, const unsigned int numberOfBytes )
readOffset += numberOfBytes << 3;
return true;
}
else
{
return ReadBits( ( unsigned char* ) outByteArray, numberOfBytes * 8 );
}

return ReadBits( ( unsigned char* ) outByteArray, numberOfBytes * 8 );
}

// Sets the read pointer back to the beginning of your data.
Expand Down Expand Up @@ -534,6 +532,11 @@ void BitStream::WriteCompressed( const unsigned char* inByteArray,
}
}

void BitStream::AlignReadToByteBoundary()
{
readOffset += 8 - ( (( readOffset - 1 ) & 7 ) + 1 );
}

// 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
Expand Down Expand Up @@ -939,6 +942,11 @@ void BitStream::PrintHex( void ) const
RAKNET_DEBUG_PRINTF("%s", out);
}

void BitStream::SetReadOffset(const BitSize_t newReadOffset)
{
readOffset = newReadOffset;
}

// Exposes the data for you to look at, like PrintBits does.
// Data will point to the stream. Returns the length in bits of the stream.
BitSize_t BitStream::CopyData( unsigned char** _data ) const
Expand Down

0 comments on commit 2a5ecab

Please sign in to comment.