A template class for aligning buffer data with a particular data type. More...
|AlignData (const vector< uint8_t > &buffer)|
|const A *||payload () const|
|Get the aligned payload from the beginning of the buffer. |
|const A *||payload_by_offset (size_t offset) const|
|Get the aligned payload by given offset from the beginning of the buffer. |
|const void *||_const_data|
|const A *||_payload|
|static const bool||_data_is_copied = false|
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.
|const A* AlignData< A >::payload||(||)|| const
|const A* AlignData< A >::payload_by_offset||(||size_t||offset||)|| const