News SF.net Project Frequently Asked Questions Documentation Downloads Mailing Lists How to Contribute

SourceForge.net Logo

Changing the way games are made and played.

TNL::ByteBuffer class Reference

TNL::ByteBuffer Class Reference

#include <tnlByteBuffer.h>

Inheritance diagram for TNL::ByteBuffer:

TNL::Object TNL::BitStream TNL::Certificate TNL::PacketStream

Public Types

enum  { DefaultBufferSize = 1500 }

Public Member Functions

 ByteBuffer (U8 *dataPtr, U32 bufferSize)
 Create a ByteBuffer from a chunk of memory.

 ByteBuffer (U32 bufferSize=DefaultBufferSize)
 Create a ByteBuffer of the specified size.

 ByteBuffer (const ByteBuffer &theBuffer)
 Copy constructor!

 ~ByteBuffer ()
void setBuffer (U8 *dataPtr, U32 bufferSize)
 Set the ByteBuffer to point to a new chunk of memory.

void setBuffer (U8 *dataPtr, U32 bufferSize, bool newOwnsMemory)
 Set the ByteBuffer to point to a new chunk of memory, indicating whether it should own the chunk or not.

bool resize (U32 newBufferSize)
 Attempts to resize the buffer.

bool appendBuffer (const U8 *dataBuffer, U32 bufferSize)
 Appends the specified buffer to the end of the byte buffer.

bool appendBuffer (const ByteBuffer &theBuffer)
 Appends the specified ByteBuffer to the end of this byte buffer.

void takeOwnership ()
 Copies the current buffer into a newly allocated buffer that the ByteBuffer owns.

bool ownsMemory ()
 Does this ByteBuffer own its own memory?

U32 getBufferSize () const
U8getBuffer ()
const U8getBuffer () const
void clear ()
 Clear the buffer.

RefPtr< ByteBufferencodeBase64 () const
 Encode the buffer to base 64, returning the encoded buffer.

RefPtr< ByteBufferdecodeBase64 () const
 Decode the buffer from base 64, returning the decoded buffer.

RefPtr< ByteBuffercomputeMD5Hash (U32 len=0) const
 Computes an MD5 hash and returns it in a ByteBuffer.

RefPtr< ByteBufferencodeBase16 () const
 Converts to ascii-hex, returning the encoded buffer.

RefPtr< ByteBufferdecodeBase16 () const
 Decodes the buffer from base 16, returning the decoded buffer.

U32 calculateCRC (U32 start=0, U32 end=0xFFFFFFFF, U32 crcVal=0xFFFFFFFF) const
 Returns a 32 bit CRC for the buffer.


Protected Attributes

U8mDataPtr
 Pointer to our data buffer.

U32 mBufSize
 Length of buffer.

bool mOwnsMemory
 Do we own the memory we are using? (If so, we should free it.).


Friends

struct MethodArgList

Member Enumeration Documentation

anonymous enum
 

Enumeration values:
DefaultBufferSize  Starting size of the buffer, varlot.


Constructor & Destructor Documentation

TNL::ByteBuffer::ByteBuffer U8 dataPtr,
U32  bufferSize
[inline]
 

Create a ByteBuffer from a chunk of memory.

TNL::ByteBuffer::ByteBuffer U32  bufferSize = DefaultBufferSize  )  [inline]
 

Create a ByteBuffer of the specified size.

TNL::ByteBuffer::ByteBuffer const ByteBuffer theBuffer  )  [inline]
 

Copy constructor!

TNL::ByteBuffer::~ByteBuffer  )  [inline]
 


Member Function Documentation

void TNL::ByteBuffer::setBuffer U8 dataPtr,
U32  bufferSize
[inline]
 

Set the ByteBuffer to point to a new chunk of memory.

void TNL::ByteBuffer::setBuffer U8 dataPtr,
U32  bufferSize,
bool  newOwnsMemory
[inline]
 

Set the ByteBuffer to point to a new chunk of memory, indicating whether it should own the chunk or not.

bool TNL::ByteBuffer::resize U32  newBufferSize  )  [inline]
 

Attempts to resize the buffer.

Returns:
True if it owns its own memory, false otherwise.

bool TNL::ByteBuffer::appendBuffer const U8 dataBuffer,
U32  bufferSize
[inline]
 

Appends the specified buffer to the end of the byte buffer.

returns false if it does not own its own memory.

bool TNL::ByteBuffer::appendBuffer const ByteBuffer theBuffer  )  [inline]
 

Appends the specified ByteBuffer to the end of this byte buffer.

returns fals if it does not own its own memory.

void TNL::ByteBuffer::takeOwnership  )  [inline]
 

Copies the current buffer into a newly allocated buffer that the ByteBuffer owns.

bool TNL::ByteBuffer::ownsMemory  )  [inline]
 

Does this ByteBuffer own its own memory?

U32 TNL::ByteBuffer::getBufferSize  )  const [inline]
 

U8* TNL::ByteBuffer::getBuffer  )  [inline]
 

const U8* TNL::ByteBuffer::getBuffer  )  const [inline]
 

void TNL::ByteBuffer::clear  )  [inline]
 

Clear the buffer.

RefPtr<ByteBuffer> TNL::ByteBuffer::encodeBase64  )  const
 

Encode the buffer to base 64, returning the encoded buffer.

RefPtr<ByteBuffer> TNL::ByteBuffer::decodeBase64  )  const
 

Decode the buffer from base 64, returning the decoded buffer.

RefPtr<ByteBuffer> TNL::ByteBuffer::computeMD5Hash U32  len = 0  )  const
 

Computes an MD5 hash and returns it in a ByteBuffer.

RefPtr<ByteBuffer> TNL::ByteBuffer::encodeBase16  )  const
 

Converts to ascii-hex, returning the encoded buffer.

RefPtr<ByteBuffer> TNL::ByteBuffer::decodeBase16  )  const
 

Decodes the buffer from base 16, returning the decoded buffer.

U32 TNL::ByteBuffer::calculateCRC U32  start = 0,
U32  end = 0xFFFFFFFF,
U32  crcVal = 0xFFFFFFFF
const
 

Returns a 32 bit CRC for the buffer.


Friends And Related Function Documentation

friend struct MethodArgList [friend]
 


Field Documentation

U8* TNL::ByteBuffer::mDataPtr [protected]
 

Pointer to our data buffer.

U32 TNL::ByteBuffer::mBufSize [protected]
 

Length of buffer.

bool TNL::ByteBuffer::mOwnsMemory [protected]
 

Do we own the memory we are using? (If so, we should free it.).