class AlignData

A template class for aligning buffer data with a particular data type. More...

 
LOGO
 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Methods


Detailed Description

A template class for aligning buffer data with a particular data type.

The technically correct solution is to allocate (using malloc()) new buffer and copy the original data to it. By definition, the malloc()-ed data is aligned, and therefore it can be casted to the desired type.

The more efficient solution (but probably technically incorrect), is to assume that the first byte of "vector<uint8_t>" buffer is aligned similar to malloc()-ed data, and therefore it can be casted to the desired type without creating a copy of it.

The desired behavior can be chosen by setting the AlignData::_data_is_copied constant to true or false. Note that the constant is predefined for all AlignData instances. If necessary, the constant can become a variable that can have different value for each AlignData instance.

 AlignData (const vector<uint8_t>& buffer)

AlignData

Constructor.

Parameters:

bufferthe buffer with the data.
 ~AlignData ()

~AlignData

Destructor.

const A*  payload ()

payload

[const]

Get the aligned payload from the beginning of the buffer.

Returns: the aligned payload from the beginning of the buffer.

const A*  payload_by_offset (size_t offset)

payload_by_offset

[const]

Get the aligned payload by given offset from the beginning of the buffer.

Note that the given offset itself is suppose to point to aligned location.

Parameters:

offsetthe offset from the beginning of the buffer.

Returns: the aligned payload by given offset from the beginning of the buffer.


Generated by: pavlin on kobe.xorp.net on Wed Jan 7 19:10:36 2009, using kdoc 2.0a54+XORP.