TPProto::Buffer Class Reference

Buffer for packing and unpacking Frames. More...

#include <buffer.h>

List of all members.

Public Member Functions

 Buffer ()
 Default constructor.
 ~Buffer ()
 Default destructor.
void packInt (uint32_t val)
 Packs a 32 bit int into the buffer.
void packInt64 (uint64_t val)
 Packs a 64 bit int into the buffer.
void packString (const std::string &val)
 Packs a string into the buffer.
uint32_t unpackInt ()
 Unpacks a 32 bit int from the buffer.
uint64_t unpackInt64 ()
 Unpacks a 64 bit int from the buffer.
std::string unpackString ()
 Unpacks a string from the buffer.
uint32_t peekInt (uint32_t offset)
 Peeks at the value of the 32 bit int at an offset into the buffer.
void createHeader (uint32_t ver, uint32_t seqnum, uint32_t type, uint32_t len, uint32_t fver=0)
 Creates a header for the given parameters.
bool readHeader (uint32_t &ver, uint32_t &seqnum, uint32_t &type, uint32_t &len, uint32_t &fver)
 Reads a header, passing back the parameters.
void setData (char *buff, uint32_t len)
 Sets the buffer with the given data.
char * getData ()
 Gets the data in the buffer.
uint32_t getLength ()
 Gets the current length of the data in the buffer.
void setStringPadding (bool nsp)
 Sets if String Padding is turned on.
bool getStringPadding () const
 Checks if String Padding is turned on.


Detailed Description

Buffer for packing and unpacking Frames.

Supports unpacking and packing various base types and creating and reading the frame header.


Member Function Documentation

void TPProto::Buffer::packInt ( uint32_t  val  ) 

Packs a 32 bit int into the buffer.

Parameters:
val The value to be packed.

void TPProto::Buffer::packInt64 ( uint64_t  val  ) 

Packs a 64 bit int into the buffer.

Parameters:
val The value to be packed.

void TPProto::Buffer::packString ( const std::string &  val  ) 

Packs a string into the buffer.

Parameters:
val The string to be packed.

uint32_t TPProto::Buffer::unpackInt (  ) 

Unpacks a 32 bit int from the buffer.

Returns:
The value unpacked.

uint64_t TPProto::Buffer::unpackInt64 (  ) 

Unpacks a 64 bit int from the buffer.

Returns:
The value unpacked.

std::string TPProto::Buffer::unpackString (  ) 

Unpacks a string from the buffer.

Returns:
The string unpacked.

uint32_t TPProto::Buffer::peekInt ( uint32_t  offset  ) 

Peeks at the value of the 32 bit int at an offset into the buffer.

This operation does not change the r/w position.

Parameters:
offset The offset into the buffer.
Returns:
The 32 bit int value at the offset.

void TPProto::Buffer::createHeader ( uint32_t  ver,
uint32_t  seqnum,
uint32_t  type,
uint32_t  len,
uint32_t  fver = 0 
)

Creates a header for the given parameters.

The buffer is set to the header.

Parameters:
ver The version of the protocol.
seqnum The sequence number.
type The type number.
len The length of the data of the frame in bytes.
fver The frame type version, defaults to 0

bool TPProto::Buffer::readHeader ( uint32_t &  ver,
uint32_t &  seqnum,
uint32_t &  type,
uint32_t &  len,
uint32_t &  fver 
)

Reads a header, passing back the parameters.

Some checks are performed to check that the buffer is a valid header.

Parameters:
ver A reference to where the version number of the protocol will be stored.
seqnum A reference to where the sequence number will be stored.
type A reference to where the type number will be stored.
len A reference to where the length of the data of the frame in bytes should be stored.
fver A reference to where the frame type version will be stored.
Returns:
True if the header is valid.

void TPProto::Buffer::setData ( char *  buff,
uint32_t  len 
)

Sets the buffer with the given data.

Should not be called in general, used by FrameCodec to set the data received from the network.

Parameters:
buff The char array of data to be copied as the buffer.
len The length of the array of data for the buffer.

char * TPProto::Buffer::getData (  ) 

Gets the data in the buffer.

Should not be called in general, used by FrameCodec to send the data on the network.

Returns:
Data in the buffer.

uint32_t TPProto::Buffer::getLength (  ) 

Gets the current length of the data in the buffer.

Returns:
The length of the buffer in bytes.

void TPProto::Buffer::setStringPadding ( bool  nsp  ) 

Sets if String Padding is turned on.

Should only be called by FrameCodec for use in the String Padding filter.

Parameters:
nsp The new bool value for String Padding.

bool TPProto::Buffer::getStringPadding (  )  const

Checks if String Padding is turned on.

Returns:
True if string padding is no, false otherwise.


The documentation for this class was generated from the following files:
Generated on Tue Jan 6 03:45:46 2009 for libtpproto-cpp by  doxygen 1.5.1